Class DataCodecManager
java.lang.Object
com.iohao.net.framework.core.codec.DataCodecManager
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 Summary
Modifier and TypeMethodDescriptionstatic <T> TDecode a byte array into the specified type using the primary codec.static byte[]Encode an object using the primary codec.static DataCodecstatic DataCodecgetDataCodec(CommunicationType communicationType) Return the appropriate codec for the given communication type.static DataCodecstatic voidsetDataCodec(DataCodec dataCodec) Set the primary data codec.static voidsetInternalDataCodec(DataCodec internalDataCodec)
-
Method Details
-
setDataCodec
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
Encode an object using the primary codec.- Parameters:
data- the object to encode- Returns:
- the encoded byte array
-
decode
Decode a byte array into the specified type using the primary codec.- Type Parameters:
T- the target type- Parameters:
data- the byte array to decodeparamClazz- the target class- Returns:
- the decoded object
-
getDataCodec
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
-
getInternalDataCodec
-
setInternalDataCodec
-