Class TradeFlyweight
java.lang.Object
com.quantfinlib.sbe.TradeFlyweight
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final intTotal encoded size in bytes.static final intMessage type discriminator at offset 0. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionencode(int symbolId, double price, double size, long timestampNanos) Encodes a full trade message at the wrap position (writes the type header).doubleprice()doublesize()intsymbolId()longstatic inttypeAt(ByteBuffer buffer, int offset) Reads the message-type discriminator atoffsetwithout wrapping.wrap(ByteBuffer buffer, int offset) Positions this flyweight overbufferatoffset.
-
Field Details
-
MESSAGE_TYPE
public static final int MESSAGE_TYPEMessage type discriminator at offset 0.- See Also:
-
BLOCK_LENGTH
public static final int BLOCK_LENGTHTotal encoded size in bytes.- See Also:
-
-
Constructor Details
-
TradeFlyweight
public TradeFlyweight()
-
-
Method Details
-
wrap
Positions this flyweight overbufferatoffset. -
encode
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
Reads the message-type discriminator atoffsetwithout wrapping.
-