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);
}
}
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;
}
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;
}
}
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);
}
}
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());
}
Aggregations