Top Description Methods
io.vertx.core.eventbus

public Interface MessageCodec<S, R>

Known Direct Implementers
io.vertx.core.eventbus.impl.codecs.BooleanMessageCodec, io.vertx.core.eventbus.impl.codecs.BufferMessageCodec, io.vertx.core.eventbus.impl.codecs.ByteArrayMessageCodec, io.vertx.core.eventbus.impl.codecs.ByteMessageCodec, io.vertx.core.eventbus.impl.codecs.CharMessageCodec, io.vertx.core.eventbus.impl.codecs.ClusterSerializableCodec, io.vertx.core.eventbus.impl.codecs.DoubleMessageCodec, io.vertx.core.eventbus.impl.codecs.FloatMessageCodec, io.vertx.core.eventbus.impl.codecs.IntMessageCodec, io.vertx.core.eventbus.impl.codecs.JsonArrayMessageCodec, io.vertx.core.eventbus.impl.codecs.JsonObjectMessageCodec, io.vertx.core.eventbus.impl.codecs.LongMessageCodec, io.vertx.core.eventbus.impl.codecs.NullMessageCodec, io.vertx.core.eventbus.impl.codecs.PingMessageCodec, io.vertx.core.eventbus.impl.codecs.ReplyExceptionMessageCodec, io.vertx.core.eventbus.impl.codecs.SerializableCodec, io.vertx.core.eventbus.impl.codecs.ShortMessageCodec, io.vertx.core.eventbus.impl.codecs.StringMessageCodec
Type Parameters
<S>
the type of the message being sent
<R>
the type of the message being received.
Imports
io.vertx.core.buffer.Buffer

A message codec allows a custom message type to be marshalled across the event bus.

Usually the event bus only allows a certain set of message types to be sent across the event bus, including primitive types, boxed primitive types, byte[], io.vertx.core.json.JsonObject, io.vertx.core.json.JsonArray, io.vertx.core.buffer.Buffer.

By specifying a message codec you can pass any other type across the event bus, e.g. POJOs.

With a message codec the type sent does not have to be the same as the type received, e.g. you could send a Buffer and have it be received as a JsonObject.

Instances of this class must be thread-safe as they may be used concurrently by different threads.

Author
Tim Fox

Method Summary

Modifier and TypeMethod and Description
public R

Returns:

the read message
decodeFromWire
(int
the position in the buffer where the message should be read from.
pos
,
Buffer
the buffer to read the message from
buffer
)
References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Called by Vert.x when a message is decoded from the wire.

public void
encodeToWire(Buffer
the message should be written into this buffer
buffer
,
S
the message that is being sent
s
)
References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Called by Vert.x when marshalling a message to the wire.

public String

Returns:

the name
name
()

The codec name.

public byte

Returns:

-1 for a user codec.
systemCodecID
()

Used to identify system codecs.

public R

Returns:

the transformed message
transform
(S
the sent message
s
)

If a message is sent locally across the event bus, this method is called to transform the message from the sent type S to the received type R

Method Detail

decodeFromWireback to summary
public R decodeFromWire(int pos, Buffer buffer)

References Deprecated

Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Called by Vert.x when a message is decoded from the wire.

Parameters
pos:int

the position in the buffer where the message should be read from.

buffer:Buffer

the buffer to read the message from

Returns:R

the read message

encodeToWireback to summary
public void encodeToWire(Buffer buffer, S s)

References Deprecated

Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Called by Vert.x when marshalling a message to the wire.

Parameters
buffer:Buffer

the message should be written into this buffer

s:S

the message that is being sent

nameback to summary
public String name()

The codec name. Each codec must have a unique name. This is used to identify a codec when sending a message and for unregistering codecs.

Returns:String

the name

systemCodecIDback to summary
public byte systemCodecID()

Used to identify system codecs. Should always return -1 for a user codec.

Returns:byte

-1 for a user codec.

transformback to summary
public R transform(S s)

If a message is sent locally across the event bus, this method is called to transform the message from the sent type S to the received type R

Parameters
s:S

the sent message

Returns:R

the transformed message