Class EnvelopeCodec

java.lang.Object
ru.pathcreator.pyc.rpc.core.envelope.EnvelopeCodec

public final class EnvelopeCodec extends Object
Кодек для прямого чтения и записи envelope без создания дополнительных объектов.

Все методы этого класса статические и работают напрямую с DirectBuffer или MutableDirectBuffer. Поля envelope записываются и читаются в формате little-endian. Использование явного ByteOrder делает код независимым от порядка байтов платформы.

Codec for direct zero-allocation reading and writing of envelope headers. All methods are static and operate directly on DirectBuffer or MutableDirectBuffer. Envelope fields are encoded and decoded using little-endian byte order.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static long
    correlationId(org.agrona.DirectBuffer b, int offset)
    Читает транспортный идентификатор корреляции из envelope.
    static void
    encode(org.agrona.MutableDirectBuffer buffer, int offset, int messageTypeId, long correlationId, int flags, int payloadLength)
    Записывает envelope в указанный буфер, начиная с заданного смещения.
    static int
    flags(org.agrona.DirectBuffer b, int offset)
    Читает битовые флаги из envelope.
    static boolean
    isError(int flags)
    Checks whether the error flag is set.
    static boolean
    isHeartbeat(int flags)
    Проверяет, установлен ли флаг heartbeat-кадра.
    static boolean
    isRequest(int flags)
    Проверяет, установлен ли флаг RPC-запроса.
    static short
    magic(org.agrona.DirectBuffer b, int offset)
    Читает сигнатуру протокола из envelope.
    static int
    messageTypeId(org.agrona.DirectBuffer b, int offset)
    Читает идентификатор типа сообщения из envelope.
    static int
    payloadLength(org.agrona.DirectBuffer b, int offset)
    Читает длину полезной нагрузки из envelope.
    static short
    version(org.agrona.DirectBuffer b, int offset)
    Читает версию формата из envelope.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • encode

      public static void encode(org.agrona.MutableDirectBuffer buffer, int offset, int messageTypeId, long correlationId, int flags, int payloadLength)
      Записывает envelope в указанный буфер, начиная с заданного смещения.

      Метод записывает ровно Envelope.LENGTH байт в область buffer[offset..offset + Envelope.LENGTH). Полезная нагрузка этим методом не записывается: он формирует только транспортный заголовок.

      Writes an envelope header into the provided buffer starting at the specified offset. The method writes exactly Envelope.LENGTH bytes and does not write the payload itself.

      Parameters:
      buffer - буфер назначения / destination buffer
      offset - смещение начала envelope в буфере / envelope start offset in the buffer
      messageTypeId - идентификатор типа сообщения для маршрутизации / message type identifier used for routing
      correlationId - транспортный идентификатор корреляции / transport-level correlation identifier
      flags - битовые флаги envelope / envelope bit flags
      payloadLength - длина полезной нагрузки после envelope, в байтах / payload length after the envelope, in bytes
    • magic

      public static short magic(org.agrona.DirectBuffer b, int offset)
      Читает сигнатуру протокола из envelope.

      Reads the protocol signature from an envelope.

      Parameters:
      b - буфер с envelope / buffer containing the envelope
      offset - смещение начала envelope в буфере / envelope start offset in the buffer
      Returns:
      значение поля Envelope.MAGIC / value of the Envelope.MAGIC field
    • version

      public static short version(org.agrona.DirectBuffer b, int offset)
      Читает версию формата из envelope.

      Reads the envelope format version.

      Parameters:
      b - буфер с envelope / buffer containing the envelope
      offset - смещение начала envelope в буфере / envelope start offset in the buffer
      Returns:
      значение поля Envelope.VERSION / value of the Envelope.VERSION field
    • messageTypeId

      public static int messageTypeId(org.agrona.DirectBuffer b, int offset)
      Читает идентификатор типа сообщения из envelope.

      Reads the message type identifier from an envelope.

      Parameters:
      b - буфер с envelope / buffer containing the envelope
      offset - смещение начала envelope в буфере / envelope start offset in the buffer
      Returns:
      идентификатор типа сообщения / message type identifier
    • correlationId

      public static long correlationId(org.agrona.DirectBuffer b, int offset)
      Читает транспортный идентификатор корреляции из envelope.

      Reads the transport-level correlation identifier from an envelope.

      Parameters:
      b - буфер с envelope / buffer containing the envelope
      offset - смещение начала envelope в буфере / envelope start offset in the buffer
      Returns:
      идентификатор корреляции / correlation identifier
    • flags

      public static int flags(org.agrona.DirectBuffer b, int offset)
      Читает битовые флаги из envelope.

      Reads the bit flags from an envelope.

      Parameters:
      b - буфер с envelope / buffer containing the envelope
      offset - смещение начала envelope в буфере / envelope start offset in the buffer
      Returns:
      значение поля флагов / flags field value
    • payloadLength

      public static int payloadLength(org.agrona.DirectBuffer b, int offset)
      Читает длину полезной нагрузки из envelope.

      Reads the payload length from an envelope.

      Parameters:
      b - буфер с envelope / buffer containing the envelope
      offset - смещение начала envelope в буфере / envelope start offset in the buffer
      Returns:
      длина полезной нагрузки после envelope, в байтах / payload length after the envelope, in bytes
    • isRequest

      public static boolean isRequest(int flags)
      Проверяет, установлен ли флаг RPC-запроса.

      Checks whether the RPC request flag is set.

      Parameters:
      flags - значение поля флагов envelope / envelope flags field value
      Returns:
      true, если envelope помечен как запрос / true if the envelope is marked as a request
    • isHeartbeat

      public static boolean isHeartbeat(int flags)
      Проверяет, установлен ли флаг heartbeat-кадра.

      Checks whether the heartbeat frame flag is set.

      Parameters:
      flags - значение поля флагов envelope / envelope flags field value
      Returns:
      true, если envelope помечен как heartbeat / true if the envelope is marked as a heartbeat frame
    • isError

      public static boolean isError(int flags)
      Checks whether the error flag is set.
      Parameters:
      flags - envelope flags
      Returns:
      true when the frame is a structured error response