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 Details

    • encode

      byte[] encode(Object data)
      Encode an object to a byte array.
      Parameters:
      data - the object to encode
      Returns:
      the encoded byte array
    • decode

      <T> T decode(byte[] data, Class<T> dataClass)
      Decode a byte array into an object of the specified type.
      Type Parameters:
      T - the target type
      Parameters:
      data - the byte array to decode
      dataClass - the target class
      Returns:
      the decoded object
    • codecName

      default String codecName()
      Return the human-readable name of this codec.
      Returns:
      the codec name
    • encode

      default byte[] encode(int data)
      Encode an int value by wrapping it in IntValue.
      Parameters:
      data - the int value
      Returns:
      the encoded byte array
    • encode

      default byte[] encode(boolean data)
      Encode a boolean value by wrapping it in BoolValue.
      Parameters:
      data - the boolean value
      Returns:
      the encoded byte array
    • encode

      default byte[] encode(long data)
      Encode a long value by wrapping it in LongValue.
      Parameters:
      data - the long value
      Returns:
      the encoded byte array
    • encode

      default byte[] encode(String data)
      Encode a string value by wrapping it in StringValue.
      Parameters:
      data - the string value
      Returns:
      the encoded byte array
    • encodeListInt

      default byte[] encodeListInt(List<Integer> dataList)
      Encode a list of integers by wrapping it in IntValueList.
      Parameters:
      dataList - the list of integers
      Returns:
      the encoded byte array
    • encodeListBool

      default byte[] encodeListBool(List<Boolean> dataList)
      Encode a list of booleans by wrapping it in BoolValueList.
      Parameters:
      dataList - the list of booleans
      Returns:
      the encoded byte array
    • encodeListLong

      default byte[] encodeListLong(List<Long> dataList)
      Encode a list of longs by wrapping it in LongValueList.
      Parameters:
      dataList - the list of longs
      Returns:
      the encoded byte array
    • encodeListString

      default byte[] encodeListString(List<String> dataList)
      Encode a list of strings by wrapping it in StringValueList.
      Parameters:
      dataList - the list of strings
      Returns:
      the encoded byte array
    • encodeList

      default byte[] encodeList(Collection<?> dataList)
      Encode a collection of objects into a ByteValueList using the default codec.
      Parameters:
      dataList - the collection of objects to encode
      Returns:
      the encoded byte array
    • encodeList

      default byte[] encodeList(Collection<?> dataList, DataCodec codec)
      Encode a collection of objects into a ByteValueList using the specified codec.
      Parameters:
      dataList - the collection of objects to encode
      codec - the codec to use for encoding each element
      Returns:
      the encoded byte array