Beispiel #1
0
 public static byte[] serialize(com.x.protobuf.Bug11.A message) {
   try {
     int totalSize = 0;
     byte[] entryBuffer = null;
     if (message.hasEntry()) {
       java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
       for (int i = 0; i < message.getEntry().size(); i++) {
         byte[] curMessageData =
             com.x.protobuf.Bug11.BSerializer.serialize(message.getEntry().get(i));
         ProtobufOutputStream.writeMessageTag(32904, baos);
         ProtobufOutputStream.writeRawVarint32(curMessageData.length, baos);
         baos.write(curMessageData);
       }
       entryBuffer = baos.toByteArray();
       totalSize += entryBuffer.length;
     }
     if (message.hasEntry2()) {
       totalSize += ProtobufOutputStream.computeInt32Size(32902, message.getEntry2());
     }
     final byte[] result = new byte[totalSize];
     int position = 0;
     if (message.hasEntry()) {
       position = ProtobufOutputStream.writeRawBytes(entryBuffer, result, position);
     }
     if (message.hasEntry2()) {
       position = ProtobufOutputStream.writeInt32(32902, message.getEntry2(), 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.A message, java.io.OutputStream os) {
   try {
     if (message.hasEntry()) {
       for (int i = 0; i < message.getEntry().size(); i++) {
         byte[] curMessageData =
             com.x.protobuf.Bug11.BSerializer.serialize(message.getEntry().get(i));
         ProtobufOutputStream.writeMessageTag(32904, os);
         ProtobufOutputStream.writeRawVarint32(curMessageData.length, os);
         os.write(curMessageData);
       }
     }
     if (message.hasEntry2()) {
       ProtobufOutputStream.writeInt32(32902, message.getEntry2(), os);
     }
   } catch (IOException e) {
     throw new RuntimeException(
         "Serializing to a byte array threw an IOException (should never happen).", e);
   }
 }