GrpcMessageMarshaller { public ByteBuf serializeRequest(I message) throws IOException { switch (requestType) { case PROTOBUF: final PrototypeMarshaller<I> marshaller = (PrototypeMarshaller<I>) requestMarshaller; return serializeProto(marshaller, (Message) message); default: final CompositeByteBuf out = alloc.compositeBuffer(); try (ByteBufOutputStream os = new ByteBufOutputStream(out)) { if (isProto) { ByteStreams.copy(method.streamRequest(message), os); } else { jsonMarshaller.serializeMessage(requestMarshaller, message, os); } } return out; } } GrpcMessageMarshaller(ByteBufAllocator alloc,
                                 SerializationFormat serializationFormat,
                                 MethodDescriptor<I, O> method,
                                 @Nullable GrpcJsonMarshaller jsonMarshaller,
                                 boolean unsafeWrapDeserializedBuffer); ByteBuf serializeRequest(I message); I deserializeRequest(DeframedMessage message, boolean grpcWebText); ByteBuf serializeResponse(O message); O deserializeResponse(DeframedMessage message, boolean grpcWebText);  }
@Test public void serializeRequest() throws Exception { final ByteBuf serialized = marshaller.serializeRequest(GrpcTestUtil.REQUEST_MESSAGE); assertThat(ByteBufUtil.getBytes(serialized)) .containsExactly(GrpcTestUtil.REQUEST_MESSAGE.toByteArray()); serialized.release(); }