/** * 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; }
/** * Internal function */ private function _ParseFromArray($length = 99999999) { $thisClassName = $this->getClassNameWithoutNamespace($this); $_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(self::$fields[$thisClassName][$messtypes['field']])) { // field is unknown so just ignore it // throw new Exception('Field ' . $messtypes['field'] . ' not present '); if ($messtypes['wired'] == ProtocolBuffers_AbstractMessage::WIRED_LENGTH_DELIMITED) { $consume = new ProtocolBuffers_Type_String($this->reader); } else { if ($messtypes['wired'] == ProtocolBuffers_AbstractMessage::WIRED_VARINT) { $consume = new ProtocolBuffers_Type_Int($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 self::$fields[$thisClassName][$messtypes['field']]($this->reader); $index = count($this->values[$messtypes['field']]) - 1; if ($messtypes['wired'] != $this->values[$messtypes['field']][$index]->getWiredType()) { throw new Exception('Expected type:' . $messtypes['wired'] . ' but had ' . self::$fields[$thisClassName][$messtypes['field']]->getWiredType()); } $this->values[$messtypes['field']][$index]->ParseFromArray(); } else { $this->values[$messtypes['field']] = new self::$fields[$thisClassName][$messtypes['field']]($this->reader); if ($messtypes['wired'] != $this->values[$messtypes['field']]->getWiredType()) { throw new Exception('Expected type:' . $messtypes['wired'] . ' but had ' . self::$fields[$thisClassName][$thisClassName][$messtypes['field']]->getWiredType()); } $this->values[$messtypes['field']]->ParseFromArray(); } } }