Custom decoders allow using SBE Decoder in the situations where default decoding scheme doesn’t work properly. For example, when a non-standard wire-level format used, or it is needed to use specific handling of normal wire-level data.
Such decoders should implement specific interface and must be created in response to specific callbacks of the OnixS::FIX::SBE::ISbeCustomCoderLibrary interface.
Where to use the customized SBE decoding | Interface to be implemented | Method of the library |
---|---|---|
A specific field that is not a FIX group. | OnixS::FIX::SBE::ISbeFieldDecoder | OnixS::FIX::SBE::ISbeCustomCoderLibrary::queryDecoder(ONIXS_FIXENGINE_UNUSED CoderOwnerId owner, ONIXS_FIXENGINE_UNUSED SbeFieldMetaData field) |
Dimensions for a FIX group. | OnixS::FIX::SBE::ISbeGroupDimensionDecoder | OnixS::FIX::SBE::ISbeCustomCoderLibrary::queryGroupDimensionDecoder(ONIXS_FIXENGINE_UNUSED CoderOwnerId owner, ONIXS_FIXENGINE_UNUSED SbeFieldSetMetaData field) |
A composite that is not included into FIX message (message header). | OnixS::FIX::SBE::ISbeCompositeDecoder | OnixS::FIX::SBE::ISbeCustomCoderLibrary::queryDecoder(ONIXS_FIXENGINE_UNUSED CoderOwnerId owner, ONIXS_FIXENGINE_UNUSED SbeTypeMetaData composite) |
Each decoder is created for particular owner that is denoted by the ownerId
parameter of the appropriate callback. Once created, the custom decoders must remain valid until the OnixS::FIX::SBE::ISbeCustomCoderLibrary::detach will be issued with the owner
parameter equal to the one used for creating of the custom decoder.
All the methods that create custom decoders have parameter that provides metadata of the object for which the decoder is requested. It is possible to keep copy of the metadata inside of the custom decoder but it will be valid only while the owning SBE decoder is valid also. The metadata object becomes invalid once the SBE decoder is deleted.
There are no specific requirements regarding uniqueness of the custom decoder, so it is possible to use the same custom decoder for different FIX fields or even to share it between different SBE coders. Ability of such sharing or reusing depends on the implementation.
To decode a single FIX field that is not a FIX group it is needed to implement OnixS::FIX::SBE::ISbeFieldDecoder interface and return appropriate pointer from the OnixS::FIX::SBE::ISbeCustomCoderLibrary::queryDecoder(ONIXS_FIXENGINE_UNUSED CoderOwnerId owner, ONIXS_FIXENGINE_UNUSED SbeFieldMetaData field) method.
The field decoder should use OnixS::FIX::SBE::SbeFieldDecoderOutput object to put the decoded data from the raw data chunk, provided by the data
and available
parameters for the OnixS::FIX::SBE::ISbeFieldDecoder::decode method. Errors of the process (if issued) must be reported via exceptions derived from the std::domain_error.
Please note that data
points to the rest of the whole SBE-encoded message but in most of cases the custom decoder should use only small part of the data.
The version
parameter repeats data retrieved from the message header. The custom decoder should adjust its behavior on the base of the version of the message decoded (if applicable).
To decode a FIX group dimensions it is needed to implement OnixS::FIX::SBE::ISbeGroupDimensionDecoder interface and return appropriate pointer from the OnixS::FIX::SBE::ISbeCustomCoderLibrary::queryGroupDimensionDecoder method.
The group dimension decoder is applied only for composite that encodes dimension of the particular repeating group (length of the root block, number of items, etc.). This decoder does not allow to decode the entire group, i.e. all its fields.
It is possible to use the SBE v2 RC2 extensions to the dimension encoding: the numGroups and numVarDataFields values. The need to use them depends on the specific SBE template.
The version
parameter repeats data retrieved from the message header. Most likely it is not be used by the custom decoder because usually the group dimension encoding does not depend on the message version.
To decode a composite that is not a part of FIX message it is needed to implement OnixS::FIX::SBE::ISbeCompositeDecoder interface and return appropriate pointer from the OnixS::FIX::SBE::ISbeCustomCoderLibrary::queryDecoder(ONIXS_FIXENGINE_UNUSED CoderOwnerId owner, ONIXS_FIXENGINE_UNUSED SbeTypeMetaData composite) method.
Such decoder is applied only for composites that are never included into the FIX message itself and SBE Decoder 'knows' how to use them. For now there is a single only such composite: the one that encodes the message header. Name of the type is mentioned in the 'headerType' attribute of the SBE template XML.
The version
parameter repeats maximum known version of the SBE template.