JprotobufRpcMethodInfo extends RpcMethodInfo { @Override public Object outputDecode(byte[] output) throws IOException { if (outputCodec != null) { return outputCodec.decode(output); } return null; } JprotobufRpcMethodInfo(Method method); @Override byte[] inputEncode(Object input); @Override void inputWriteToStream(Object input, CodedOutputStream stream); @Override Object outputDecode(byte[] output); @Override Object outputDecode(ByteBuf output); @Override Object outputDecode(DynamicCompositeByteBuf output); @Override Object inputDecode(byte[] input); @Override Object inputDecode(ByteBuf input); @Override Object inputDecode(DynamicCompositeByteBuf input); @Override byte[] outputEncode(Object output); @Override void outputWriteToStream(Object output, CodedOutputStream stream); @Override int getInputSerializedSize(Object input); @Override int getOutputSerializedSize(Object output);  }
@Test public void testOutputDecodeBytes() throws Exception { Method method = EchoService.class.getMethod("echo", EchoRequest.class); JprotobufRpcMethodInfo rpcMethodInfo = new JprotobufRpcMethodInfo(method); Echo.EchoResponse response = Echo.EchoResponse.newBuilder().setMessage("hello").build(); byte[] bytes = response.toByteArray(); EchoResponse response1 = (EchoResponse) rpcMethodInfo.outputDecode(bytes); Assert.assertTrue(response1.getMessage().equals(response.getMessage())); }
@Test public void testOutputDecodeByteBuf() throws Exception { Method method = EchoService.class.getMethod("echo", EchoRequest.class); JprotobufRpcMethodInfo rpcMethodInfo = new JprotobufRpcMethodInfo(method); Echo.EchoResponse response = Echo.EchoResponse.newBuilder().setMessage("hello").build(); byte[] bytes = response.toByteArray(); ByteBuf buf = Unpooled.wrappedBuffer(bytes); EchoResponse response1 = (EchoResponse) rpcMethodInfo.outputDecode(buf); Assert.assertTrue(response1.getMessage().equals(response.getMessage())); }
@Test public void testOutputDecodeDynamicCompositeByteBuf() throws Exception { Method method = EchoService.class.getMethod("echo", EchoRequest.class); JprotobufRpcMethodInfo rpcMethodInfo = new JprotobufRpcMethodInfo(method); Echo.EchoResponse response = Echo.EchoResponse.newBuilder().setMessage("hello").build(); byte[] bytes = response.toByteArray(); ByteBuf buf = Unpooled.wrappedBuffer(bytes); DynamicCompositeByteBuf compositeByteBuf = new DynamicCompositeByteBuf(buf); EchoResponse response1 = (EchoResponse) rpcMethodInfo.outputDecode(compositeByteBuf); Assert.assertTrue(response1.getMessage().equals(response.getMessage())); }