function testReadVarint()
 {
     foreach ($this->tests as $i => $enc) {
         if (is_string($i)) {
             $i = (double) $i;
         }
         $this->reset($enc);
         if ($i >= 0) {
             $a = Protobuf::read_varint($this->fp);
         } else {
             $a = Protobuf::read_signed_varint($this->fp);
         }
         $this->assertSame($i, $a, "Failed to read_varint({$i})");
     }
 }
Exemple #2
0
 function read($fp, &$limit = PHP_INT_MAX)
 {
     while (!feof($fp) && $limit > 0) {
         $tag = Protobuf::read_varint($fp, $limit);
         if ($tag === false) {
             break;
         }
         $wire = $tag & 0x7;
         $field = $tag >> 3;
         //var_dump("LogGroupList: Found $field type " . Protobuf::get_wiretype($wire) . " $limit bytes left");
         switch ($field) {
             case 1:
                 ASSERT('$wire == 2');
                 $len = Protobuf::read_varint($fp, $limit);
                 if ($len === false) {
                     throw new Exception('Protobuf::read_varint returned false');
                 }
                 $limit -= $len;
                 $this->logGroupList_[] = new LogGroup($fp, $len);
                 ASSERT('$len == 0');
                 break;
             default:
                 $this->_unknown[$field . '-' . Protobuf::get_wiretype($wire)][] = Protobuf::read_field($fp, $wire, $limit);
         }
     }
     if (!$this->validateRequired()) {
         throw new Exception('Required fields are missing');
     }
 }
Exemple #3
0
 /**
  * Read a unknown field from the stream and return its raw bytes
  */
 public static function read_field($fp, $wire_type, &$limit = null)
 {
     switch ($wire_type) {
         case 0:
             // varint
             return Protobuf::read_varint($fp, $limit);
         case 1:
             // 64bit
             $limit -= 8;
             return fread($fp, 8);
         case 2:
             // length delimited
             $len = Protobuf::read_varint($fp, $limit);
             $limit -= $len;
             return fread($fp, $len);
             //case 3: // Start group TODO we must keep looping until we find the closing end grou
             //case 4: // End group - We should never skip a end group!
             //	return 0; // Do nothing
         //case 3: // Start group TODO we must keep looping until we find the closing end grou
         //case 4: // End group - We should never skip a end group!
         //	return 0; // Do nothing
         case 5:
             // 32bit
             $limit -= 4;
             return fread($fp, 4);
         default:
             throw new Exception('read_unknown(' . ProtoBuf::get_wiretype($wire_type) . '): Unsupported wire_type');
     }
 }
 function read($fp, &$limit = PHP_INT_MAX)
 {
     while (!feof($fp) && $limit > 0) {
         $tag = Protobuf::read_varint($fp, $limit);
         if ($tag === false) {
             break;
         }
         $wire = $tag & 0x7;
         $field = $tag >> 3;
         //var_dump("Response: Found $field type " . Protobuf::get_wiretype($wire) . " $limit bytes left");
         switch ($field) {
             case 1:
                 ASSERT('$wire == 3');
                 $this->responsegroup_[] = new Response_ResponseGroup($fp, $limit);
                 break;
             default:
                 $this->_unknown[$field . '-' . Protobuf::get_wiretype($wire)][] = Protobuf::read_field($fp, $wire, $limit);
         }
     }
     if (!$this->validateRequired()) {
         throw new Exception('Required fields are missing');
     }
 }