コード例 #1
0
 /**
  * Serialized \Google\Protobuf\FileDescriptorProto to Protocol Buffers message.
  *
  * @param FileDescriptorProto $object
  * @param array $filter
  *
  * @throws \Exception
  *
  * @return string
  */
 public static function toProtobuf($object, $filter = NULL)
 {
     $output = '';
     if (isset($object->name) && ($filter === null || isset($filter['name']))) {
         $output .= "\n";
         $output .= Binary::encodeVarint(strlen($object->name));
         $output .= $object->name;
     }
     if (isset($object->package) && ($filter === null || isset($filter['package']))) {
         $output .= "";
         $output .= Binary::encodeVarint(strlen($object->package));
         $output .= $object->package;
     }
     if (isset($object->dependency) && ($filter === null || isset($filter['dependency']))) {
         foreach ($object->dependency instanceof \Traversable ? $object->dependency : (array) $object->dependency as $k => $v) {
             $output .= "";
             $output .= Binary::encodeVarint(strlen($v));
             $output .= $v;
         }
     }
     if (isset($object->publicDependency) && ($filter === null || isset($filter['publicDependency']))) {
         foreach ($object->publicDependency instanceof \Traversable ? $object->publicDependency : (array) $object->publicDependency as $k => $v) {
             $output .= "P";
             $output .= Binary::encodeVarint($v);
         }
     }
     if (isset($object->weakDependency) && ($filter === null || isset($filter['weakDependency']))) {
         foreach ($object->weakDependency instanceof \Traversable ? $object->weakDependency : (array) $object->weakDependency as $k => $v) {
             $output .= "X";
             $output .= Binary::encodeVarint($v);
         }
     }
     if (isset($object->messageType) && ($filter === null || isset($filter['messageType']))) {
         foreach ($object->messageType instanceof \Traversable ? $object->messageType : (array) $object->messageType as $k => $v) {
             $output .= "\"";
             $buffer = DescriptorProtoMeta::toProtobuf($v, $filter === null ? null : $filter['messageType']);
             $output .= Binary::encodeVarint(strlen($buffer));
             $output .= $buffer;
         }
     }
     if (isset($object->enumType) && ($filter === null || isset($filter['enumType']))) {
         foreach ($object->enumType instanceof \Traversable ? $object->enumType : (array) $object->enumType as $k => $v) {
             $output .= "*";
             $buffer = EnumDescriptorProtoMeta::toProtobuf($v, $filter === null ? null : $filter['enumType']);
             $output .= Binary::encodeVarint(strlen($buffer));
             $output .= $buffer;
         }
     }
     if (isset($object->service) && ($filter === null || isset($filter['service']))) {
         foreach ($object->service instanceof \Traversable ? $object->service : (array) $object->service as $k => $v) {
             $output .= "2";
             $buffer = ServiceDescriptorProtoMeta::toProtobuf($v, $filter === null ? null : $filter['service']);
             $output .= Binary::encodeVarint(strlen($buffer));
             $output .= $buffer;
         }
     }
     if (isset($object->extension) && ($filter === null || isset($filter['extension']))) {
         foreach ($object->extension instanceof \Traversable ? $object->extension : (array) $object->extension as $k => $v) {
             $output .= ":";
             $buffer = FieldDescriptorProtoMeta::toProtobuf($v, $filter === null ? null : $filter['extension']);
             $output .= Binary::encodeVarint(strlen($buffer));
             $output .= $buffer;
         }
     }
     if (isset($object->options) && ($filter === null || isset($filter['options']))) {
         $output .= "B";
         $buffer = FileOptionsMeta::toProtobuf($object->options, $filter === null ? null : $filter['options']);
         $output .= Binary::encodeVarint(strlen($buffer));
         $output .= $buffer;
     }
     if (isset($object->sourceCodeInfo) && ($filter === null || isset($filter['sourceCodeInfo']))) {
         $output .= "J";
         $buffer = SourceCodeInfoMeta::toProtobuf($object->sourceCodeInfo, $filter === null ? null : $filter['sourceCodeInfo']);
         $output .= Binary::encodeVarint(strlen($buffer));
         $output .= $buffer;
     }
     if (isset($object->syntax) && ($filter === null || isset($filter['syntax']))) {
         $output .= "b";
         $output .= Binary::encodeVarint(strlen($object->syntax));
         $output .= $object->syntax;
     }
     return $output;
 }
