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 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 OnixS.SimpleBinaryEncoding.IFieldSet.SetToNull(System.Int32)
method.
Getters
The naming convention for getters is GetTypeName(..)
.
Getting Optional Fields
To read optional message fields, use the corresponding TryGet<FIELD-TYPE>
method.
These methods return nullable values. If the message field is absent, the null
value is returned.
To check if an optional field is present in the message, use
the OnixS.SimpleBinaryEncoding.IFieldSet.Contains(System.Int32)
method.
Please see also the Reading optional fields section of the .NET SBE Codec Programming Guide.
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
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
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
OnixS.SimpleBinaryEncoding.IFieldSet.GetEnum(System.Int32)
and
OnixS.SimpleBinaryEncoding.IFieldSet.SetEnum(System.Int32,0)
methods.
Variable-length Fields
Variable-length fields is exposed by OnixS.SimpleBinaryEncoding.IVariableLengthField
interface.
Use 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 OnixS.SimpleBinaryEncoding.IFieldSet.GetBytes(System.Int32)
and 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)
.SetString(SenderIDTag, "GFP")
.SetString(ClOrdIDTag, "OrderId")
.SetEnum(TimeInForceTag, TimeInForce.Day)
.SetUnsignedInteger(OrderQtyTag, 1)
.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 = message.TryGetDecimal(PriceTag);