GrpcMessageMarshaller { public ByteBuf serializeResponse(O message) throws IOException { switch (responseType) { case PROTOBUF: final PrototypeMarshaller<O> marshaller = (PrototypeMarshaller<O>) method.getResponseMarshaller(); return serializeProto(marshaller, (Message) message); default: final CompositeByteBuf out = alloc.compositeBuffer(); try (ByteBufOutputStream os = new ByteBufOutputStream(out)) { if (isProto) { ByteStreams.copy(method.streamResponse(message), os); } else { jsonMarshaller.serializeMessage(responseMarshaller, 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 serializeResponse() throws Exception { final ByteBuf serialized = marshaller.serializeResponse(GrpcTestUtil.RESPONSE_MESSAGE); assertThat(ByteBufUtil.getBytes(serialized)) .containsExactly(GrpcTestUtil.RESPONSE_MESSAGE.toByteArray()); serialized.release(); }