Example #1
0
 public static byte[] serialize(com.x.protobuf.Bug11.B.Result message) {
   try {
     assertInitialized(message);
     int totalSize = 0;
     byte[] urlBuffer = null;
     if (message.hasUrl()) {
       urlBuffer = message.getUrl().getBytes("UTF-8");
       totalSize += urlBuffer.length;
       totalSize += ProtobufOutputStream.computeTagSize(2);
       totalSize += ProtobufOutputStream.computeRawVarint32Size(urlBuffer.length);
     }
     byte[] titleBuffer = null;
     if (message.hasTitle()) {
       titleBuffer = message.getTitle().getBytes("UTF-8");
       totalSize += titleBuffer.length;
       totalSize += ProtobufOutputStream.computeTagSize(3);
       totalSize += ProtobufOutputStream.computeRawVarint32Size(titleBuffer.length);
     }
     byte[] snippetsBuffer = null;
     if (message.hasSnippets()) {
       java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
       for (int i = 0; i < message.getSnippets().size(); i++) {
         ProtobufOutputStream.writeString(4, message.getSnippets().get(i), baos);
       }
       snippetsBuffer = baos.toByteArray();
       totalSize += snippetsBuffer.length;
     }
     final byte[] result = new byte[totalSize];
     int position = 0;
     if (message.hasUrl()) {
       position = ProtobufOutputStream.writeString(2, urlBuffer, result, position);
     }
     if (message.hasTitle()) {
       position = ProtobufOutputStream.writeString(3, titleBuffer, result, position);
     }
     if (message.hasSnippets()) {
       position = ProtobufOutputStream.writeRawBytes(snippetsBuffer, result, position);
     }
     ProtobufOutputStream.checkNoSpaceLeft(result, position);
     return result;
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
Example #2
0
 public static void serialize(com.x.protobuf.Bug11.B.Result message, java.io.OutputStream os) {
   try {
     assertInitialized(message);
     if (message.hasUrl()) {
       ProtobufOutputStream.writeString(2, message.getUrl(), os);
     }
     if (message.hasTitle()) {
       ProtobufOutputStream.writeString(3, message.getTitle(), os);
     }
     if (message.hasSnippets()) {
       for (int i = 0; i < message.getSnippets().size(); i++) {
         ProtobufOutputStream.writeString(4, message.getSnippets().get(i), os);
       }
     }
   } catch (IOException e) {
     throw new RuntimeException(
         "Serializing to a byte array threw an IOException (should never happen).", e);
   }
 }