예제 #1
0
 public static function serializeFieldToStream($value, $field, $need_tag, &$output)
 {
     if ($need_tag) {
         if (!GPBWire::writeTag($output, self::makeTag($field->getNumber(), $field->getType()))) {
             return false;
         }
     }
     switch ($field->getType()) {
         case GPBType::DOUBLE:
             if (!GPBWire::writeDouble($output, $value)) {
                 return false;
             }
             break;
         case GPBType::FLOAT:
             if (!GPBWire::writeFloat($output, $value)) {
                 return false;
             }
             break;
         case GPBType::INT64:
             if (!GPBWire::writeInt64($output, $value)) {
                 return false;
             }
             break;
         case GPBType::UINT64:
             if (!GPBWire::writeUint64($output, $value)) {
                 return false;
             }
             break;
         case GPBType::INT32:
             if (!GPBWire::writeInt32($output, $value)) {
                 return false;
             }
             break;
         case GPBType::FIXED32:
             if (!GPBWire::writeFixed32($output, $value)) {
                 return false;
             }
             break;
         case GPBType::FIXED64:
             if (!GPBWire::writeFixed64($output, $value)) {
                 return false;
             }
             break;
         case GPBType::BOOL:
             if (!GPBWire::writeBool($output, $value)) {
                 return false;
             }
             break;
         case GPBType::STRING:
             if (!GPBWire::writeString($output, $value)) {
                 return false;
             }
             break;
             //    case GPBType::GROUP:
             //      echo "GROUP\xA";
             //      trigger_error("Not implemented.", E_ERROR);
             //      break;
         //    case GPBType::GROUP:
         //      echo "GROUP\xA";
         //      trigger_error("Not implemented.", E_ERROR);
         //      break;
         case GPBType::MESSAGE:
             if (!GPBWire::writeMessage($output, $value)) {
                 return false;
             }
             break;
         case GPBType::BYTES:
             if (!GPBWire::writeBytes($output, $value)) {
                 return false;
             }
             break;
         case GPBType::UINT32:
             if (!GPBWire::writeUint32($output, $value)) {
                 return false;
             }
             break;
         case GPBType::ENUM:
             if (!GPBWire::writeInt32($output, $value)) {
                 return false;
             }
             break;
         case GPBType::SFIXED32:
             if (!GPBWire::writeSfixed32($output, $value)) {
                 return false;
             }
             break;
         case GPBType::SFIXED64:
             if (!GPBWire::writeSfixed64($output, $value)) {
                 return false;
             }
             break;
         case GPBType::SINT32:
             if (!GPBWire::writeSint32($output, $value)) {
                 return false;
             }
             break;
         case GPBType::SINT64:
             if (!GPBWire::writeSint64($output, $value)) {
                 return false;
             }
             break;
         default:
             user_error("Unsupported type.");
             return false;
     }
     return true;
 }