io.vertx.core.eventbus

## Interface MessageCodec<S,R>

- Type Parameters:
    `S` - the type of the message being sent
    `R` - the type of the message being received.

      public interface MessageCodec<S,R>

  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[]`, `JsonObject`, `JsonArray`, `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

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `R` | `decodeFromWire(int pos, Buffer buffer)` Called by Vert.x when a message is decoded from the wire.
    `void` | `encodeToWire(Buffer buffer, S s)` Called by Vert.x when marshalling a message to the wire.
    `String` | `name()` The codec name.
    `byte` | `systemCodecID()` Used to identify system codecs.
    `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

- - ### Method Detail

    - #### encodeToWire

          void encodeToWire(Buffer buffer,
                            S s)

      Called by Vert.x when marshalling a message to the wire.
      Parameters:
        `buffer` - the message should be written into this buffer
        `s` - the message that is being sent

    - #### decodeFromWire

          R decodeFromWire(int pos,
                           Buffer buffer)

      Called by Vert.x when a message is decoded from the wire.
      Parameters:
        `pos` - the position in the buffer where the message should be read from.
        `buffer` - the buffer to read the message from
      Returns:
        the read message

    - #### transform

          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` - the sent message
      Returns:
        the transformed message

    - #### name

          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:
        the name

    - #### systemCodecID

          byte systemCodecID()

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

Copyright © 2015. All rights reserved.