Ejemplo n.º 1
0
 /**
  * @ignore
  */
 private function fieldDataOnlyByteSize($field, $value)
 {
     $size = 0;
     switch ($field->getType()) {
         case GPBType::BOOL:
             $size += 1;
             break;
         case GPBType::FLOAT:
         case GPBType::FIXED32:
         case GPBType::SFIXED32:
             $size += 4;
             break;
         case GPBType::DOUBLE:
         case GPBType::FIXED64:
         case GPBType::SFIXED64:
             $size += 8;
             break;
         case GPBType::UINT32:
         case GPBType::INT32:
         case GPBType::ENUM:
             $size += GPBWire::varint32Size($value);
             break;
         case GPBType::UINT64:
         case GPBType::INT64:
             $size += GPBWire::varint64Size($value);
             break;
         case GPBType::SINT32:
             $size += GPBWire::sint32Size($value);
             break;
         case GPBType::SINT64:
             $size += GPBWire::sint64Size($value);
             break;
         case GPBType::STRING:
         case GPBType::BYTES:
             $size += strlen($value);
             $size += GPBWire::varint32Size($size);
             break;
         case GPBType::MESSAGE:
             $size += $value->byteSize();
             $size += GPBWire::varint32Size($size);
             break;
         case GPBType::GROUP:
             // TODO(teboring): Add support.
             user_error("Unsupported type.");
             break;
         default:
             user_error("Unsupported type.");
             return 0;
     }
     return $size;
 }