org.apache.mina.codec.delimited

## Class ByteBufferEncoder<INPUT>

- java.lang.Object
- - org.apache.mina.codec.delimited.ByteBufferEncoder<INPUT>

Type Parameters:
  `INPUT` - the type of the messages which will be encoded in ByteBuffers and decoded from ByteBuffers.

All Implemented Interfaces:
  ProtocolEncoder<INPUT,ByteBuffer,Void>, StatelessProtocolEncoder<INPUT,ByteBuffer>

Direct Known Subclasses:
  JavaNativeMessageEncoder, ProtobufMessageEncoder, ThriftMessageEncoder

    public abstract class ByteBufferEncoder<INPUT>
    extends Object
    implements StatelessProtocolEncoder<INPUT,ByteBuffer>

Abstract class providing both encoding and decoding methods between a given type and ByteBuffers.

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.

Author:
  Apache MINA Project

### Constructor Summary

Constructors
Constructor and Description
`ByteBufferEncoder()`

### Method Summary

Methods
`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`.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### ByteBufferEncoder

    public ByteBufferEncoder()

### Method Detail

#### createEncoderState

    public final Void createEncoderState()

Being stateless, this method is left empty

Specified by:
  `createEncoderState` in interface `ProtocolEncoder<INPUT,ByteBuffer,Void>`
Returns:
  the newly created context
See Also:
  `ProtocolDecoder.createDecoderState()`

#### encode

    public ByteBuffer encode(INPUT message)

Encodes a message to a `ByteBuffer`

Parameters:
  `message` - a message to be encoded
Returns:
  the buffer containing `ByteBuffer` representation of the message

#### encode

    public final 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)`

Specified by:
  `encode` in interface `ProtocolEncoder<INPUT,ByteBuffer,Void>`
Parameters:
  `message` - the message to encode
  `context` - the encoding context (will be stored in the session for the next decode call)

#### getEncodedSize

    public abstract int getEncodedSize(INPUT message)

Computes the size of the serialized form of a message in bytes.

Parameters:
  `message` - a message to be encoded
Returns:
  the size of the serialized form of the message

#### writeTo

    public abstract void writeTo(INPUT message,
               ByteBuffer buffer)

Writes a message on a `ByteBuffer`.

n.b. The buffer is expected to have at least a sufficient capacity to handle the serialized form of the message.

Parameters:
  `message` - a message to be encoded
  `buffer` - a target `ByteBuffer`