Class TradeFlyweight

java.lang.Object
com.quantfinlib.sbe.TradeFlyweight

public final class TradeFlyweight extends Object
SBE-style flyweight codec for a market-data trade message: fixed field offsets over a ByteBuffer, so encode/decode is a handful of absolute primitive reads/writes — zero allocation, zero parsing, zero copying. This is the wire format real HFT feeds use (ITCH/SBE family), as opposed to the text protocols (JSON/FIX tag-value) of the retail edges.

Wire layout (little-endian, 32 bytes):

 offset  0  int32   messageType   = 1
 offset  4  int32   symbolId          (dense id shared by both ends)
 offset  8  double  price
 offset 16  double  size
 offset 24  int64   timestampNanos    (exchange event time)
 

Usage: wrap(buffer, offset) then read/write fields. The flyweight holds no state besides the wrap position — reuse one instance for millions of messages.

  • Field Details

    • MESSAGE_TYPE

      public static final int MESSAGE_TYPE
      Message type discriminator at offset 0.
      See Also:
    • BLOCK_LENGTH

      public static final int BLOCK_LENGTH
      Total encoded size in bytes.
      See Also:
  • Constructor Details

    • TradeFlyweight

      public TradeFlyweight()
  • Method Details

    • wrap

      public TradeFlyweight wrap(ByteBuffer buffer, int offset)
      Positions this flyweight over buffer at offset.
    • encode

      public TradeFlyweight encode(int symbolId, double price, double size, long timestampNanos)
      Encodes a full trade message at the wrap position (writes the type header).
    • symbolId

      public int symbolId()
    • price

      public double price()
    • size

      public double size()
    • timestampNanos

      public long timestampNanos()
    • typeAt

      public static int typeAt(ByteBuffer buffer, int offset)
      Reads the message-type discriminator at offset without wrapping.