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 <xref:OnixS.SimpleBinaryEncoding.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 <xref:OnixS.SimpleBinaryEncoding.IFieldSet.SetToNull(System.Int32)> 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 <xref:OnixS.SimpleBinaryEncoding.IFieldSet.Contains(System.Int32)> 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 <xref:OnixS.SimpleBinaryEncoding.IFieldSet.GetInteger(System.Int32)> 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 <xref:OnixS.SimpleBinaryEncoding.IFieldSet.SetByte(System.Int32,System.Byte)> for short
and integer
fields.
Enumerations Fields
There is an ability to work with user-defined enumerations using <xref:OnixS.SimpleBinaryEncoding.IFieldSet.GetEnum``1(System.Int32)> and <xref:OnixS.SimpleBinaryEncoding.IFieldSet.SetEnum``1(System.Int32,``0)> methods.
Variable-length Fields
Variable-length fields is esposed by <xref:OnixS.SimpleBinaryEncoding.IVariableLengthField> interface. Use <xref:OnixS.SimpleBinaryEncoding.IFieldSet.GetVariableLengthField(System.Int32)> method to obtain variable-length field.
Raw field Value
There is an ability to get/set raw field bytes using <xref:OnixS.SimpleBinaryEncoding.IFieldSet.GetBytes(System.Int32)> and <xref:OnixS.SimpleBinaryEncoding.IFieldSet.SetBytes(System.Int32,System.ReadOnlySpan{System.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);
}