类 CodedConstant
java.lang.Object
com.baidu.bjf.remoting.protobuf.code.CodedConstant
Utility class for codec.
- 从以下版本开始:
- 1.0.0
- 作者:
- xiemalin
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static ListAs list.static Stringcapitalize(String str) Capitalizes a String changing the first letter to title case as perCharacter.toTitleCase(char).static intcomputeElementSize(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 intcomputeElementSizeNoTag(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 intcomputeLengthDelimitedFieldSize(int fieldLength) Compute length delimited field size.static intcomputeListSize(int order, Collection<?> list, FieldType type, boolean debug, File path) Compute list size.static intcomputeListSize(int order, Collection list, FieldType type, boolean debug, File path, boolean packed) Compute list size.static intcomputeListSize(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 intCompute object size no tag.static intcomputeSize(int order, Object o, FieldType type, boolean list, boolean debug, File path) get object size byFieldType.static intcomputeSize(int order, Object o, FieldType type, boolean debug, File path) get object size byFieldType.static com.google.protobuf.Descriptors.DescriptorgetDescriptor(Class<?> cls) Gets the descriptor.static StringgetEnumName(Enum[] e, int value) Gets the enum name.static <T extends Enum<T>>
TgetEnumValue(Class<T> enumType, String name) Gets the enumeration value.static intgetEnumValue(Enum en) Gets the enum value.static StringgetFieldName(int order) get field name.static StringgetFiledType(FieldType type, boolean isList) Gets the filed type.static StringGets the map field generic parameter string.static StringgetMappedTypeDefined(int order, FieldType type, String express, boolean isList, boolean isMap) get mapped type defined java expression.static StringgetMappedTypeSize(FieldInfo field, int order, FieldType type, boolean isList, boolean isMap, boolean debug, File path) Gets the mapped type size.static StringgetMappedWriteCode(FieldInfo field, String prefix, int order, FieldType type, boolean isList, boolean isMap) get mapped object byte write java expression.static StringgetRequiredCheck(int order, Field field) get required field check java expression.static StringgetRetRequiredCheck(String express, Field field) get return required field check java expression.static StringgetWriteValueToField(FieldType type, String express, boolean isList) Gets the write value to field.static booleanisNull(byte o) check byte is null.static booleanisNull(char o) check char is null.static booleanisNull(double o) check double is null.static booleanisNull(float o) check float is null.static booleanisNull(int o) check int is null.static booleanisNull(long o) check long is null.static booleanisNull(short o) check short is null.static booleancheck object is null.static intmakeTag(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 ObjectreadPrimitiveField(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 voidwriteElement(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 voidwriteElementNoTag(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 voidwriteObject(com.google.protobuf.CodedOutputStream out, int order, FieldType type, Object o, boolean list) Write object.static voidwriteObject(com.google.protobuf.CodedOutputStream out, int order, FieldType type, Object o, boolean list, boolean withTag) Write object to byte array byFieldType.static voidwriteToList(com.google.protobuf.CodedOutputStream out, int order, FieldType type, Collection list) Write to list.static voidwriteToList(com.google.protobuf.CodedOutputStream out, int order, FieldType type, Collection list, boolean packed) write list toCodedOutputStreamobject.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.
-
构造器详细资料
-
CodedConstant
public CodedConstant()
-
-
方法详细资料
-
getFieldName
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 byMessageOrBuilder.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. -
getFiledType
Gets the filed type.- 参数:
type- the typeisList- the is list- 返回:
- the filed type
-
getWriteValueToField
Gets the write value to field.- 参数:
type- the typeexpress- the expressisList- 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- fieldorder- field ordertype- field typeisList- is field type is aListisMap- the is mapdebug- debug mode if true enable debug.path- the path- 返回:
- full java expression
-
getMapFieldGenericParameterString
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 orderlist- field valuetype- field type of list objdebug- the debugpath- 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 orderlist- the listtype- the typedebug- the debugpath- the pathpacked- 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 orderlist- the listtype- the typedebug- the debugpath- the pathpacked- the packedsizeOnly- 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 typeV- the value type- 参数:
order- the ordermap- the mapkeyType- the key typedefaultKey- the default keyvalueType- the value typedefalutValue- 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 IOExceptionPut map value.- 类型参数:
K- the key typeV- the value type- 参数:
input- the inputmap- the mapkeyType- the key typedefaultKey- the default keyvalueType- the value typedefalutValue- 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 IOExceptionWrite to map.- 类型参数:
K- the key typeV- the value type- 参数:
output- the outputorder- the ordermap- the mapkeyType- the key typedefaultKey- the default keyvalueType- the value typedefalutValue- the defalut value- 抛出:
IOException- Signals that an I/O exception has occurred.
-
computeSize
get object size byFieldType.- 参数:
order- the ordero- the otype- the typedebug- the debugpath- the path- 返回:
- the int
-
computeObjectSizeNoTag
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 byFieldType.- 参数:
order- the ordero- the otype- the typelist- the listdebug- the debugpath- 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 fieldprefix- the prefixorder- field ordertype- field typeisList- the is listisMap- 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 outorder- the ordertype- the typelist- 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 toCodedOutputStreamobject.- 参数:
out- target output stream to writeorder- field ordertype- field typelist- target list object to be serializedpacked- 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 outorder- the ordertype- the typeo- the olist- 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 byFieldType.- 参数:
out- the outorder- the ordertype- the typeo- the olist- the listwithTag- the with tag- 抛出:
IOException- Signals that an I/O exception has occurred.
-
getRequiredCheck
get required field check java expression.- 参数:
order- field orderfield- java field- 返回:
- full java expression
-
getRetRequiredCheck
get return required field check java expression.- 参数:
express- java expressionfield- java field- 返回:
- full java expression
-
isNull
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
As list.- 参数:
value- the value- 返回:
- the list
-
capitalize
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,
nullif null String input
-
makeTag
public static int makeTag(int fieldNumber, int wireType) make protobuf tag.- 参数:
fieldNumber- field number orderwireType- wireformat type- 返回:
- tag id
-
getEnumName
Gets the enum name.- 参数:
e- the evalue- the value- 返回:
- the enum name
-
getEnumValue
Gets the enum value.- 参数:
en- the en- 返回:
- the enum value
-
getEnumValue
Gets the enumeration value.- 类型参数:
T- the generic type- 参数:
enumType- the enum typename- 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 byMessageOrBuilder.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 byMessageOrBuilder.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 byMessageOrBuilder.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.
-