Example #1
0
 /**
  * Serializes type
  */
 public function SerializeToString($rec = -1)
 {
     // now convert signed int to int
     $save = $this->value;
     if ($this->value < 0) {
         $this->value = abs($this->value) * 2 - 1;
     } else {
         $this->value = $this->value * 2;
     }
     $string = parent::SerializeToString($rec);
     // restore value
     $this->value = $save;
     return $string;
 }
Example #2
0
 /**
  * Internal function
  */
 private function _ParseFromArray($length = 99999999)
 {
     $_begin = $this->reader->get_pointer();
     while ($this->reader->get_pointer() - $_begin < $length) {
         $next = $this->reader->next();
         if ($next === false) {
             break;
         }
         // now get the message type
         $messtypes = $this->get_types($next);
         // now make method test
         if (!isset($this->fields[$messtypes['field']])) {
             // field is unknown so just ignore it
             // throw new Exception('Field ' . $messtypes['field'] . ' not present ');
             if ($messtypes['wired'] == PBMessage::WIRED_LENGTH_DELIMITED) {
                 $consume = new PBString($this->reader);
             } else {
                 if ($messtypes['wired'] == PBMessage::WIRED_VARINT) {
                     $consume = new PBInt($this->reader);
                 } else {
                     throw new Exception('I dont understand this wired code:' . $messtypes['wired']);
                 }
             }
             // perhaps send a warning out
             // @TODO SEND CHUNK WARNING
             $_oldpointer = $this->reader->get_pointer();
             $consume->ParseFromArray();
             // now add array from _oldpointer to pointer to the chunk array
             $this->chunk .= $this->reader->get_message_from($_oldpointer);
             continue;
         }
         // now array or not
         if (is_array($this->values[$messtypes['field']])) {
             $this->values[$messtypes['field']][] = new $this->fields[$messtypes['field']]($this->reader);
             $index = count($this->values[$messtypes['field']]) - 1;
             if ($messtypes['wired'] != $this->values[$messtypes['field']][$index]->wired_type) {
                 throw new Exception('Expected type:' . $messtypes['wired'] . ' but had ' . $this->fields[$messtypes['field']]->wired_type);
             }
             $this->values[$messtypes['field']][$index]->ParseFromArray();
         } else {
             $this->values[$messtypes['field']] = new $this->fields[$messtypes['field']]($this->reader);
             if ($messtypes['wired'] != $this->values[$messtypes['field']]->wired_type) {
                 throw new Exception('Expected type:' . $messtypes['wired'] . ' but had ' . $this->fields[$messtypes['field']]->wired_type);
             }
             $this->values[$messtypes['field']]->ParseFromArray();
         }
     }
 }
Example #3
0
 public static function StaticSerializeToString($rec = -1, $base128, $value)
 {
     return PBInt::StaticSerializeToString($rec, $base128, $value);
 }
Example #4
0
 /**
  * @param null $reader
  */
 public function __construct($reader = null)
 {
     parent::__construct($reader);
     $this->wired_type = PBMessage::WIRED_VARINT;
 }