forwardSecurity Definitions Cache   Table of ContentReplaying Log Filesforward
Strongly Typed Messages

By default SBE messages and repeating groups can be accessed in Handler callbacks via IFieldSet interface. But there is a tool which allows to use pre-generated strongly typed messages.

IFieldSet style code:

C#
int securityId = securityDefinition.DefinitionMessage.GetInteger(Tags.SecurityID);
string symbol = securityDefinition.DefinitionMessage.GetString(Tags.Symbol);
int contractMultiplier = securityDefinition.DefinitionMessage.GetInteger(Tags.ContractMultiplier);

Strongly typed messages code:

C#
if (securityDefinition.DefinitionMessage.TemplateID == 27)
{
    MDInstrumentDefinitionFuture27 definition = (MDInstrumentDefinitionFuture27)securityDefinition.DefinitionMessage;
    int securityId = definition.SecurityID;
    string symbol = definition.Symbol;
    int contractMultiplier = definition.ContractMultiplier;
}

Note Note

Please note, that strongly typed messages assembly should be generated each time, when templates file will be changed. Also code, which depends on this assembly, should be rebuilded.

Using strongly typed messages

There're are several steps which should be completed to use strongly typed messages:

  1. Generate strongly typed messages assembly with tool, which is placed under tools\sbe-decoder-generator folder of the installation package:

    OnixS.SimpleBinaryEncoding.DecoderGenerator.exe
    Please do not forget to place actual templates file to the folder, where this tool is located.

  2. Add a reference to the generated OnixS.SimpleBinaryEncoding.Cme.dll to your project.

  3. Set the Handler to load generated library:

    C#
    handler.LoadDecoderLibrary = true;
  4. Use template id to cast IMessage to the required message type:

    C#
    if (securityDefinition.DefinitionMessage.TemplateID == 27)
    {
        MDInstrumentDefinitionFuture27 definition = (MDInstrumentDefinitionFuture27)securityDefinition.DefinitionMessage;
    }
  5. Use properties of the strongly typed message:

    C#
    int securityId = definition.SecurityID;
    string symbol = definition.Symbol;
    int contractMultiplier = definition.ContractMultiplier;