Class ProtoDataCodec

java.lang.Object
com.iohao.net.framework.core.codec.ProtoDataCodec
All Implemented Interfaces:
DataCodec

public final class ProtoDataCodec extends Object implements DataCodec
Protobuf-based implementation of DataCodec.

Delegates serialization and deserialization to ProtoKit (jprotobuf). Pre-encodes and caches the byte representations of true and false BoolValue instances to avoid repeated encoding of common boolean values.

Author:
渔民小镇
date:
2022-05-18
  • Constructor Details

    • ProtoDataCodec

      public ProtoDataCodec()
  • Method Details

    • encode

      public byte[] encode(Object data)
      Description copied from interface: DataCodec
      Encode an object to a byte array.
      Specified by:
      encode in interface DataCodec
      Parameters:
      data - the object to encode
      Returns:
      the encoded byte array
    • decode

      public <T> T decode(byte[] data, Class<T> dataClass)
      Description copied from interface: DataCodec
      Decode a byte array into an object of the specified type.
      Specified by:
      decode in interface DataCodec
      Type Parameters:
      T - the target type
      Parameters:
      data - the byte array to decode
      dataClass - the target class
      Returns:
      the decoded object
    • encode

      public byte[] encode(boolean data)
      Encode a boolean value using cached byte arrays for efficiency.
      Specified by:
      encode in interface DataCodec
      Parameters:
      data - the boolean value
      Returns:
      the pre-cached encoded byte array
    • codecName

      public String codecName()
      Description copied from interface: DataCodec
      Return the human-readable name of this codec.
      Specified by:
      codecName in interface DataCodec
      Returns:
      the codec name