Class Message.Serializer

  • Enclosing class:
    Message<T>

    public static final class Message.Serializer
    extends java.lang.Object
    Each message contains a header with several fixed fields, an optional key-value params section, and then the message payload itself. Below is a visualization of the layout. The params are prefixed by the count of key-value pairs; this value is encoded as unsigned vint. An individual param has an unsvint id (more specifically, a ParamType), and a byte array value. The param value is prefixed with it's length, encoded as an unsigned vint, followed by by the value's bytes. Legacy Notes (see serialize(Message, DataOutputPlus, int) for complete details): - pre 4.0, the IP address was sent along in the header, before the verb. The IP address may be either IPv4 (4 bytes) or IPv6 (16 bytes) - pre-4.0, the verb was encoded as a 4-byte integer; in 4.0 and up it is an unsigned vint - pre-4.0, the payloadSize was encoded as a 4-byte integer; in 4.0 and up it is an unsigned vint - pre-4.0, the count of param key-value pairs was encoded as a 4-byte integer; in 4.0 and up it is an unsigned vint - pre-4.0, param names were encoded as strings; in 4.0 they are encoded as enum id vints - pre-4.0, expiry time wasn't encoded at all; in 4.0 it's an unsigned vint - pre-4.0, message id was an int; in 4.0 and up it's an unsigned vint - pre-4.0, messages included PROTOCOL MAGIC BYTES; post-4.0, we rely on frame CRCs instead - pre-4.0, messages would serialize boolean params as dummy ONE_BYTEs; post-4.0 we have a dedicated 'flags' vint
     
                1 1 1 1 1 2 2 2 2 2 3
      0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 0
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     | Message ID (vint)             |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     | Creation timestamp (int)      |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     | Expiry (vint)                 |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     | Verb (vint)                   |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     | Flags (vint)                  |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     | Param count (vint)            |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                               /
     /           Params              /
     /                               |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     | Payload size (vint)           |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                               /
     /           Payload             /
     /                               |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     
     
    • Method Detail

      • serialize

        public <T> void serialize​(Message<T> message,
                                  DataOutputPlus out,
                                  int version)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • deserialize

        public <T> Message<T> deserialize​(DataInputPlus in,
                                          Message.Header header,
                                          int version)
                                   throws java.io.IOException
        A partial variant of deserialize, taking in a previously deserialized Message.Header as an argument. Skip deserializing the Message.Header from the input stream in favour of using the provided header.
        Throws:
        java.io.IOException