Java Code Examples for com.google.protobuf.ByteString.newCodedInput()

The following are Jave code examples for showing how to use newCodedInput() of the com.google.protobuf.ByteString class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: calcite-avatica   File: ProtobufTranslationImpl.java   Source Code and License Vote up 6 votes
@Override public Request parseRequest(byte[] bytes) throws IOException {
  ByteString byteString = UnsafeByteOperations.unsafeWrap(bytes);
  CodedInputStream inputStream = byteString.newCodedInput();
  // Enable aliasing to avoid an extra copy to get at the serialized Request inside of the
  // WireMessage.
  inputStream.enableAliasing(true);
  WireMessage wireMsg = WireMessage.parseFrom(inputStream);

  String serializedMessageClassName = wireMsg.getName();

  try {
    RequestTranslator translator = getParserForRequest(serializedMessageClassName);

    // The ByteString should be logical offsets into the original byte array
    return translator.transform(wireMsg.getWrappedMessage());
  } catch (RuntimeException e) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Failed to parse request message '{}'", TextFormat.shortDebugString(wireMsg));
    }
    throw e;
  }
}
 
Example 2
Project: calcite-avatica   File: ProtobufTranslationImpl.java   Source Code and License Vote up 6 votes
@Override public Response parseResponse(byte[] bytes) throws IOException {
  ByteString byteString = UnsafeByteOperations.unsafeWrap(bytes);
  CodedInputStream inputStream = byteString.newCodedInput();
  // Enable aliasing to avoid an extra copy to get at the serialized Response inside of the
  // WireMessage.
  inputStream.enableAliasing(true);
  WireMessage wireMsg = WireMessage.parseFrom(inputStream);

  String serializedMessageClassName = wireMsg.getName();
  try {
    ResponseTranslator translator = getParserForResponse(serializedMessageClassName);

    return translator.transform(wireMsg.getWrappedMessage());
  } catch (RuntimeException e) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Failed to parse response message '{}'", TextFormat.shortDebugString(wireMsg));
    }
    throw e;
  }
}
 
Example 3
Project: ditb   File: ProtobufUtil.java   Source Code and License Vote up 3 votes
/**
 * This version of protobuf's mergeFrom avoids the hard-coded 64MB limit for decoding
 * buffers when working with ByteStrings
 * @param builder current message builder
 * @param bs ByteString containing the 
 * @throws IOException 
 */
public static void mergeFrom(Message.Builder builder, ByteString bs) throws IOException {
  final CodedInputStream codedInput = bs.newCodedInput();
  codedInput.setSizeLimit(bs.size());
  builder.mergeFrom(codedInput);
  codedInput.checkLastTagWas(0);
}