Beispiel #1
0
 public static byte[] serialize(com.x.protobuf.Bug11.B message) {
   try {
     int totalSize = 0;
     byte[] valBuffer = null;
     if (message.hasVal()) {
       valBuffer = message.getVal().getBytes("UTF-8");
       totalSize += valBuffer.length;
       totalSize += ProtobufOutputStream.computeTagSize(1);
       totalSize += ProtobufOutputStream.computeRawVarint32Size(valBuffer.length);
     }
     byte[] cvalBuffer = null;
     if (message.hasCval()) {
       cvalBuffer = com.x.protobuf.Bug11.CSerializer.serialize(message.getCval());
       totalSize += ProtobufOutputStream.computeTagSize(2);
       totalSize += ProtobufOutputStream.computeRawVarint32Size(cvalBuffer.length);
       totalSize += cvalBuffer.length;
     }
     byte[] resultBuffer = null;
     if (message.hasResult()) {
       java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
       for (int i = 0; i < message.getResult().size(); i++) {
         byte[] curMessageData =
             com.x.protobuf.Bug11.B.ResultSerializer.serialize(message.getResult().get(i));
         ProtobufOutputStream.writeTag(3, ProtobufInputStream.WIRETYPE_GROUP_START, baos);
         baos.write(curMessageData);
         ProtobufOutputStream.writeTag(3, ProtobufInputStream.WIRETYPE_GROUP_END, baos);
       }
       resultBuffer = baos.toByteArray();
       totalSize += resultBuffer.length;
     }
     final byte[] result = new byte[totalSize];
     int position = 0;
     if (message.hasVal()) {
       position = ProtobufOutputStream.writeString(1, valBuffer, result, position);
     }
     if (message.hasCval()) {
       position = ProtobufOutputStream.writeBytes(2, cvalBuffer, result, position);
     }
     if (message.hasResult()) {
       position = ProtobufOutputStream.writeRawBytes(resultBuffer, result, position);
     }
     ProtobufOutputStream.checkNoSpaceLeft(result, position);
     return result;
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
Beispiel #2
0
 public static void serialize(com.x.protobuf.Bug11.B message, java.io.OutputStream os) {
   try {
     if (message.hasVal()) {
       ProtobufOutputStream.writeString(1, message.getVal(), os);
     }
     if (message.hasCval()) {
       byte[] curMessageData = com.x.protobuf.Bug11.CSerializer.serialize(message.getCval());
       ProtobufOutputStream.writeMessageTag(2, os);
       ProtobufOutputStream.writeRawVarint32(curMessageData.length, os);
       os.write(curMessageData);
     }
     if (message.hasResult()) {
       for (int i = 0; i < message.getResult().size(); i++) {
         ProtobufOutputStream.writeTag(3, ProtobufInputStream.WIRETYPE_GROUP_START, os);
         os.write(com.x.protobuf.Bug11.B.ResultSerializer.serialize(message.getResult().get(i)));
         ProtobufOutputStream.writeTag(3, ProtobufInputStream.WIRETYPE_GROUP_END, os);
       }
     }
   } catch (IOException e) {
     throw new RuntimeException(
         "Serializing to a byte array threw an IOException (should never happen).", e);
   }
 }