Class EnvelopeCodec
Все методы этого класса статические и работают напрямую с 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 TypeMethodDescriptionstatic longcorrelationId(org.agrona.DirectBuffer b, int offset) Читает транспортный идентификатор корреляции из envelope.static voidencode(org.agrona.MutableDirectBuffer buffer, int offset, int messageTypeId, long correlationId, int flags, int payloadLength) Записывает envelope в указанный буфер, начиная с заданного смещения.static intflags(org.agrona.DirectBuffer b, int offset) Читает битовые флаги из envelope.static booleanisError(int flags) Checks whether the error flag is set.static booleanisHeartbeat(int flags) Проверяет, установлен ли флаг heartbeat-кадра.static booleanisRequest(int flags) Проверяет, установлен ли флаг RPC-запроса.static shortmagic(org.agrona.DirectBuffer b, int offset) Читает сигнатуру протокола из envelope.static intmessageTypeId(org.agrona.DirectBuffer b, int offset) Читает идентификатор типа сообщения из envelope.static intpayloadLength(org.agrona.DirectBuffer b, int offset) Читает длину полезной нагрузки из envelope.static shortversion(org.agrona.DirectBuffer b, int offset) Читает версию формата из envelope.
-
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.LENGTHbytes and does not write the payload itself.- Parameters:
buffer- буфер назначения / destination bufferoffset- смещение начала envelope в буфере / envelope start offset in the buffermessageTypeId- идентификатор типа сообщения для маршрутизации / message type identifier used for routingcorrelationId- транспортный идентификатор корреляции / transport-level correlation identifierflags- битовые флаги envelope / envelope bit flagspayloadLength- длина полезной нагрузки после 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 envelopeoffset- смещение начала envelope в буфере / envelope start offset in the buffer- Returns:
- значение поля
Envelope.MAGIC/ value of theEnvelope.MAGICfield
-
version
public static short version(org.agrona.DirectBuffer b, int offset) Читает версию формата из envelope.Reads the envelope format version.
- Parameters:
b- буфер с envelope / buffer containing the envelopeoffset- смещение начала envelope в буфере / envelope start offset in the buffer- Returns:
- значение поля
Envelope.VERSION/ value of theEnvelope.VERSIONfield
-
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 envelopeoffset- смещение начала 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 envelopeoffset- смещение начала 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 envelopeoffset- смещение начала 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 envelopeoffset- смещение начала 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 помечен как запрос /trueif 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 /trueif 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:
truewhen the frame is a structured error response
-