@Test public void testGetMessageType() throws Exception { Method method = EchoService.class.getMethod("echo", Echo.EchoRequest.class); ProtobufUtils.MessageType messageType = ProtobufUtils.getMessageType(method); Assert.assertTrue(messageType == ProtobufUtils.MessageType.PROTOBUF); Method method2 = com.baidu.brpc.protocol.jprotobuf.EchoService.class.getMethod("echo", EchoRequest.class); ProtobufUtils.MessageType messageType2 = ProtobufUtils.getMessageType(method2); Assert.assertTrue(messageType2 == ProtobufUtils.MessageType.JPROTOBUF); }
public static MessageType getMessageType(Method method) { Class<?>[] types = method.getParameterTypes(); Class returnType = method.getReturnType(); if (types.length < 0) { throw new IllegalArgumentException("invalid rpc method params"); } if (types.length != 1) { return MessageType.POJO; } Class<?> inputType = types[0]; if (Message.class.isAssignableFrom(inputType) && Message.class.isAssignableFrom(returnType)) { return MessageType.PROTOBUF; } ProtobufClass protobufClass = inputType.getAnnotation(ProtobufClass.class); if (protobufClass != null) { return MessageType.JPROTOBUF; } Field[] fields = inputType.getDeclaredFields(); for (Field field : fields) { Protobuf protobuf = field.getAnnotation(Protobuf.class); if (protobuf != null) { return MessageType.JPROTOBUF; } } return MessageType.POJO; }
ProtobufUtils { public static MessageType getMessageType(Method method) { Class<?>[] types = method.getParameterTypes(); Class returnType = method.getReturnType(); if (types.length < 0) { throw new IllegalArgumentException("invalid rpc method params"); } if (types.length != 1) { return MessageType.POJO; } Class<?> inputType = types[0]; if (Message.class.isAssignableFrom(inputType) && Message.class.isAssignableFrom(returnType)) { return MessageType.PROTOBUF; } ProtobufClass protobufClass = inputType.getAnnotation(ProtobufClass.class); if (protobufClass != null) { return MessageType.JPROTOBUF; } Field[] fields = inputType.getDeclaredFields(); for (Field field : fields) { Protobuf protobuf = field.getAnnotation(Protobuf.class); if (protobuf != null) { return MessageType.JPROTOBUF; } } return MessageType.POJO; } }
ProtobufUtils { public static MessageType getMessageType(Method method) { Class<?>[] types = method.getParameterTypes(); Class returnType = method.getReturnType(); if (types.length < 0) { throw new IllegalArgumentException("invalid rpc method params"); } if (types.length != 1) { return MessageType.POJO; } Class<?> inputType = types[0]; if (Message.class.isAssignableFrom(inputType) && Message.class.isAssignableFrom(returnType)) { return MessageType.PROTOBUF; } ProtobufClass protobufClass = inputType.getAnnotation(ProtobufClass.class); if (protobufClass != null) { return MessageType.JPROTOBUF; } Field[] fields = inputType.getDeclaredFields(); for (Field field : fields) { Protobuf protobuf = field.getAnnotation(Protobuf.class); if (protobuf != null) { return MessageType.JPROTOBUF; } } return MessageType.POJO; }  }
ProtobufUtils { public static MessageType getMessageType(Method method) { Class<?>[] types = method.getParameterTypes(); Class returnType = method.getReturnType(); if (types.length < 0) { throw new IllegalArgumentException("invalid rpc method params"); } if (types.length != 1) { return MessageType.POJO; } Class<?> inputType = types[0]; if (Message.class.isAssignableFrom(inputType) && Message.class.isAssignableFrom(returnType)) { return MessageType.PROTOBUF; } ProtobufClass protobufClass = inputType.getAnnotation(ProtobufClass.class); if (protobufClass != null) { return MessageType.JPROTOBUF; } Field[] fields = inputType.getDeclaredFields(); for (Field field : fields) { Protobuf protobuf = field.getAnnotation(Protobuf.class); if (protobuf != null) { return MessageType.JPROTOBUF; } } return MessageType.POJO; }  static MessageType getMessageType(Method method); static Message parseFrom(InputStream inputStream, Class clazz); static Message parseFrom(byte[] inputBytes, Class clazz); static Message parseFrom(ByteBuf input, Message defaultInstance); static Message parseFrom(byte[] input, Message defaultInstance); static Message parseFrom(DynamicCompositeByteBuf input, Message defaultInstance); }
ProtobufUtils { public static MessageType getMessageType(Method method) { Class<?>[] types = method.getParameterTypes(); Class returnType = method.getReturnType(); if (types.length < 0) { throw new IllegalArgumentException("invalid rpc method params"); } if (types.length != 1) { return MessageType.POJO; } Class<?> inputType = types[0]; if (Message.class.isAssignableFrom(inputType) && Message.class.isAssignableFrom(returnType)) { return MessageType.PROTOBUF; } ProtobufClass protobufClass = inputType.getAnnotation(ProtobufClass.class); if (protobufClass != null) { return MessageType.JPROTOBUF; } Field[] fields = inputType.getDeclaredFields(); for (Field field : fields) { Protobuf protobuf = field.getAnnotation(Protobuf.class); if (protobuf != null) { return MessageType.JPROTOBUF; } } return MessageType.POJO; }  static MessageType getMessageType(Method method); static Message parseFrom(InputStream inputStream, Class clazz); static Message parseFrom(byte[] inputBytes, Class clazz); static Message parseFrom(ByteBuf input, Message defaultInstance); static Message parseFrom(byte[] input, Message defaultInstance); static Message parseFrom(DynamicCompositeByteBuf input, Message defaultInstance);  }