示例#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);
   }
 }
示例#2
0
 public static com.x.protobuf.Bug11.B parseFrom(java.io.InputStream is, CurrentCursor cursor)
     throws java.io.IOException {
   com.x.protobuf.Bug11.B message = new com.x.protobuf.Bug11.B();
   while (true) {
     if (cursor.getCurrentPosition() == cursor.getProcessUpToPosition()) {
       return message;
     }
     int varint = ProtobufInputStream.readRawVarint32(is, cursor);
     int tag = ProtobufInputStream.getTagFieldNumber(varint);
     if (ProtobufInputStream.isAtEnd(cursor)) {
       return message;
     }
     switch (tag) {
       case 0:
         return message;
       default:
         ProtobufInputStream.skipUnknown(varint, is, cursor);
         break;
       case 1:
         message.setVal(ProtobufInputStream.readString(is, cursor));
         break;
       case 2:
         int lengthCval = ProtobufInputStream.readRawVarint32(is, cursor);
         message.setCval(
             com.x.protobuf.Bug11.CSerializer.parseFrom(
                 is, cursor.getCurrentPosition(), lengthCval));
         cursor.addToPosition(lengthCval);
         break;
       case 3:
         if (message.getResult() == null || message.getResult().isEmpty()) {
           message.setResult(new java.util.ArrayList<com.x.protobuf.Bug11.B.Result>());
         }
         com.x.protobuf.Bug11.B.Result tempResult =
             com.x.protobuf.Bug11.B.ResultSerializer.parseFrom(is, cursor);
         message.getResult().add(tempResult);
         break;
     }
   }
 }
示例#3
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);
   }
 }