Interface Marshaller<T>
- Type Parameters:
T- the message type - 消息类型
public interface Marshaller<T>
Marshaller - Message Serialization Interface
编组器 - 消息序列化接口
Defines how messages are serialized to and deserialized from byte arrays.
定义消息如何序列化为字节数组以及从字节数组反序列化。
Features | 主要功能:
- Bidirectional serialization: marshal (object to bytes) and unmarshal (bytes to object) - 双向序列化
- Generic type parameter for type safety - 泛型参数保证类型安全
- Simple SPI for custom serialization strategies - 自定义序列化策略的简单SPI
Usage Examples | 使用示例:
Marshaller<MyMessage> marshaller = new JsonMarshaller<>(MyMessage.class);
byte[] data = marshaller.marshal(message);
MyMessage restored = marshaller.unmarshal(data);
Security | 安全性:
- Thread-safe: Depends on implementation - 线程安全: 取决于实现
- Null-safe: Depends on implementation - 空值安全: 取决于实现
- Since:
- JDK 25, opencode-base-io V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
-
Method Details
-
marshal
Serializes a message to bytes. 将消息序列化为字节。- Parameters:
value- the message to serialize - 要序列化的消息- Returns:
- the serialized bytes - 序列化的字节
-
unmarshal
Deserializes a message from bytes. 从字节反序列化消息。- Parameters:
data- the bytes to deserialize - 要反序列化的字节- Returns:
- the deserialized message - 反序列化的消息
-