Class DataCodecManager

java.lang.Object
com.iohao.net.framework.core.codec.DataCodecManager

public final class DataCodecManager extends Object
Central manager for the active DataCodec instances.

Holds two codec references: a primary codec used for user-facing requests and an internal codec used for inter-server communication. By default both point to ProtoDataCodec. Calling setDataCodec(DataCodec) updates the primary codec and, if the internal codec has not been explicitly overridden, keeps them in sync.

Since:
25.1
Author:
渔民小镇
date:
2025-09-28
  • Method Details

    • setDataCodec

      public static void setDataCodec(DataCodec dataCodec)
      Set the primary data codec. If the internal codec has not been explicitly changed, it is updated to match the new primary codec.
      Parameters:
      dataCodec - the new primary codec
    • encode

      public static byte[] encode(Object data)
      Encode an object using the primary codec.
      Parameters:
      data - the object to encode
      Returns:
      the encoded byte array
    • decode

      public static <T> T decode(byte[] data, Class<T> paramClazz)
      Decode a byte array into the specified type using the primary codec.
      Type Parameters:
      T - the target type
      Parameters:
      data - the byte array to decode
      paramClazz - the target class
      Returns:
      the decoded object
    • getDataCodec

      public static DataCodec getDataCodec(CommunicationType communicationType)
      Return the appropriate codec for the given communication type. User requests use the primary codec; internal communication uses the internal codec.
      Parameters:
      communicationType - the communication type
      Returns:
      the corresponding DataCodec
    • getDataCodec

      public static DataCodec getDataCodec()
    • getInternalDataCodec

      public static DataCodec getInternalDataCodec()
    • setInternalDataCodec

      public static void setInternalDataCodec(DataCodec internalDataCodec)