Search in sources :

Example 1 with CodedInputStream

use of com.google.protobuf.CodedInputStream in project sonarqube by SonarSource.

the class FileSourceDto method decodeHugeSourceData.

private static DbFileSources.Data decodeHugeSourceData(byte[] binaryData) throws IOException {
    try (LZ4BlockInputStream lz4Input = new LZ4BlockInputStream(new ByteArrayInputStream(binaryData))) {
        CodedInputStream input = CodedInputStream.newInstance(lz4Input);
        input.setSizeLimit(Integer.MAX_VALUE);
        return DbFileSources.Data.parseFrom(input);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CodedInputStream(com.google.protobuf.CodedInputStream) LZ4BlockInputStream(net.jpountz.lz4.LZ4BlockInputStream)

Example 2 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 3 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 4 with CodedInputStream

use of com.google.protobuf.CodedInputStream in project twister2 by DSC-SPIDAL.

the class ExtraActionUtils method getExtraActionInfo.

public static ExtraActionInfo getExtraActionInfo(String extraActionFile) {
    ExtensionRegistry registry = ExtensionRegistry.newInstance();
    ExtraActionsBase.registerAllExtensions(registry);
    try (InputStream stream = Files.newInputStream(Paths.get(extraActionFile))) {
        CodedInputStream coded = CodedInputStream.newInstance(stream);
        return ExtraActionInfo.parseFrom(coded, registry);
    } catch (IOException e) {
        throw new RuntimeException("ERROR: failed to deserialize extra action file " + extraActionFile + ": " + e.getMessage(), e);
    }
}
Also used : CodedInputStream(com.google.protobuf.CodedInputStream) InputStream(java.io.InputStream) CodedInputStream(com.google.protobuf.CodedInputStream) IOException(java.io.IOException) ExtensionRegistry(com.google.protobuf.ExtensionRegistry)

Example 5 with CodedInputStream

use of com.google.protobuf.CodedInputStream in project elephant-bird by twitter.

the class SerializedBlock method parseFrom.

public static SerializedBlock parseFrom(InputStream in, int maxSize) throws InvalidProtocolBufferException, IOException {
    // create a CodedInputStream so that protobuf can enforce the configured max size
    // instead of using the default which may not be large enough for this data
    CodedInputStream codedInput = CodedInputStream.newInstance(in);
    codedInput.setSizeLimit(maxSize);
    DynamicMessage.Builder messageBuilder = DynamicMessage.newBuilder(messageDescriptor).mergeFrom(codedInput);
    // verify we've read to the end
    codedInput.checkLastTagWas(0);
    return new SerializedBlock(messageBuilder.build());
}
Also used : CodedInputStream(com.google.protobuf.CodedInputStream) DynamicMessage(com.google.protobuf.DynamicMessage)

Aggregations

CodedInputStream (com.google.protobuf.CodedInputStream)25 IOException (java.io.IOException)14 InputStream (java.io.InputStream)7 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 WireMessage (org.apache.calcite.avatica.proto.Common.WireMessage)2 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 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1