コード例 #2
0
 /**
  * Serialized \Google\Protobuf\DescriptorProto to Protocol Buffers message.
  *
  * @param DescriptorProto $object
  * @param array $filter
  *
  * @throws \Exception
  *
  * @return string
  */
 public static function toProtobuf($object, $filter = NULL)
 {
     $output = '';
     if (isset($object->name) && ($filter === null || isset($filter['name']))) {
         $output .= "\n";
         $output .= Binary::encodeVarint(strlen($object->name));
         $output .= $object->name;
     }
     if (isset($object->field) && ($filter === null || isset($filter['field']))) {
         foreach ($object->field instanceof \Traversable ? $object->field : (array) $object->field as $k => $v) {
             $output .= "";
             $buffer = FieldDescriptorProtoMeta::toProtobuf($v, $filter === null ? null : $filter['field']);
             $output .= Binary::encodeVarint(strlen($buffer));
             $output .= $buffer;
         }
     }
     if (isset($object->extension) && ($filter === null || isset($filter['extension']))) {
         foreach ($object->extension instanceof \Traversable ? $object->extension : (array) $object->extension as $k => $v) {
             $output .= "2";
             $buffer = FieldDescriptorProtoMeta::toProtobuf($v, $filter === null ? null : $filter['extension']);
             $output .= Binary::encodeVarint(strlen($buffer));
             $output .= $buffer;
         }
     }
     if (isset($object->nestedType) && ($filter === null || isset($filter['nestedType']))) {
         foreach ($object->nestedType instanceof \Traversable ? $object->nestedType : (array) $object->nestedType as $k => $v) {
             $output .= "";
             $buffer = DescriptorProtoMeta::toProtobuf($v, $filter === null ? null : $filter['nestedType']);
             $output .= Binary::encodeVarint(strlen($buffer));
             $output .= $buffer;
         }
     }
     if (isset($object->enumType) && ($filter === null || isset($filter['enumType']))) {
         foreach ($object->enumType instanceof \Traversable ? $object->enumType : (array) $object->enumType as $k => $v) {
             $output .= "\"";
             $buffer = EnumDescriptorProtoMeta::toProtobuf($v, $filter === null ? null : $filter['enumType']);
             $output .= Binary::encodeVarint(strlen($buffer));
             $output .= $buffer;
         }
     }
     if (isset($object->extensionRange) && ($filter === null || isset($filter['extensionRange']))) {
         foreach ($object->extensionRange instanceof \Traversable ? $object->extensionRange : (array) $object->extensionRange as $k => $v) {
             $output .= "*";
             $buffer = ExtensionRangeMeta::toProtobuf($v, $filter === null ? null : $filter['extensionRange']);
             $output .= Binary::encodeVarint(strlen($buffer));
             $output .= $buffer;
         }
     }
     if (isset($object->oneofDecl) && ($filter === null || isset($filter['oneofDecl']))) {
         foreach ($object->oneofDecl instanceof \Traversable ? $object->oneofDecl : (array) $object->oneofDecl as $k => $v) {
             $output .= "B";
             $buffer = OneofDescriptorProtoMeta::toProtobuf($v, $filter === null ? null : $filter['oneofDecl']);
             $output .= Binary::encodeVarint(strlen($buffer));
             $output .= $buffer;
         }
     }
     if (isset($object->options) && ($filter === null || isset($filter['options']))) {
         $output .= ":";
         $buffer = MessageOptionsMeta::toProtobuf($object->options, $filter === null ? null : $filter['options']);
         $output .= Binary::encodeVarint(strlen($buffer));
         $output .= $buffer;
     }
     if (isset($object->reservedRange) && ($filter === null || isset($filter['reservedRange']))) {
         foreach ($object->reservedRange instanceof \Traversable ? $object->reservedRange : (array) $object->reservedRange as $k => $v) {
             $output .= "J";
             $buffer = ReservedRangeMeta::toProtobuf($v, $filter === null ? null : $filter['reservedRange']);
             $output .= Binary::encodeVarint(strlen($buffer));
             $output .= $buffer;
         }
     }
     if (isset($object->reservedName) && ($filter === null || isset($filter['reservedName']))) {
         foreach ($object->reservedName instanceof \Traversable ? $object->reservedName : (array) $object->reservedName as $k => $v) {
             $output .= "R";
             $output .= Binary::encodeVarint(strlen($v));
             $output .= $v;
         }
     }
     return $output;
 }