Search in sources :

Example 26 with CodedInputStream

use of com.google.protobuf.CodedInputStream in project calcite-avatica by apache.

the class ProtobufTranslationImpl method parseResponse.

@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;
    }
}
Also used : ByteString(com.google.protobuf.ByteString) CodedInputStream(com.google.protobuf.CodedInputStream) WireMessage(org.apache.calcite.avatica.proto.Common.WireMessage) ByteString(com.google.protobuf.ByteString)

Aggregations

CodedInputStream (com.google.protobuf.CodedInputStream)26 IOException (java.io.IOException)15 InputStream (java.io.InputStream)8 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)4 ByteString (com.google.protobuf.ByteString)3 ExtensionRegistry (com.google.protobuf.ExtensionRegistry)3 BytesWritable (org.apache.hadoop.io.BytesWritable)3 Text (org.apache.hadoop.io.Text)3 ChangedFile (boa.types.Diff.ChangedFile)2 Protocol (communication.Protocol)2 FileInputStream (java.io.FileInputStream)2 WireMessage (org.apache.calcite.avatica.proto.Common.WireMessage)2 CompiledFile (android.aapt.pb.internal.ResourcesInternal.CompiledFile)1 IssuesRoot (boa.types.Issues.IssuesRoot)1 DynamicMessage (com.google.protobuf.DynamicMessage)1 Parser (com.google.protobuf.Parser)1 MotanFrameworkException (com.weibo.api.motan.exception.MotanFrameworkException)1 KnownLength (io.grpc.KnownLength)1 PrototypeMarshaller (io.grpc.MethodDescriptor.PrototypeMarshaller)1 BufferedInputStream (java.io.BufferedInputStream)1