require_once "./tests/Example/Test1.php"; require_once "./tests/Example/Test3.php"; echo "Test values less than 128 (encode/decode)\n"; $result = PhpBuf_Base128::decodeFromReader(new PhpBuf_IO_Reader(PhpBuf_Base128::encode(120))); echo "120 == " . $result . "\n\n"; echo "Test values more than 128 (only decode)\n"; $result = PhpBuf_Base128::decodeFromReader(new PhpBuf_IO_Reader(pack("n", 44034))); echo "300 == " . $result . "\n\n"; echo "Test values more than 128 (encode/decode)\n"; $encode = PhpBuf_Base128::encode(300); $result = PhpBuf_Base128::decodeFromReader(new PhpBuf_IO_Reader($encode)); echo "encoded: {$encode}\n\n"; echo "300 == " . $result . "\n\n"; echo "Test values more than 128 (encode/decode)\n"; $encode = PhpBuf_Base128::encode(123456789); $result = PhpBuf_Base128::decodeFromReader(new PhpBuf_IO_Reader($encode)); echo "encoded: {$encode}\n\n"; echo "123456789 == " . $result . "\n\n"; echo "Test ZigZag class\n"; echo "value: 0\n"; $encode = PhpBuf_ZigZag::encode(0); echo "encoded: " . $encode . "\n"; echo "decoded: " . PhpBuf_ZigZag::decode($encode) . "\n\n"; echo "value: 1\n"; $encode = PhpBuf_ZigZag::encode(1); echo "encoded: " . $encode . "\n"; echo "decoded: " . PhpBuf_ZigZag::decode($encode) . "\n\n"; echo "value: -1\n"; $encode = PhpBuf_ZigZag::encode(-1); echo "encoded: " . $encode . "\n"; echo "decoded: " . PhpBuf_ZigZag::decode($encode) . "\n\n";
public static function read(PhpBuf_IO_Reader_Interface $reader) { return PhpBuf_Base128::decodeFromReader($reader); }
public function testEncodeAndDecodeBigValues() { $encode = PhpBuf_Base128::encode(123456789); $result = PhpBuf_Base128::decodeFromReader(new PhpBuf_IO_Reader($encode)); $this->assertEquals(123456789, $result); }
/** * Read field info from reader and return associated field class * * @param IO_Reader_Interface $reader * @return Message_Abstract */ protected function readFieldFromHeader(PhpBuf_IO_Reader_Interface $reader) { $varint = PhpBuf_Base128::decodeFromReader($reader); $fieldIndex = $varint >> 3; $wireType = self::mask($varint); if (!isset($this->fields[$fieldIndex])) { throw new PhpBuf_Field_Exception("class " . get_class($this) . " field index {$fieldIndex} not found"); } $fieldClass = $this->fields[$fieldIndex]; $fieldsWireType = $fieldClass->getWireType(); if ($wireType !== $fieldsWireType) { throw new PhpBuf_Field_Exception("discrepancy of wire types"); } return $fieldClass; }
public static function read(PhpBuf_IO_Reader_Interface $reader) { $lenght = PhpBuf_Base128::decodeFromReader($reader); return $reader->getBytes($lenght); }