class ProtobufUtils {

    public static Message parseFrom(InputStream inputStream, Class clazz) {
        try {
            Method method = clazz.getMethod("getDefaultInstance");
            Message proto = (Message) method.invoke(null);
            proto = proto.newBuilderForType().mergeFrom(inputStream).build();
            return proto;
        } catch (Exception ex) {
            String errorMsg = String.format("parse proto failed, msg=%s", ex.getMessage());
            log.error(errorMsg);
            throw new RuntimeException(errorMsg);
        }
    }

}