/** * Parses the message for this type * * @param array */ public function ParseFromArray() { parent::ParseFromArray(); $saved = $this->value; $this->value = round($this->value / 2); if ($saved % 2 == 1) { $this->value = -$this->value; } }
/** * 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(); } } }