Message Fields
An SBE message provides access to message fields via its methods.
To get/set a field value, use the corresponding method of the IFieldSet interface.
Setters
The naming convention for setters is SetTypeName(..)
.
Setting Optional Fields
To set the value of the optional field to null
, use the SetToNull(int) method.
Getters
The naming convention for getters is GetTypeName(..)
.
Getting Optional Fields
To check if an optional field is present in the message, use the Contains(int) method.
Field types
There is a need to use the correct field type in getters/setters. But if field type can be implicitly cast to getter type, it is allowed to use such type.
For example, it is allowed to call GetInteger(int) for byte
and short
fields.
For setters, it is an opposite rule: if setter type can be implicitly cast to the field type, it is allowed to use such type.
For example, it is allowed to call SetByte(int, byte) for short
and integer
fields.
Enumerations Fields
There is an ability to work with user-defined enumerations using GetEnum<T>(int) and SetEnum<T>(int, T) methods.
Variable-length Fields
Variable-length fields is esposed by IVariableLengthField interface. Use GetVariableLengthField(int) method to obtain variable-length field.
Raw field Value
There is an ability to get/set raw field bytes using GetBytes(int) and SetBytes(int, ReadOnlySpan<byte>) methods.
Example
const int NewOrderSingleTemplateId = 514;
IEncoder encoder = session.CreateEncoder();
IMessage message = encoder.Wrap(NewOrderSingleTemplateId);
const int SideTag = 54;
const int SenderIDTag = 5392;
const int ClOrdIDTag = 11;
const int TimeInForceTag = 59;
const int OrderQtyTag = 38;
const int PriceTag = 44;
const int DisplayQtyTag = 1138;
// Set fields:
message.SetEnum(SideTag, Side.Buy);
message.SetString(SenderIDTag, "GFP");
message.SetString(ClOrdIDTag, "OrderId");
message.SetEnum(TimeInForceTag, TimeInForce.Day);
message.SetUnsignedInteger(OrderQtyTag, 1);
message.SetDecimal(PriceTag, 100);
// Set an optional field to the `null` value:
message.SetToNull(DisplayQtyTag);
// Get required fields:
Side side = message.GetEnum<Side>(SideTag);
string senderId = message.GetString(SenderIDTag);
string clOrdId = message.GetString(ClOrdIDTag);
TimeInForce timeInForce = message.GetEnum<TimeInForce>(TimeInForceTag);
uint orderQty = message.GetUnsignedInteger(OrderQtyTag);
// Get an optional field:
decimal price;
if (message.Contains(PriceTag))
{
price = message.GetDecimal(PriceTag);
}