-
Notifications
You must be signed in to change notification settings - Fork 12
Data Type Annotations
English | 中文
FastProto supports multiple data types, in addition to Java primitive data types and their wrapper classes, FastProto
also supports Timestamp, String and byte array, all above type annotations can be replaced by @AutoType
. Taking into
account cross-language data sharing, unsigned types, int8, int16 are also introduced.
Annotation | Java | C/C++ | Size | AutoType |
---|---|---|---|---|
@BooleanType |
Boolean / boolean | bool | 1 bit | √ |
@CharacterType |
Character / char | -- | 2 bytes | √ |
@ByteType |
Byte / byte | char | 1 byte | √ |
@ShortType |
Short / short | short | 2 bytes | √ |
@IntegerType |
Integer / int | int | 4 bytes | √ |
@LongType |
Long / long | long long | 8 bytes | √ |
@FloatType |
Float / float | float | 4 bytes | √ |
@DoubleType |
Double / double | double | 8 bytes | √ |
@Integer8Type |
Integer / int | char | 1 byte | × |
@Integer16Type |
Integer / int | short | 2 bytes | × |
@UInteger8Type |
Integer / int | unsigned char | 1 byte | × |
@UInteger16Type |
Integer / int | unsigned short | 2 bytes | × |
@UInteger32Type |
Long / long | unsigned long | 4 bytes | × |
@UInteger64Type |
BigInteger | unsigned long long | 8 bytes | √ |
@BinaryType |
byte[] | char[] | variable length | √ |
@StringType |
java.lang.String | -- | variable length | √ |
@TimestampType |
java.sql.Timestamp | -- | 4 / 8 bytes | √ |
@Date |
java.util.Date | -- | 4 / 8 bytes | √ |
@ArrayType |
array of primitive data types | array of primitive data types | variable length | √ |
@ListType |
list of primitive data types | -- | variable length | √ |
@EnumType |
enum | enum | 1 / 2 bytes | √ |
Boolean type annotation,can be used to annotate Boolean and boolean field directly,or annotate any data type field by specifying encoding formula and decoding formula.
Field | Data Type | Description |
---|---|---|
value | int | byte offset |
bitOffset | int | bit offset |
afterDecode | Class<? extend Function>[] | decoding formula |
beforeEncode | Class<? extend Function>[] | encoding formula |
Character type annotation,can be used to annotate Character and char field directly,or annotate any data type field by specifying encoding formula and decoding formula.
Field | Data Type | Description |
---|---|---|
value | int | byte offset |
afterDecode | Class<? extend Function>[] | decoding formula |
beforeEncode | Class<? extend Function>[] | encoding formula |
Byte type annotation,can be used to annotate Byte and byte field directly,or annotate any data type field by specifying encoding formula and decoding formula.
Field | Data Type | Description |
---|---|---|
value | int | byte offset |
afterDecode | Class<? extend Function>[] | decoding formula |
beforeEncode | Class<? extend Function>[] | encoding formula |
Short type annotation,can be used to annotate Short and short field directly,or annotate any data type field by specifying encoding formula and decoding formula.
Field | Data Type | Description |
---|---|---|
value | int | byte offset |
afterDecode | Class<? extend Function>[] | decoding formula |
beforeEncode | Class<? extend Function>[] | encoding formula |
Integer type annotation,can be used to annotate Integer and int field directly,or annotate any data type field by specifying encoding formula and decoding formula.
Field | Data Type | Description |
---|---|---|
value | int | byte offset |
afterDecode | Class<? extend Function>[] | decoding formula |
beforeEncode | Class<? extend Function>[] | encoding formula |
Long type annotation,can be used to annotate Long and long field directly,or annotate any data type field by specifying encoding formula and decoding formula.
Field | Data Type | Description |
---|---|---|
value | int | byte offset |
afterDecode | Class<? extend Function>[] | decoding formula |
beforeEncode | Class<? extend Function>[] | encoding formula |
Float type annotation,can be used to annotate Float and float field directly,or annotate any data type field by specifying encoding formula and decoding formula.
Field | Data Type | Description |
---|---|---|
value | int | byte offset |
afterDecode | Class<? extend Function>[] | decoding formula |
beforeEncode | Class<? extend Function>[] | encoding formula |
Double type annotation,can be used to annotate Double and double field directly,or annotate any data type field by specifying encoding formula and decoding formula.
Field | Data Type | Description |
---|---|---|
value | int | byte offset |
afterDecode | Class<? extend Function>[] | decoding formula |
beforeEncode | Class<? extend Function>[] | encoding formula |
Singed 8-bit Integer type annotation,can be used to annotate Integer and int field directly,or annotate any data type field by specifying encoding formula and decoding formula.
Field | Data Type | Description |
---|---|---|
value | int | byte offset |
afterDecode | Class<? extend Function>[] | decoding formula |
beforeEncode | Class<? extend Function>[] | encoding formula |
Singed 16-bit Integer type annotation,can be used to annotate Integer and int field directly,or annotate any data type field by specifying encoding formula and decoding formula.
Field | Data Type | Description |
---|---|---|
value | int | byte offset |
afterDecode | Class<? extend Function>[] | decoding formula |
beforeEncode | Class<? extend Function>[] | encoding formula |
Unsigned 8-bit Integer type annotation,can be used to annotate Integer and int field directly,or annotate any data type field by specifying encoding formula and decoding formula.
Field | Data Type | Description |
---|---|---|
value | int | byte offset |
afterDecode | Class<? extend Function>[] | decoding formula |
beforeEncode | Class<? extend Function>[] | encoding formula |
Unsigned 8-bit Integer type annotation,can be used to annotate Integer and int field directly,or annotate any data type field by specifying encoding formula and decoding formula.
Field | Data Type | Description |
---|---|---|
value | int | byte offset |
afterDecode | Class<? extend Function>[] | decoding formula |
beforeEncode | Class<? extend Function>[] | encoding formula |
Unsigned 32-bit Integer type annotation,can be used to annotate Long and long field directly,or annotate any data type field by specifying encoding formula and decoding formula.
Field | Data Type | Description |
---|---|---|
value | int | byte offset |
afterDecode | Class<? extend Function>[] | decoding formula |
beforeEncode | Class<? extend Function>[] | encoding formula |
Unsigned 64-bit Integer type annotation,can be used to annotate BigInteger type field directly,or annotate any data type field by specifying encoding formula and decoding formula.
Field | Data Type | Description |
---|---|---|
value | int | byte offset |
afterDecode | Class<? extend Function>[] | decoding formula |
beforeEncode | Class<? extend Function>[] | encoding formula |
Binary type annotation,can be used to annotate byte[] field directly,or annotate any data type field by specifying encoding formula and decoding formula.
Field | Data Type | Description |
---|---|---|
value | int | byte offset |
length | int | length |
afterDecode | Class<? extend Function> | decoding formula |
beforeEncode | Class<? extend Function> | encoding formula |
String type annotation,can be used to annotate String field directly,or annotate any data type field by specifying encoding formula and decoding formula.
Field | Data Type | Description |
---|---|---|
value | int | byte offset |
length | int | length |
charsetName | String | character set |
afterDecode | Class<? extend Function> | decoding formula |
beforeEncode | Class<? extend Function> | encoding formula |
Timestamp type annotation,can be used to annotate java.sql.Timestamp field directly,or annotate any data type field by specifying encoding formula and decoding formula.
Field | Data Type | Description |
---|---|---|
value | int | byte offset |
protocolType | ProtocolType | protocol type |
unit | TimeUnit | time unit |
afterDecode | Class<? extend Function> | decoding formula |
beforeEncode | Class<? extend Function> | encoding formula |
Date type annotation,can be used to annotate java.util.Date field directly,or annotate any data type field by specifying encoding formula and decoding formula.
Field | Data Type | Description |
---|---|---|
value | int | byte offset |
protocolType | ProtocolType | protocol type |
unit | TimeUnit | time unit |
afterDecode | Class<? extend Function> | decoding formula |
beforeEncode | Class<? extend Function> | encoding formula |
Array type annotation,can be used to annotate any array of Java primitive type field directly,or annotate any data type field by specifying encoding formula and decoding formula.
Field | Data Type | Description |
---|---|---|
value | int | byte offset |
protocolType | ProtocolType | protocol type |
unit | TimeUnit | time unit |
afterDecode | Class<? extend Function> | decoding formula |
beforeEncode | Class<? extend Function> | encoding formula |
List type annotation,can be used to annotate any list of Java primitive type field directly,or annotate any data type field by specifying encoding formula and decoding formula.
Field | Data Type | Description |
---|---|---|
value | int | byte offset |
protocolType | ProtocolType | protocol type |
length | int | length |
afterDecode | Class<? extend Function> | decoding formula |
beforeEncode | Class<? extend Function> | encoding formula |
Enum type annotation,can be used to annotate enum field directly,or annotate any data type field by specifying encoding formula and decoding formula.
Field | Data Type | Description |
---|---|---|
value | int | byte offset |
protocolType | ProtocolType | protocol type |
afterDecode | Class<? extend Function> | decoding formula |
beforeEncode | Class<? extend Function> | encoding formula |
When the data type of the protocol is Java's native data type, developers can directly use the AutoType annotation to annotate, and FastProto can infer the protocol type based on the field type.
In order to resolve indefinite length data, FastProto supports reverse addressing:
- If the byte offset is equal to -1, then address to the end of the message. Similarly, if the byte offset is equal to -2, then the second-to-last byte of the data is addressed
- The length of StringType and BianryType also supports reverse addressing. If the length is equal to -1, then the address is to the end of the message. Similarly, if the length is equal to -2, then the second-to-last byte of the data is addressed