类 ProtobufProxy

java.lang.Object
com.baidu.bjf.remoting.protobuf.ProtobufProxy

public final class ProtobufProxy extends Object
A simple protocol buffer encode and decode utility tool.
   example code as follow:
   
   User user = new User();
   ...
   Codec codec = ProtobufProxy.create(User.class);
   
   // do encode
   byte[] result = codec.encode(user);
   // do decode
   User user2 = codec.decode(result);
 
 
从以下版本开始:
1.0.0
作者:
xiemalin
  • 字段详细资料

    • DEBUG_CONTROLLER

      public static final ThreadLocal<Boolean> DEBUG_CONTROLLER
      The Constant DEBUG_CONTROLLER.
    • OUTPUT_PATH

      public static final ThreadLocal<File> OUTPUT_PATH
      The Constant OUTPUT_PATH for target directory to create generated source code out.
    • CACHE_ENABLED

      public static final ThreadLocal<Boolean> CACHE_ENABLED
      The Constant OUTPUT_PATH for target directory to create generated source code out.
  • 构造器详细资料

    • ProtobufProxy

      public ProtobufProxy()
  • 方法详细资料

    • clearCache

      public static void clearCache()
      Clear cache.
    • compile

      public static void compile(Class<?> cls, File outputPath)
      Compile.
      参数:
      cls - target class to be compiled
      outputPath - compile byte files output stream
    • create

      public static <T> Codec<T> create(Class<T> cls)
      To create a protobuf proxy class for target class.
      类型参数:
      T - generic type
      参数:
      cls - target class to parse @Protobuf annotation
      返回:
      Codec instance proxy
    • create

      public static <T> Codec<T> create(Class<T> cls, boolean debug)
      Creates the.
      类型参数:
      T - the generic type
      参数:
      cls - the cls
      debug - the debug
      返回:
      the codec
    • create

      public static <T> Codec<T> create(Class<T> cls, boolean debug, File path)
      To create a protobuf proxy class for target class.
      类型参数:
      T - target object type to be proxied.
      参数:
      cls - target object class
      debug - true will print generate java source code
      path - the path
      返回:
      proxy instance object.
    • create

      public static <T> Codec<T> create(Class<T> cls, boolean debug, File path, Compiler compiler, ICodeGenerator codeGenerator)
      To create a protobuf proxy class for target class.
      类型参数:
      T - target object type to be proxied.
      参数:
      cls - target object class
      debug - true will print generate java source code
      path - the path
      compiler - the compiler
      codeGenerator - the code generator
      返回:
      proxy instance object.
    • create

      public static <T> Codec<T> create(Class<T> cls, Compiler compiler, ICodeGenerator codeGenerator)
      To create a protobuf proxy class for target class.
      类型参数:
      T - generic type
      参数:
      cls - target class to parse @Protobuf annotation
      compiler - the compiler
      codeGenerator - the code generator
      返回:
      Codec instance proxy
    • doCreate

      protected static <T> Codec<T> doCreate(Class<T> cls, boolean debug, Compiler compiler, ICodeGenerator cg)
      To create a protobuf proxy class for target class.
      类型参数:
      T - target object type to be proxied.
      参数:
      cls - target object class
      debug - true will print generate java source code
      compiler - the compiler
      cg - the cg
      返回:
      proxy instance object.
    • dynamicCodeGenerate

      public static void dynamicCodeGenerate(OutputStream os, Class cls, Charset charset) throws IOException
      To generate a protobuf proxy java source code for target class.
      参数:
      os - to generate java source code
      cls - target class
      charset - charset type
      抛出:
      IOException - in case of any io relative exception.
    • dynamicCodeGenerate

      public static void dynamicCodeGenerate(OutputStream os, Class cls, Charset charset, ICodeGenerator codeGenerator) throws IOException
      To generate a protobuf proxy java source code for target class.
      参数:
      os - to generate java source code
      cls - target class
      charset - charset type
      codeGenerator - the code generator
      抛出:
      IOException - in case of any io relative exception.
    • enableCache

      public static void enableCache(boolean enabled)
      Enable cache.
      参数:
      enabled - the enabled
    • getFullClassName

      public static String getFullClassName(Class cls)
      Gets the full class name.
      参数:
      cls - the cls
      返回:
      the full class name
    • isCacheEnabled

      public static boolean isCacheEnabled()
      Checks if is cache enabled.
      返回:
      true, if is cache enabled
    • isDebugEnabled

      public static boolean isDebugEnabled()
      Checks if is debug enabled.
      返回:
      true, if is debug enabled