ProtobufRpcMethodInfo extends RpcMethodInfo { @Override public Object outputDecode(byte[] output) throws IOException { if (outputParseFromMethod != null && output != null) { try { return outputParseFromMethod.invoke(outputClass, output); } catch (Exception e) { throw new IOException(e.getMessage(), e); } } return null; } ProtobufRpcMethodInfo(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); Object outputDecode(InputStream stream); Object inputDecode(byte[] input); Object inputDecode(byte[] input, int offset, int len); Object inputDecode(ByteBuf input); Object inputDecode(DynamicCompositeByteBuf input); Object inputDecode(InputStream stream); 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", Echo.EchoRequest.class); ProtobufRpcMethodInfo rpcMethodInfo = new ProtobufRpcMethodInfo(method); Echo.EchoResponse response = Echo.EchoResponse.newBuilder().setMessage("hello").build(); byte[] bytes = response.toByteArray(); Echo.EchoResponse response1 = (Echo.EchoResponse) rpcMethodInfo.outputDecode(bytes); Assert.assertTrue(response1.getMessage().equals(response.getMessage())); }
@Test public void testOutputDecodeByteBuf() throws Exception { Method method = EchoService.class.getMethod("echo", Echo.EchoRequest.class); ProtobufRpcMethodInfo rpcMethodInfo = new ProtobufRpcMethodInfo(method); Echo.EchoResponse response = Echo.EchoResponse.newBuilder().setMessage("hello").build(); byte[] bytes = response.toByteArray(); ByteBuf buf = Unpooled.wrappedBuffer(bytes); Echo.EchoResponse response1 = (Echo.EchoResponse) rpcMethodInfo.outputDecode(buf); Assert.assertTrue(response1.getMessage().equals(response.getMessage())); }
@Test public void testOutputDecodeDynamicCompositeByteBuf() throws Exception { Method method = EchoService.class.getMethod("echo", Echo.EchoRequest.class); ProtobufRpcMethodInfo rpcMethodInfo = new ProtobufRpcMethodInfo(method); Echo.EchoResponse response = Echo.EchoResponse.newBuilder().setMessage("hello").build(); byte[] bytes = response.toByteArray(); ByteBuf buf = Unpooled.wrappedBuffer(bytes); DynamicCompositeByteBuf compositeByteBuf = new DynamicCompositeByteBuf(buf); Echo.EchoResponse response1 = (Echo.EchoResponse) rpcMethodInfo.outputDecode(compositeByteBuf); Assert.assertTrue(response1.getMessage().equals(response.getMessage())); }
@Test public void testOutputDecodeStream() throws Exception { Method method = EchoService.class.getMethod("echo", Echo.EchoRequest.class); ProtobufRpcMethodInfo rpcMethodInfo = new ProtobufRpcMethodInfo(method); Echo.EchoResponse response = Echo.EchoResponse.newBuilder().setMessage("hello").build(); byte[] bytes = response.toByteArray(); ByteBuf buf = Unpooled.wrappedBuffer(bytes); ByteBufInputStream inputStream = new ByteBufInputStream(buf); Echo.EchoResponse response1 = (Echo.EchoResponse) rpcMethodInfo.outputDecode(inputStream); Assert.assertTrue(response1.getMessage().equals(response.getMessage())); }