Exemplo n.º 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);
   }
 }
Exemplo n.º 2
0
 public static com.x.protobuf.Bug11.A parseFrom(byte[] data, CurrentCursor cursor)
     throws java.io.IOException {
   com.x.protobuf.Bug11.A message = new com.x.protobuf.Bug11.A();
   while (true) {
     if (ProtobufInputStream.isAtEnd(data, cursor)) {
       return message;
     }
     int varint = ProtobufInputStream.readRawVarint32(data, cursor);
     int tag = ProtobufInputStream.getTagFieldNumber(varint);
     switch (tag) {
       case 0:
         return message;
       default:
         ProtobufInputStream.skipUnknown(varint, data, cursor);
         break;
       case 32904:
         if (message.getEntry() == null || message.getEntry().isEmpty()) {
           message.setEntry(new java.util.ArrayList<com.x.protobuf.Bug11.B>());
         }
         int lengthEntry = ProtobufInputStream.readRawVarint32(data, cursor);
         message
             .getEntry()
             .add(
                 com.x.protobuf.Bug11.BSerializer.parseFrom(
                     data, cursor.getCurrentPosition(), lengthEntry));
         cursor.addToPosition(lengthEntry);
         break;
       case 32902:
         message.setEntry2(ProtobufInputStream.readInt32(data, cursor));
         break;
     }
   }
 }
Exemplo n.º 3
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);
   }
 }