Strongly Typed Messages
By default, SBE messages and repeating groups can be accessed in
Session callbacks via the general OnixS.SimpleBinaryEncoding.IFieldSet
interface.
Also, there is a tool that allows generating an assembly with pre-generated strongly typed messages.
IFieldSet style code
int securityId = report.GetInteger(Tag.SecurityID);
string clOrdID = report.GetString(Tag.ClOrdID);
decimal price = report.GetDecimal(Tag.Price);
Strongly typed messages code
int securityId = report.SecurityID;
string clOrdID = report.ClOrdID;
decimal price = report.Price;
Note
Please note that strongly typed messages assembly should be generated each time when templates file is changed. Also, code, which depends on this assembly, should be rebuilt.
Using strongly typed messages
There are several steps that should be completed to use strongly typed messages:
- Generate strongly typed messages assembly with the tool, which is placed under the tools/sbe-decoder-generator folder of the installation package:
dotnet OnixS.SimpleBinaryEncoding.CodeGenerator.dll
Note
Please do not forget to place the actual templates file in the folder where this tool is located.
Add a reference to the generated OnixS.SimpleBinaryEncoding.Cme.dll to your project.
Set the Handler to load generated library:
settings.LoadDecoderLibrary = true;
- Create typed message object, set its fields, and send it:
NewOrderSingle514 order = new ();
order.SecurityID = securityId;
order.ClOrdID = clOrdId;
order.Price = price;
session.Send(order);
- Use template id to cast <xref:OnixS.SimpleBinaryEncoding.IMessage> to the required message type in callback:
if (e.Message.TemplateID == 522)
{
ExecutionReportNew522 report = (ExecutionReportNew522)e.Message;
}
- Use properties of the strongly typed message:
int securityId = report.SecurityID;
string clOrdID = report.ClOrdID;
decimal price = report.Price;
See Also
- The Typed Messages sample from the distribution package.