类 CodedConstant

java.lang.Object
com.baidu.bjf.remoting.protobuf.code.CodedConstant

public class CodedConstant extends Object
Utility class for codec.
从以下版本开始:
1.0.0
作者:
xiemalin
  • 构造器概要

    构造器
    构造器
    说明
     
  • 方法概要

    修饰符和类型
    方法
    说明
    static List
    asList(String value)
    As list.
    static String
    Capitalizes a String changing the first letter to title case as per Character.toTitleCase(char).
    static int
    computeElementSize(com.google.protobuf.WireFormat.FieldType type, int number, Object value)
    Compute the number of bytes that would be needed to encode a single tag/value pair of arbitrary type.
    static int
    computeElementSizeNoTag(com.google.protobuf.WireFormat.FieldType type, Object value)
    Compute the number of bytes that would be needed to encode a particular value of arbitrary type, excluding tag.
    static int
    Compute length delimited field size.
    static int
    computeListSize(int order, Collection<?> list, FieldType type, boolean debug, File path)
    Compute list size.
    static int
    computeListSize(int order, Collection list, FieldType type, boolean debug, File path, boolean packed)
    Compute list size.
    static int
    computeListSize(int order, Collection list, FieldType type, boolean debug, File path, boolean packed, boolean sizeOnly)
    Compute list size.
    static <K, V> int
    computeMapSize(int order, Map<K,V> map, com.google.protobuf.WireFormat.FieldType keyType, K defaultKey, com.google.protobuf.WireFormat.FieldType valueType, V defalutValue)
    Compute map size.
    static int
    Compute object size no tag.
    static int
    computeSize(int order, Object o, FieldType type, boolean list, boolean debug, File path)
    get object size by FieldType.
    static int
    computeSize(int order, Object o, FieldType type, boolean debug, File path)
    get object size by FieldType.
    static com.google.protobuf.Descriptors.Descriptor
    Gets the descriptor.
    static String
    getEnumName(Enum[] e, int value)
    Gets the enum name.
    static <T extends Enum<T>>
    T
    getEnumValue(Class<T> enumType, String name)
    Gets the enumeration value.
    static int
    Gets the enum value.
    static String
    getFieldName(int order)
    get field name.
    static String
    getFiledType(FieldType type, boolean isList)
    Gets the filed type.
    static String
    Gets the map field generic parameter string.
    static String
    getMappedTypeDefined(int order, FieldType type, String express, boolean isList, boolean isMap)
    get mapped type defined java expression.
    static String
    getMappedTypeSize(FieldInfo field, int order, FieldType type, boolean isList, boolean isMap, boolean debug, File path)
    Gets the mapped type size.
    static String
    getMappedWriteCode(FieldInfo field, String prefix, int order, FieldType type, boolean isList, boolean isMap)
    get mapped object byte write java expression.
    static String
    getRequiredCheck(int order, Field field)
    get required field check java expression.
    static String
    getRetRequiredCheck(String express, Field field)
    get return required field check java expression.
    static String
    getWriteValueToField(FieldType type, String express, boolean isList)
    Gets the write value to field.
    static boolean
    isNull(byte o)
    check byte is null.
    static boolean
    isNull(char o)
    check char is null.
    static boolean
    isNull(double o)
    check double is null.
    static boolean
    isNull(float o)
    check float is null.
    static boolean
    isNull(int o)
    check int is null.
    static boolean
    isNull(long o)
    check long is null.
    static boolean
    isNull(short o)
    check short is null.
    static boolean
    check object is null.
    static int
    makeTag(int fieldNumber, int wireType)
    make protobuf tag.
    static <K, V> void
    putMapValue(com.google.protobuf.CodedInputStream input, Map<K,V> map, com.google.protobuf.WireFormat.FieldType keyType, K defaultKey, com.google.protobuf.WireFormat.FieldType valueType, V defalutValue)
    Put map value.
    static <K, V> void
    putMapValue(com.google.protobuf.CodedInputStream input, Map<K,V> map, com.google.protobuf.WireFormat.FieldType keyType, K defaultKey, com.google.protobuf.WireFormat.FieldType valueType, V defalutValue, EnumHandler<K> keyHandler, EnumHandler<V> valHandler)
     
    static <K, V> void
    putMapValue(com.google.protobuf.CodedInputStream input, Map<K,V> map, com.google.protobuf.WireFormat.FieldType keyType, K defaultKey, com.google.protobuf.WireFormat.FieldType valueType, V defalutValue, EnumHandler<V> handler)
     
    static Object
    readPrimitiveField(com.google.protobuf.CodedInputStream input, com.google.protobuf.WireFormat.FieldType type, boolean checkUtf8)
    Read a field of any primitive type for immutable messages from a CodedInputStream.
    static void
    writeElement(com.google.protobuf.CodedOutputStream output, com.google.protobuf.WireFormat.FieldType type, int number, Object value)
    Write a single tag-value pair to the stream.
    static void
    writeElementNoTag(com.google.protobuf.CodedOutputStream output, com.google.protobuf.WireFormat.FieldType type, Object value)
    Write a field of arbitrary type, without its tag, to the stream.
    static void
    writeObject(com.google.protobuf.CodedOutputStream out, int order, FieldType type, Object o, boolean list)
    Write object.
    static void
    writeObject(com.google.protobuf.CodedOutputStream out, int order, FieldType type, Object o, boolean list, boolean withTag)
    Write object to byte array by FieldType.
    static void
    writeToList(com.google.protobuf.CodedOutputStream out, int order, FieldType type, Collection list)
    Write to list.
    static void
    writeToList(com.google.protobuf.CodedOutputStream out, int order, FieldType type, Collection list, boolean packed)
    write list to CodedOutputStream object.
    static <K, V> void
    writeToMap(com.google.protobuf.CodedOutputStream output, int order, Map<K,V> map, com.google.protobuf.WireFormat.FieldType keyType, K defaultKey, com.google.protobuf.WireFormat.FieldType valueType, V defalutValue)
    Write to map.

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 构造器详细资料

    • CodedConstant

      public CodedConstant()
  • 方法详细资料

    • getFieldName

      public static String getFieldName(int order)
      get field name.
      参数:
      order - field order
      返回:
      field name
    • computeElementSize

      public static int computeElementSize(com.google.protobuf.WireFormat.FieldType type, int number, Object value)
      Compute the number of bytes that would be needed to encode a single tag/value pair of arbitrary type.
      参数:
      type - The field's type.
      number - The field's number.
      value - Object representing the field's value. Must be of the exact type which would be returned by MessageOrBuilder.getField(Descriptors.FieldDescriptor) for this field.
      返回:
      the int
    • getMappedTypeDefined

      public static String getMappedTypeDefined(int order, FieldType type, String express, boolean isList, boolean isMap)
      get mapped type defined java expression.
      参数:
      order - field order
      type - field type
      express - java expression
      isList - is field type is a List
      isMap - is field type is a Map
      返回:
      full java expression
    • getFiledType

      public static String getFiledType(FieldType type, boolean isList)
      Gets the filed type.
      参数:
      type - the type
      isList - the is list
      返回:
      the filed type
    • getWriteValueToField

      public static String getWriteValueToField(FieldType type, String express, boolean isList)
      Gets the write value to field.
      参数:
      type - the type
      express - the express
      isList - the is list
      返回:
      the write value to field
    • getMappedTypeSize

      public static String getMappedTypeSize(FieldInfo field, int order, FieldType type, boolean isList, boolean isMap, boolean debug, File path)
      Gets the mapped type size.
      参数:
      field - field
      order - field order
      type - field type
      isList - is field type is a List
      isMap - the is map
      debug - debug mode if true enable debug.
      path - the path
      返回:
      full java expression
    • getMapFieldGenericParameterString

      public static String getMapFieldGenericParameterString(FieldInfo field)
      Gets the map field generic parameter string.
      参数:
      field - the field
      返回:
      the map field generic parameter string
    • computeListSize

      public static int computeListSize(int order, Collection<?> list, FieldType type, boolean debug, File path)
      Compute list size.
      参数:
      order - field order
      list - field value
      type - field type of list obj
      debug - the debug
      path - the path
      返回:
      full java expression
    • computeListSize

      public static int computeListSize(int order, Collection list, FieldType type, boolean debug, File path, boolean packed)
      Compute list size.
      参数:
      order - the order
      list - the list
      type - the type
      debug - the debug
      path - the path
      packed - the packed
      返回:
      the int
    • computeListSize

      public static int computeListSize(int order, Collection list, FieldType type, boolean debug, File path, boolean packed, boolean sizeOnly)
      Compute list size.
      参数:
      order - the order
      list - the list
      type - the type
      debug - the debug
      path - the path
      packed - the packed
      sizeOnly - the size only if true will not include order size and tag size
      返回:
      the int
    • computeMapSize

      public static <K, V> int computeMapSize(int order, Map<K,V> map, com.google.protobuf.WireFormat.FieldType keyType, K defaultKey, com.google.protobuf.WireFormat.FieldType valueType, V defalutValue)
      Compute map size.
      类型参数:
      K - the key type
      V - the value type
      参数:
      order - the order
      map - the map
      keyType - the key type
      defaultKey - the default key
      valueType - the value type
      defalutValue - the defalut value
      返回:
      the int
    • putMapValue

      public static <K, V> void putMapValue(com.google.protobuf.CodedInputStream input, Map<K,V> map, com.google.protobuf.WireFormat.FieldType keyType, K defaultKey, com.google.protobuf.WireFormat.FieldType valueType, V defalutValue) throws IOException
      Put map value.
      类型参数:
      K - the key type
      V - the value type
      参数:
      input - the input
      map - the map
      keyType - the key type
      defaultKey - the default key
      valueType - the value type
      defalutValue - the defalut value
      抛出:
      IOException - Signals that an I/O exception has occurred.
    • putMapValue

      public static <K, V> void putMapValue(com.google.protobuf.CodedInputStream input, Map<K,V> map, com.google.protobuf.WireFormat.FieldType keyType, K defaultKey, com.google.protobuf.WireFormat.FieldType valueType, V defalutValue, EnumHandler<V> handler) throws IOException
      抛出:
      IOException
    • putMapValue

      public static <K, V> void putMapValue(com.google.protobuf.CodedInputStream input, Map<K,V> map, com.google.protobuf.WireFormat.FieldType keyType, K defaultKey, com.google.protobuf.WireFormat.FieldType valueType, V defalutValue, EnumHandler<K> keyHandler, EnumHandler<V> valHandler) throws IOException
      抛出:
      IOException
    • writeToMap

      public static <K, V> void writeToMap(com.google.protobuf.CodedOutputStream output, int order, Map<K,V> map, com.google.protobuf.WireFormat.FieldType keyType, K defaultKey, com.google.protobuf.WireFormat.FieldType valueType, V defalutValue) throws IOException
      Write to map.
      类型参数:
      K - the key type
      V - the value type
      参数:
      output - the output
      order - the order
      map - the map
      keyType - the key type
      defaultKey - the default key
      valueType - the value type
      defalutValue - the defalut value
      抛出:
      IOException - Signals that an I/O exception has occurred.
    • computeSize

      public static int computeSize(int order, Object o, FieldType type, boolean debug, File path)
      get object size by FieldType.
      参数:
      order - the order
      o - the o
      type - the type
      debug - the debug
      path - the path
      返回:
      the int
    • computeObjectSizeNoTag

      public static int computeObjectSizeNoTag(Object o)
      Compute object size no tag.
      参数:
      o - the o
      返回:
      the int
    • computeSize

      public static int computeSize(int order, Object o, FieldType type, boolean list, boolean debug, File path)
      get object size by FieldType.
      参数:
      order - the order
      o - the o
      type - the type
      list - the list
      debug - the debug
      path - the path
      返回:
      the int
    • getMappedWriteCode

      public static String getMappedWriteCode(FieldInfo field, String prefix, int order, FieldType type, boolean isList, boolean isMap)
      get mapped object byte write java expression.
      参数:
      field - the field
      prefix - the prefix
      order - field order
      type - field type
      isList - the is list
      isMap - the is map
      返回:
      full java expression
    • writeToList

      public static void writeToList(com.google.protobuf.CodedOutputStream out, int order, FieldType type, Collection list) throws IOException
      Write to list.
      参数:
      out - the out
      order - the order
      type - the type
      list - the list
      抛出:
      IOException - Signals that an I/O exception has occurred.
    • writeToList

      public static void writeToList(com.google.protobuf.CodedOutputStream out, int order, FieldType type, Collection list, boolean packed) throws IOException
      write list to CodedOutputStream object.
      参数:
      out - target output stream to write
      order - field order
      type - field type
      list - target list object to be serialized
      packed - the packed
      抛出:
      IOException - Signals that an I/O exception has occurred.
    • writeObject

      public static void writeObject(com.google.protobuf.CodedOutputStream out, int order, FieldType type, Object o, boolean list) throws IOException
      Write object.
      参数:
      out - the out
      order - the order
      type - the type
      o - the o
      list - the list
      抛出:
      IOException - Signals that an I/O exception has occurred.
    • writeObject

      public static void writeObject(com.google.protobuf.CodedOutputStream out, int order, FieldType type, Object o, boolean list, boolean withTag) throws IOException
      Write object to byte array by FieldType.
      参数:
      out - the out
      order - the order
      type - the type
      o - the o
      list - the list
      withTag - the with tag
      抛出:
      IOException - Signals that an I/O exception has occurred.
    • getRequiredCheck

      public static String getRequiredCheck(int order, Field field)
      get required field check java expression.
      参数:
      order - field order
      field - java field
      返回:
      full java expression
    • getRetRequiredCheck

      public static String getRetRequiredCheck(String express, Field field)
      get return required field check java expression.
      参数:
      express - java expression
      field - java field
      返回:
      full java expression
    • isNull

      public static boolean isNull(Object o)
      check object is null.
      参数:
      o - to check
      返回:
      true if is null
    • isNull

      public static boolean isNull(double o)
      check double is null.
      参数:
      o - to check
      返回:
      true if is null
    • isNull

      public static boolean isNull(int o)
      check int is null.
      参数:
      o - to check
      返回:
      true if is null
    • isNull

      public static boolean isNull(byte o)
      check byte is null.
      参数:
      o - to check
      返回:
      true if is null
    • isNull

      public static boolean isNull(short o)
      check short is null.
      参数:
      o - to check
      返回:
      true if is null
    • isNull

      public static boolean isNull(long o)
      check long is null.
      参数:
      o - to check
      返回:
      true if is null
    • isNull

      public static boolean isNull(float o)
      check float is null.
      参数:
      o - to check
      返回:
      true if is null
    • isNull

      public static boolean isNull(char o)
      check char is null.
      参数:
      o - to check
      返回:
      true if is null
    • asList

      public static List asList(String value)
      As list.
      参数:
      value - the value
      返回:
      the list
    • capitalize

      public static String capitalize(String str)

      Capitalizes a String changing the first letter to title case as per Character.toTitleCase(char). No other letters are changed.

      参数:
      str - the String to capitalize, may be null
      返回:
      the capitalized String, null if null String input
    • makeTag

      public static int makeTag(int fieldNumber, int wireType)
      make protobuf tag.
      参数:
      fieldNumber - field number order
      wireType - wireformat type
      返回:
      tag id
    • getEnumName

      public static String getEnumName(Enum[] e, int value)
      Gets the enum name.
      参数:
      e - the e
      value - the value
      返回:
      the enum name
    • getEnumValue

      public static int getEnumValue(Enum en)
      Gets the enum value.
      参数:
      en - the en
      返回:
      the enum value
    • getEnumValue

      public static <T extends Enum<T>> T getEnumValue(Class<T> enumType, String name)
      Gets the enumeration value.
      类型参数:
      T - the generic type
      参数:
      enumType - the enum type
      name - the name
      返回:
      the enum value
    • readPrimitiveField

      public static Object readPrimitiveField(com.google.protobuf.CodedInputStream input, com.google.protobuf.WireFormat.FieldType type, boolean checkUtf8) throws IOException
      Read a field of any primitive type for immutable messages from a CodedInputStream. Enums, groups, and embedded messages are not handled by this method.
      参数:
      input - The stream from which to read.
      type - Declared type of the field.
      checkUtf8 - When true, check that the input is valid utf8.
      返回:
      An object representing the field's value, of the exact type which would be returned by MessageOrBuilder.getField(Descriptors.FieldDescriptor) for this field.
      抛出:
      IOException - Signals that an I/O exception has occurred.
    • writeElement

      public static void writeElement(com.google.protobuf.CodedOutputStream output, com.google.protobuf.WireFormat.FieldType type, int number, Object value) throws IOException
      Write a single tag-value pair to the stream.
      参数:
      output - The output stream.
      type - The field's type.
      number - The field's number.
      value - Object representing the field's value. Must be of the exact type which would be returned by MessageOrBuilder.getField(Descriptors.FieldDescriptor) for this field.
      抛出:
      IOException - Signals that an I/O exception has occurred.
    • writeElementNoTag

      public static void writeElementNoTag(com.google.protobuf.CodedOutputStream output, com.google.protobuf.WireFormat.FieldType type, Object value) throws IOException
      Write a field of arbitrary type, without its tag, to the stream.
      参数:
      output - The output stream.
      type - The field's type.
      value - Object representing the field's value. Must be of the exact type which would be returned by MessageOrBuilder.getField(Descriptors.FieldDescriptor) for this field.
      抛出:
      IOException - Signals that an I/O exception has occurred.
    • computeLengthDelimitedFieldSize

      public static int computeLengthDelimitedFieldSize(int fieldLength)
      Compute length delimited field size.
      参数:
      fieldLength - the field length
      返回:
      the int
    • computeElementSizeNoTag

      public static int computeElementSizeNoTag(com.google.protobuf.WireFormat.FieldType type, Object value)
      Compute the number of bytes that would be needed to encode a particular value of arbitrary type, excluding tag.
      参数:
      type - The field's type.
      value - Object representing the field's value. Must be of the exact type which would be returned by MessageOrBuilder.getField(Descriptors.FieldDescriptor) for this field.
      返回:
      the int
    • getDescriptor

      public static com.google.protobuf.Descriptors.Descriptor getDescriptor(Class<?> cls) throws IOException
      Gets the descriptor.
      参数:
      cls - the cls
      返回:
      the descriptor
      抛出:
      IOException - Signals that an I/O exception has occurred.