Custom encoders allow using SBE Encoder in the situations where default encoding 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 encoders 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 encoding | Interface to be implemented | Method of the library |
---|---|---|
A specific field that is not a FIX group. | OnixS::FIX::SBE::ISbeFieldEncoder | OnixS::FIX::SBE::ISbeCustomCoderLibrary::queryEncoder(ONIXS_FIXENGINE_UNUSED CoderOwnerId owner, ONIXS_FIXENGINE_UNUSED SbeFieldMetaData field) |
Dimensions for a FIX group. | OnixS::FIX::SBE::ISbeGroupDimensionEncoder | OnixS::FIX::SBE::ISbeCustomCoderLibrary::queryGroupDimensionEncoder(ONIXS_FIXENGINE_UNUSED CoderOwnerId owner, ONIXS_FIXENGINE_UNUSED SbeFieldSetMetaData group) |
A composite that is not included into FIX message (message header). | OnixS::FIX::SBE::ISbeCompositeEncoder | OnixS::FIX::SBE::ISbeCustomCoderLibrary::queryEncoder(ONIXS_FIXENGINE_UNUSED CoderOwnerId owner, ONIXS_FIXENGINE_UNUSED SbeTypeMetaData composite) |
Each decoder is created for particular owner that is denoted by the owner
parameter of the appropriate callback. Once created, the custom encoders 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 encoder.
All the methods that create custom encoders have parameter that provides metadata of the object for which the encoder is requested. It is possible to keep copy of the metadata inside of the custom encoder but it will be valid only while the owning SBE Encoder is valid also. The metadata object becomes invalid once the SBE decoder is deleted.
There are no specific requirements regarding uniqueness of the custom encoder, so it is possible to use the same custom encoder for different FIX fields or even to share it between different SBE coders. Ability of such sharing or reusing depends on the implementation.
To encode a single FIX field that is not a FIX group it is needed to implement OnixS::FIX::SBE::ISbeFieldEncoder interface and return appropriate pointer from the OnixS::FIX::SBE::ISbeCustomCoderLibrary::queryEncoder((ONIXS_FIXENGINE_UNUSED CoderOwnerId owner, ONIXS_FIXENGINE_UNUSED SbeFieldMetaData field) method.
The custom encoder will be requested by the main Encoder with the following order:
The field encoder should use OnixS::FIX::SBE::SbeBinaryOutputStream object to put the encoded data which values is obtained from the object of the OnixS::FIX::SBE::SbeConstFieldAccess type. Errors of the process (if issued) must be reported via exceptions derived from the std::domain_error.
The version
parameter repeats data retrieved from the message header. The custom encoder should adjust its behaviour on the base of the version of the message encoded (if applicable).
To encode a FIX group dimensions it is needed to implement OnixS::FIX::SBE::ISbeGroupDimensionEncoder interface and return appropriate pointer from the OnixS::FIX::SBE::ISbeCustomCoderLibrary::queryGroupDimensionEncoder method.
Main Encoder calls only OnixS::FIX::SBE::ISbeGroupDimensionEncoder::encode method to encode group dimension data.
The group dimension encoder is applied only for the composite that encodes dimension of the particular repeating group (length of the root block, number of items, etc.). This encoder does not allow to encode 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.
To encode a composite that is not a part of FIX message it is needed to implement OnixS::FIX::SBE::ISbeCompositeEncoder interface and return appropriate pointer from the OnixS::FIX::SBE::ISbeCustomCoderLibrary::queryEncoder(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 Encoder '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.
This encoder used by the OnixS::FIX::SBE::Encoder::encodeWithHeader method before encoding of the FIX message and there is particular dependency between input parameters of this method and values that arrive to the decoder:
version
input parameter and the version value that is received from OnixS::FIX::SBE::SbeSpecialCompositeInput::getMessageHeaderData are equal and repeat input value of the encodeWithHeader
method;templateId
value that is received from OnixS::FIX::SBE::SbeSpecialCompositeInput::getMessageHeaderData is equal to the input parameter of the encodeWithHeader
method.