Ejemplo n.º 1
0
 /**
  * Serialized \Skrz\Bundle\BunnyBundle\Tests\Fixtures\Message to Protocol Buffers message.
  *
  * @param Message $object
  * @param array $filter
  *
  * @throws \Exception
  *
  * @return string
  */
 public static function toProtobuf($object, $filter = NULL)
 {
     $output = '';
     if (isset($object->intValue) && ($filter === null || isset($filter['intValue']))) {
         $output .= "";
         $output .= Binary::encodeVarint($object->intValue);
     }
     if (isset($object->floatValue) && ($filter === null || isset($filter['floatValue']))) {
         $output .= "";
         $output .= Binary::encodeDouble($object->floatValue);
     }
     if (isset($object->stringValue) && ($filter === null || isset($filter['stringValue']))) {
         $output .= "";
         $output .= Binary::encodeVarint(strlen($object->stringValue));
         $output .= $object->stringValue;
     }
     return $output;
 }
Ejemplo n.º 2
0
 /**
  * Serialized \Google\Protobuf\UninterpretedOption to Protocol Buffers message.
  *
  * @param UninterpretedOption $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']))) {
         foreach ($object->name instanceof \Traversable ? $object->name : (array) $object->name as $k => $v) {
             $output .= "";
             $buffer = NamePartMeta::toProtobuf($v, $filter === null ? null : $filter['name']);
             $output .= Binary::encodeVarint(strlen($buffer));
             $output .= $buffer;
         }
     }
     if (isset($object->identifierValue) && ($filter === null || isset($filter['identifierValue']))) {
         $output .= "";
         $output .= Binary::encodeVarint(strlen($object->identifierValue));
         $output .= $object->identifierValue;
     }
     if (isset($object->positiveIntValue) && ($filter === null || isset($filter['positiveIntValue']))) {
         $output .= " ";
         $output .= Binary::encodeVarint($object->positiveIntValue);
     }
     if (isset($object->negativeIntValue) && ($filter === null || isset($filter['negativeIntValue']))) {
         $output .= "(";
         $output .= Binary::encodeVarint($object->negativeIntValue);
     }
     if (isset($object->doubleValue) && ($filter === null || isset($filter['doubleValue']))) {
         $output .= "1";
         $output .= Binary::encodeDouble($object->doubleValue);
     }
     if (isset($object->stringValue) && ($filter === null || isset($filter['stringValue']))) {
         $output .= ":";
         $output .= Binary::encodeVarint(strlen($object->stringValue));
         $output .= $object->stringValue;
     }
     if (isset($object->aggregateValue) && ($filter === null || isset($filter['aggregateValue']))) {
         $output .= "B";
         $output .= Binary::encodeVarint(strlen($object->aggregateValue));
         $output .= $object->aggregateValue;
     }
     return $output;
 }