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