use of com.google.protobuf.nano.CodedInputByteBufferNano in project grpc-java by grpc.
the class NanoUtils method marshaller.
/** Adapt {@code parser} to a {@code Marshaller}. */
public static <T extends MessageNano> Marshaller<T> marshaller(final MessageNanoFactory<T> factory) {
return new Marshaller<T>() {
@Override
public InputStream stream(T value) {
return new NanoProtoInputStream(value);
}
@Override
public T parse(InputStream stream) {
try {
// TODO(simonma): Investigate whether we can do 0-copy here.
CodedInputByteBufferNano input = CodedInputByteBufferNano.newInstance(ByteStreams.toByteArray(stream));
input.setSizeLimit(Integer.MAX_VALUE);
T message = factory.newInstance();
message.mergeFrom(input);
return message;
} catch (IOException ipbe) {
throw Status.INTERNAL.withDescription("Failed parsing nano proto message").withCause(ipbe).asRuntimeException();
}
}
};
}
Aggregations