Search in sources :

Example 6 with CodedInputStream

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

the class ProtobufTranslationImpl method parseRequest.

@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;
    }
}
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)

Example 7 with CodedInputStream

use of com.google.protobuf.CodedInputStream in project atlas by alibaba.

the class ApkFileListUtils method getCompiledFileMd5.

private static String getCompiledFileMd5(File file) {
    String md5;
    try (InputStream is = new BufferedInputStream(new FileInputStream(file))) {
        CodedInputStream codedInputStream = CodedInputStream.newInstance(is);
        int numFiles = codedInputStream.readRawLittleEndian32();
        // Preconditions.checkState(numFiles == 1, "inline xml not implemented yet");
        long pbSize = codedInputStream.readRawLittleEndian64();
        codedInputStream.pushLimit((int) pbSize);
        CompiledFile compiledFile = CompiledFile.parser().parsePartialFrom(codedInputStream);
        md5 = MD5Util.getFileMD5(compiledFile.getSourcePath());
        // codedInputStream.pushLimit(0);
        return md5;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) CodedInputStream(com.google.protobuf.CodedInputStream) InputStream(java.io.InputStream) CodedInputStream(com.google.protobuf.CodedInputStream) CompiledFile(android.aapt.pb.internal.ResourcesInternal.CompiledFile) UncheckedIOException(org.gradle.api.UncheckedIOException) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 8 with CodedInputStream

use of com.google.protobuf.CodedInputStream in project voldemort by voldemort.

the class ProtoUtils method readToBuilder.

public static <T extends Message.Builder> T readToBuilder(DataInputStream input, T builder) throws IOException {
    int size = input.readInt();
    CodedInputStream codedIn = CodedInputStream.newInstance(input);
    codedIn.pushLimit(size);
    builder.mergeFrom(codedIn);
    return builder;
}
Also used : CodedInputStream(com.google.protobuf.CodedInputStream)

Example 9 with CodedInputStream

use of com.google.protobuf.CodedInputStream in project hbase by apache.

the class ProtobufUtil method mergeFrom.

/**
   * This version of protobuf's mergeFrom avoids the hard-coded 64MB limit for decoding
   * buffers when working with byte arrays
   * @param builder current message builder
   * @param b byte array
   * @throws IOException
   */
public static void mergeFrom(Message.Builder builder, byte[] b) throws IOException {
    final CodedInputStream codedInput = CodedInputStream.newInstance(b);
    codedInput.setSizeLimit(b.length);
    builder.mergeFrom(codedInput);
    codedInput.checkLastTagWas(0);
}
Also used : CodedInputStream(com.google.protobuf.CodedInputStream)

Example 10 with CodedInputStream

use of com.google.protobuf.CodedInputStream in project hbase by apache.

the class ProtobufUtil method mergeFrom.

/**
   * This version of protobuf's mergeFrom avoids the hard-coded 64MB limit for decoding
   * buffers when working with byte arrays
   * @param builder current message builder
   * @param b byte array
   * @param offset
   * @param length
   * @throws IOException
   */
public static void mergeFrom(Message.Builder builder, byte[] b, int offset, int length) throws IOException {
    final CodedInputStream codedInput = CodedInputStream.newInstance(b, offset, length);
    codedInput.setSizeLimit(length);
    builder.mergeFrom(codedInput);
    codedInput.checkLastTagWas(0);
}
Also used : CodedInputStream(com.google.protobuf.CodedInputStream)

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