-
Notifications
You must be signed in to change notification settings - Fork 38
Api protocolbuffers
Shuhei Tanuma edited this page Dec 24, 2013
·
6 revisions
- Name
- ProtocolBuffers
- Alias
- ProtocolBuffers
Old-style protocol buffers serializer / deserializer.
You should use generated class which extends ProtocolBuffers\Message
instead of this class.
Name | Description |
---|---|
ProtocolBuffers::WIRETYPE_VARINT | |
ProtocolBuffers::WIRETYPE_FIXED64 | |
ProtocolBuffers::WIRETYPE_LENGTH_DELIMITED | |
ProtocolBuffers::WIRETYPE_START_GROUP | |
ProtocolBuffers::WIRETYPE_END_GROUP | |
ProtocolBuffers::WIRETYPE_FIXED32 | |
ProtocolBuffers::TYPE_DOUBLE | |
ProtocolBuffers::TYPE_FLOAT | |
ProtocolBuffers::TYPE_INT64 | |
ProtocolBuffers::TYPE_UINT64 | |
ProtocolBuffers::TYPE_INT32 | |
ProtocolBuffers::TYPE_FIXED64 | |
ProtocolBuffers::TYPE_FIXED32 | |
ProtocolBuffers::TYPE_BOOL | |
ProtocolBuffers::TYPE_STRING | |
ProtocolBuffers::TYPE_GROUP | |
ProtocolBuffers::TYPE_MESSAGE | |
ProtocolBuffers::TYPE_BYTES | |
ProtocolBuffers::TYPE_UINT32 | |
ProtocolBuffers::TYPE_ENUM | |
ProtocolBuffers::TYPE_SFIXED32 | |
ProtocolBuffers::TYPE_SFIXED64 | |
ProtocolBuffers::TYPE_SINT32 | |
ProtocolBuffers::TYPE_SINT64 | |
ProtocolBuffers::MAX_FIELD_TYPE | |
ProtocolBuffers::PHP_MESSAGE_OPTION |
encode PHP object to raw protocolbuffers message.
$class: class which have getDescriptor
method and returns correct ProtocolBuffers\Descriptor
.
string: raw protocolbuffers message
<?php
class Article
{
protected $IsDraft;
public static function getDescriptor()
{
static $descriptor;
if (!isset($descriptor)) {
$desc = new ProtocolBuffersDescriptorBuilder();
$desc->addField(1, new ProtocolBuffersFieldDescriptor(array(
"type" => ProtocolBuffers::TYPE_BOOL,
"name" => "IsDraft",
"required" => false,
"optional" => true,
"repeated" => false,
"packable" => false,
"default" => false,
)));
$descriptor = $desc->build();
}
return $descriptor;
}
}
$article = new Article(["IsDraft" => true]);
// You can encode any class which has expected `getDescriptor` method.
echo ProtocolBuffers::encode($article);
decode raw protcolbuffers message into $class_name.
$class_name: class which have getDescriptor
method and returns correct ProtocolBuffers\Descriptor
.
$raw_message: valid raw protocolbuffers message
mixed: class