public class ProtocolSerialization<P extends Protocol<?>> extends Object implements ObjectSerialization<P>
Protocol and get Header from source byte[].
[0,1] - Magic number [2,9] - Long id [10] - ObjectSerialization type [11] - Protocol type [12-15] - Data length
Protocol| 限定符和类型 | 字段和说明 |
|---|---|
static short |
MAGIC_NUMBER
Magic number (22202).
|
static int |
PROTOCOL_DATE_INFINITE
Protocol data size infinite.
|
static int |
PROTOCOL_HEADER_SIZE
Protocol header size.
|
static byte |
PROTOCOL_TYPE_UNINITIALIZED
Protocol type uninitialized.
|
| 构造器和说明 |
|---|
ProtocolSerialization(ObjectSerialization objectSerialization,
Map<Byte,ObjectSerialization> supportedObjectSerializations)
Constructor.
|
| 限定符和类型 | 方法和说明 |
|---|---|
<T> T |
deserialize(byte[] bytes,
Class<T> clz)
Deserialize an object from the given binary data.
|
<T> T |
deserialize(InputStream input,
Class<T> clz)
Deserialize an object from the given input stream.
|
P |
deserializeByteBuffer(ByteBuffer buffer,
Class<P> clz)
Deserialize
ByteBuffer object to Protocol object. |
ObjectSerialization |
getObjectSerialization(ByteBuffer buffer)
根据原
ByteBuffer获取ObjectSerialization。 |
byte |
getType()
Serialization type.
|
P |
recover(P protocol,
byte[] bytes)
根据
byte[]恢复Protocol对象信息。 |
P |
recover(P protocol,
ByteBuffer buffer)
根据
ByteBuffer恢复Protocol对象信息。 |
protected P |
recover(P protocol,
net.jrouter.protocol.serialize.ProtocolSerialization.Header header)
根据
Header恢复Protocol对象信息。 |
void |
serialize(OutputStream output,
P protocol)
Serialize the given object to stream data.
|
byte[] |
serialize(P protocol)
Serialize the given object to binary data.
|
ByteBuffer |
serializeByteBuffer(P protocol)
Serialize
Protocol object to ByteBuffer object. |
public static final int PROTOCOL_HEADER_SIZE
public static final short MAGIC_NUMBER
public static final byte PROTOCOL_TYPE_UNINITIALIZED
public static final int PROTOCOL_DATE_INFINITE
public ProtocolSerialization(ObjectSerialization objectSerialization, Map<Byte,ObjectSerialization> supportedObjectSerializations)
objectSerialization - Object Serialization.supportedObjectSerializations - Supported Object Serializations.public ObjectSerialization getObjectSerialization(ByteBuffer buffer)
ByteBuffer获取ObjectSerialization。buffer - ByteBuffer对象。public P recover(P protocol, byte[] bytes)
byte[]恢复Protocol对象信息。protocol - Protocol对象。bytes - byte[]对象。Protocol对象。public P recover(P protocol, ByteBuffer buffer)
ByteBuffer恢复Protocol对象信息。protocol - Protocol对象。buffer - ByteBuffer对象。Protocol对象。protected P recover(P protocol, net.jrouter.protocol.serialize.ProtocolSerialization.Header header)
Header恢复Protocol对象信息。protocol - Protocol对象。header - Header对象。Protocol对象。public byte[] serialize(P protocol)
ObjectSerializationserialize 在接口中 ObjectSerialization<P extends Protocol<?>>protocol - object to serializepublic void serialize(OutputStream output, P protocol)
ObjectSerializationserialize 在接口中 ObjectSerialization<P extends Protocol<?>>output - output stream to writeprotocol - object to serializepublic ByteBuffer serializeByteBuffer(P protocol)
Protocol object to ByteBuffer object.protocol - Protocol object.ByteBuffer.public P deserializeByteBuffer(ByteBuffer buffer, Class<P> clz)
ByteBuffer object to Protocol object.buffer - ByteBuffer object.clz - Protocol class type.Protocol object.public <T> T deserialize(byte[] bytes,
Class<T> clz)
ObjectSerializationdeserialize 在接口中 ObjectSerialization<P extends Protocol<?>>T - Object class typebytes - object binary representationclz - specified class typepublic <T> T deserialize(InputStream input, Class<T> clz)
ObjectSerializationdeserialize 在接口中 ObjectSerialization<P extends Protocol<?>>T - Object class typeinput - object input stream representationclz - specified class typepublic byte getType()
ObjectSerializationgetType 在接口中 ObjectSerialization<P extends Protocol<?>>Copyright © 2018–2020. All rights reserved.