private <T> Message deserializeProto(PrototypeMarshaller<T> marshaller, ByteBuf buf) throws IOException {
        final Message prototype = (Message) marshaller.getMessagePrototype();
        if (isProto) {
            if (!buf.isReadable()) {
                return prototype.getDefaultInstanceForType();
            }
            try {
                final Message msg;
                if (useMethodMarshaller) {
                    msg = (Message) marshaller.parse(new ByteBufInputStream(buf));
                } else {
                    final CodedInputStream stream;
                    if (unsafeWrapDeserializedBuffer) {
                        stream = UnsafeByteOperations.unsafeWrap(buf.nioBuffer()).newCodedInput();
                        stream.enableAliasing(true);
                    } else {
                        stream = CodedInputStream.newInstance(buf.nioBuffer());
                    }
                    msg = prototype.getParserForType().parseFrom(stream);
                    try {
                        stream.checkLastTagWas(0);
                    } catch (InvalidProtocolBufferException e) {
                        e.setUnfinishedMessage(msg);
                        throw e;
                    }
                }
                return msg;
            } catch (InvalidProtocolBufferException e) {
                throw Status.INTERNAL.withDescription("Invalid protobuf byte sequence")
                                     .withCause(e).asRuntimeException();
            }
        } else {
            try (ByteBufInputStream is = new ByteBufInputStream(buf, /* releaseOnClose */ false)) {
                assert jsonMarshaller != null;
                return (Message) jsonMarshaller.deserializeMessage(marshaller, is);
            }
        }
    }
Marshaller for gRPC method request or response messages to and from {@link ByteBuf}. Will attempt to use
optimized code paths for known message types, and otherwise delegates to the gRPC stub.
grpc/src/main/java/com/linecorp/armeria/internal/common/grpc/GrpcMessageMarshaller.java