INPUT
- the type of the messages which will be encoded in ByteBuffers and
decoded from ByteBuffers.public abstract class ByteBufferEncoder<INPUT> extends Object implements StatelessProtocolEncoder<INPUT,ByteBuffer>
Transcoder is stateless class providing encoding and decoding facilities. Additionally this abstract requires two methods which allows to determine the size of a given message and to write it directly to a previously allocated ByteBuffer.
Constructor and Description |
---|
ByteBufferEncoder() |
Modifier and Type | Method and Description |
---|---|
Void |
createEncoderState()
Being stateless, this method is left empty
|
ByteBuffer |
encode(INPUT message)
Encodes a message to a
ByteBuffer |
ByteBuffer |
encode(INPUT message,
Void context)
Encodes a message to a
ByteBuffer
The actual encoding needs to be implemented in the abstract method
encode(Object)
|
abstract int |
getEncodedSize(INPUT message)
Computes the size of the serialized form of a message in bytes.
|
abstract void |
writeTo(INPUT message,
ByteBuffer buffer)
Writes a message on a
ByteBuffer . |
public final Void createEncoderState()
createEncoderState
in interface ProtocolEncoder<INPUT,ByteBuffer,Void>
ProtocolDecoder.createDecoderState()
public ByteBuffer encode(INPUT message)
ByteBuffer
message
- a message to be encodedByteBuffer
representation of the
messagepublic final ByteBuffer encode(INPUT message, Void context)
ByteBuffer
The actual encoding needs to be implemented in the abstract method
encode(Object)
encode
in interface ProtocolEncoder<INPUT,ByteBuffer,Void>
message
- the message to encodecontext
- the encoding context (will be stored in the session for the next decode call)public abstract int getEncodedSize(INPUT message)
message
- a message to be encodedpublic abstract void writeTo(INPUT message, ByteBuffer buffer)
ByteBuffer
.
n.b. The buffer is expected to have at least a sufficient capacity to handle the serialized form of the message.
message
- a message to be encodedbuffer
- a target ByteBuffer
Copyright © 2009–2013 Apache MINA Project. All rights reserved.