Interface DataCodec
- All Known Implementing Classes:
ProtoDataCodec
public interface DataCodec
Strategy interface for encoding and decoding business data.
Provides methods to serialize objects to byte[] and deserialize byte[] back
to typed objects. Default convenience methods handle primitive wrappers (IntValue,
LongValue, BoolValue, StringValue) and list wrappers
(IntValueList, LongValueList, BoolValueList, StringValueList,
ByteValueList) transparently.
- Author:
- 渔民小镇
- date:
- 2022-05-18
-
Method Summary
Modifier and TypeMethodDescriptiondefault StringReturn the human-readable name of this codec.<T> TDecode a byte array into an object of the specified type.default byte[]encode(boolean data) Encode a boolean value by wrapping it inBoolValue.default byte[]encode(int data) Encode an int value by wrapping it inIntValue.default byte[]encode(long data) Encode a long value by wrapping it inLongValue.byte[]Encode an object to a byte array.default byte[]Encode a string value by wrapping it inStringValue.default byte[]encodeList(Collection<?> dataList) Encode a collection of objects into aByteValueListusing the default codec.default byte[]encodeList(Collection<?> dataList, DataCodec codec) Encode a collection of objects into aByteValueListusing the specified codec.default byte[]encodeListBool(List<Boolean> dataList) Encode a list of booleans by wrapping it inBoolValueList.default byte[]encodeListInt(List<Integer> dataList) Encode a list of integers by wrapping it inIntValueList.default byte[]encodeListLong(List<Long> dataList) Encode a list of longs by wrapping it inLongValueList.default byte[]encodeListString(List<String> dataList) Encode a list of strings by wrapping it inStringValueList.
-
Method Details
-
encode
Encode an object to a byte array.- Parameters:
data- the object to encode- Returns:
- the encoded byte array
-
decode
Decode a byte array into an object of the specified type.- Type Parameters:
T- the target type- Parameters:
data- the byte array to decodedataClass- the target class- Returns:
- the decoded object
-
codecName
-
encode
default byte[] encode(int data) Encode an int value by wrapping it inIntValue.- Parameters:
data- the int value- Returns:
- the encoded byte array
-
encode
default byte[] encode(boolean data) Encode a boolean value by wrapping it inBoolValue.- Parameters:
data- the boolean value- Returns:
- the encoded byte array
-
encode
default byte[] encode(long data) Encode a long value by wrapping it inLongValue.- Parameters:
data- the long value- Returns:
- the encoded byte array
-
encode
Encode a string value by wrapping it inStringValue.- Parameters:
data- the string value- Returns:
- the encoded byte array
-
encodeListInt
Encode a list of integers by wrapping it inIntValueList.- Parameters:
dataList- the list of integers- Returns:
- the encoded byte array
-
encodeListBool
Encode a list of booleans by wrapping it inBoolValueList.- Parameters:
dataList- the list of booleans- Returns:
- the encoded byte array
-
encodeListLong
Encode a list of longs by wrapping it inLongValueList.- Parameters:
dataList- the list of longs- Returns:
- the encoded byte array
-
encodeListString
Encode a list of strings by wrapping it inStringValueList.- Parameters:
dataList- the list of strings- Returns:
- the encoded byte array
-
encodeList
Encode a collection of objects into aByteValueListusing the default codec.- Parameters:
dataList- the collection of objects to encode- Returns:
- the encoded byte array
-
encodeList
Encode a collection of objects into aByteValueListusing the specified codec.- Parameters:
dataList- the collection of objects to encodecodec- the codec to use for encoding each element- Returns:
- the encoded byte array
-