#pragma once /* * Copyright Onix Solutions Limited [OnixS]. All rights reserved. * * This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law * and international copyright treaties. * * Access to and use of the software is governed by the terms of the applicable ONIXS Software * Services Agreement (the Agreement) and Customer end user license agreements granting * a non-assignable, non-transferable and non-exclusive license to use the software * for it's own data processing purposes under the terms defined in the Agreement. * * Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part * of this source code or associated reference material to any other location for further reproduction * or redistribution, and any amendments to this copyright notice, are expressly prohibited. * * Any reproduction or redistribution for sale or hiring of the Software not in accordance with * the terms of the Agreement is a violation of copyright law. */ #include #include #include #include #include #include #include #include namespace OnixS { namespace FIX { ONIXS_FIXENGINE_API_DECL(class, Message); ONIXS_FIXENGINE_API_DECL(class, Dictionary); namespace SBE { /// The size of wire-level entities. typedef UInt32 SbeWireSize; /// The owner of custom coders. typedef UInt64 CoderOwnerId; /// The special value that usually mean "nothing" or "null" regarding wire-level entities. const SbeWireSize UnusedWireSizeValue = (std::numeric_limits::max)(); /// An appearance of the %SBE-encoded field struct SbePresence { enum Enum { /// The required field. Required, /// The optional field. Optional, /// The constant value. Constant }; }; /// The byte order of the message schema. struct SbeEndianness { enum Enum { /// The big endian order. BigEndian, /// The little endian order. LittleEndian }; }; /// The primitive type of the %SBE-encoded value. struct SbePrimitiveType { enum Enum { /// Inapplicable. Unknown, /// The character. Char, /// The signed 8-bits integer. Int8, /// The signed 16-bits integer. Int16, /// The signed 32-bits integer. Int32, /// The signed 64-bits integer. Int64, /// The unsigned 8-bits integer. UInt8, /// The unsigned 16-bits integer. UInt16, /// The unsigned 32-bits integer. UInt32, /// The unsigned 64-bits integer. UInt64, /// The single precision IEEE 754-2008 value (4 bytes). Float, /// The double precision IEEE 754-2008 value (8 bytes). Double }; }; /// The %FIX semantic type of the %SBE-encoded field. struct SbeFixSemanticType { enum Enum { /// Inapplicable or unknown. Unknown, /// The integer value. Int, /// The length value. Length, /// The tag number. TagNum, /// A message sequence number. SeqNum, /// The number of entries in a repeating group. NumInGroup, /// A day during a particular month (values 1 to 31). DayOfMonth, /// The quantity. Qty, /// A real number. Float, /// The price value. Price, /// A price offset that can be added to the Price. PriceOffset, /// A field typically representing a Price times a Qty. Amt, /// The percentage. Percentage, /// The single character. Char, /// A fixed-length character array. StringFixed, /// Alpha-numeric free format strings can include any character or punctuation. StringVariable, /// The non-ASCII string. The character encoding may be specified by a schema attribute. StringEncodedText, /// The variable-length data. Must be paired with a Length field. Data, /// The variable-length XML. Must be paired with a Length field. XmlData, /// The ISO 3166-1:2013 Country code. Country, /// The ISO 4217:2008 Currency code (3 character). Currency, /// The ISO 10383:2012 Market Identifier Code (MIC). Exchange, /// The National language - uses ISO 639-1:2002 standard. Language, /// A single choice of alternative values. ImplicitEnum, /// Values true or false. Boolean, /// The multiple choice of a set of values. MultipleCharValue, /// The multiple choice of a set of values. MultipleStringValue, /// A flexible date format that must include month and year at least, but may also include day or week. MonthYear, /// The time/date combination represented in UTC (Universal Time Coordinated, also known as "GMT"). UtcTimestamp, /// The time-only represented in UTC (Universal Time Coordinated, also known as "GMT"). UtcTimeOnly, /// The date represented in UTC (Universal Time Coordinated, also known as "GMT"). UtcDateOnly, /// The local date(as oppose to UTC). LocalMktDate, /// The time of a day. TzTimeOnly, /// The time/date combination representing the local time with an offset to UTC to allow an identification of the local time and the timezone offset of that time. The representation is based on ISO 8601:2004. TzTimestamp }; }; class SbeSchemaMetaData; /// The name and the description of an %SBE entity. class ONIXS_FIXENGINE_API ISbeNameDescription { public: /// The destructor. virtual ~ISbeNameDescription() ONIXS_FIXENGINE_DEFAULT; /// The name of the entity. virtual const std::string &name() const = 0; /// The description of the entity. virtual const std::string &description() const = 0; }; /// An %SBE entity that can be bound to the given message schema. class ONIXS_FIXENGINE_API ISchemaMember : public ISbeNameDescription { public: /// Returns true if the entity really bound to the message schema. virtual bool hasSchema() const = 0; /// The metadata of the schema. /// /// @throw The std::exception if hasSchema() == false. /// /// @return The message schema metadata if applicable. virtual SbeSchemaMetaData schema() const = 0; }; /// The named value. /// /// This class represents a named value that appears in the %SBE set or enumeration. class ONIXS_FIXENGINE_API SbeNamedValueMetaData : public ISchemaMember { public: /// The name of the value. const std::string& name() const ONIXS_FIXENGINE_OVERRIDE; /// The description of the value. const std::string& description() const ONIXS_FIXENGINE_OVERRIDE; /// Return true for most of such objects. bool hasSchema() const ONIXS_FIXENGINE_OVERRIDE; /// The schema metadata. SbeSchemaMetaData schema() const ONIXS_FIXENGINE_OVERRIDE; /// The value in the string presentation. const std::string& value() const; private: friend SbeNamedValueMetaData createSbeNamedValueMetaData(const void*); SbeNamedValueMetaData() {} SbeNamedValueMetaData(const void*); const void* details_; }; /// The metadata of the %SBE type. class ONIXS_FIXENGINE_API SbeTypeMetaData : public ISchemaMember { public: /// The name of the type. const std::string& name() const; /// The description of the type. const std::string& description() const; /// Return true for most of such objects. bool hasSchema() const ONIXS_FIXENGINE_OVERRIDE; /// The schema metadata. SbeSchemaMetaData schema() const ONIXS_FIXENGINE_OVERRIDE; /// The earliest version of the scheme where the type appears. unsigned sinceVersion() const; /// Checks if the object describes an %SBE set. bool isSet() const; /// Checks if the object describes an %SBE enumeration. bool isEnumeration() const; /// Checks if the object describes an %SBE composite. bool isComposite() const; /// Checks if the object describes a simple %SBE type. /// /// The simple type is a type that consists of a single field. This differs it against composites, arrays or field sets. bool isSimple() const; /// Checks if the object describes an %SBE array. bool isArray() const; /// Primitive type that is used by the given type. SbePrimitiveType::Enum primitiveType() const; /// The size of the type. /// /// @return 0 if the type is a variadic-length type or fixed size of the type in bytes. SbeWireSize fixedSize() const; /// The length of the fixed-length array. SbeWireSize arraySize() const; /// The local offset of the object. SbeWireSize localOffset() const; /// The presence of the type. SbePresence::Enum presence() const; /// The null value (if applicable). /// /// @return The null value if it applicable to the type; an empty string otherwise. const std::string& nullValue() const; /// The minimum value (if applicable). /// /// @return The minimum possible value if it applicable to the type; an empty string otherwise. const std::string& minValue() const; /// The maximum value (if applicable). /// /// @return The maximum possible value if it applicable to the type; an empty string otherwise. const std::string& maxValue() const; /// The constant value (if applicable). /// /// @return The constant value if it applicable to the type; an empty string otherwise. const std::string& constValue() const; /// The %FIX semantic type of the type if applicable. SbeFixSemanticType::Enum semanticType() const; /// The string presentation of the %FIX semantic type. const std::string& rawSemanticType() const; /// The epoch for the time-aware type. const std::string& timeEpoch() const; /// The time unit for the time-aware type. const std::string& timeUnit() const; /// The number of composite type members. size_t noOfMembers() const; /// The metadata of the particular composite member. SbeTypeMetaData member(size_t) const; /// The number of values for the multivalue type. size_t noOfValues() const; /// The metadata of the particular value. SbeNamedValueMetaData value(size_t) const; private: friend SbeTypeMetaData createSbeTypeMetaData(const void*); SbeTypeMetaData() {} SbeTypeMetaData(const void*); const void *details_; }; /// The metadata of the field set: the %FIX message of the %FIX repeating group. class ONIXS_FIXENGINE_API SbeFieldSetMetaData : public ISchemaMember { public: /// The name of the field set. const std::string& name() const ONIXS_FIXENGINE_OVERRIDE; /// The description. const std::string& description() const ONIXS_FIXENGINE_OVERRIDE; /// Always return true. bool hasSchema() const ONIXS_FIXENGINE_OVERRIDE; /// The metadata of the %SBE schema. SbeSchemaMetaData schema() const ONIXS_FIXENGINE_OVERRIDE; /// Checks if the field set has the parent field set. bool hasParent() const; /// The parent field set. /// /// @throw An exception when hasParent() == false. /// @return The metadata of the parent field set. const SbeFieldSetMetaData parent() const; /// The tag associated with the field set. /// /// This is the tag of the %FIX message or repeating group. int tag() const; /// Check if the field is a repeating group. bool isGroup() const; /// Check if the field is a %FIX message. bool isMessage() const; /// The metadata of the group dimension composite. SbeTypeMetaData groupDimensionType() const; /// The %FIX semantic type if the field set is a %FIX message. const std::string& messageSemanticType() const; private: friend SbeFieldSetMetaData createSbeFieldSetMetaData(const void*); SbeFieldSetMetaData() {} SbeFieldSetMetaData(const void*); const void* details_; }; class ONIXS_FIXENGINE_API SbeFieldMetaData : public ISchemaMember { public: /// The name of the field. const std::string& name() const ONIXS_FIXENGINE_OVERRIDE; /// The description. const std::string& description() const ONIXS_FIXENGINE_OVERRIDE; /// Always return true. bool hasSchema() const ONIXS_FIXENGINE_OVERRIDE; /// The metadata of the %SBE schema. SbeSchemaMetaData schema() const ONIXS_FIXENGINE_OVERRIDE; /// The parent of the %FIX field. SbeFieldSetMetaData parent() const; /// The %FIX tag of the field. int tag() const; /// Checks if the field represents a %FIX repeating group. bool isGroup() const; /// The %FIX group if the field is a group. /// /// @throw An exception if the field is not a %FIX group. SbeFieldSetMetaData group() const; /// The type of the field. SbeTypeMetaData typeMetaData() const; private: friend SbeFieldMetaData createSbeFieldMetaData(const void*); SbeFieldMetaData() {} SbeFieldMetaData(const void*); const void* details_; }; /// The metadata of the %SBE schema. class ONIXS_FIXENGINE_API SbeSchemaMetaData : public ISbeNameDescription { public: /// The name of the schema: repeats the schema Id in the text form. const std::string& name() const ONIXS_FIXENGINE_OVERRIDE; /// The description of the schema. /// /// The description appears in the "description" attribute of the <messageSchema> node. const std::string& description() const ONIXS_FIXENGINE_OVERRIDE; /// The schema Id. /// /// The id appears in the "id" attribute of the <messageSchema> node. UInt32 id() const; /// The schema package. /// /// The package name appears in the "package" attribute of the <messageSchema> node. const std::string& package() const; /// The schema version. /// /// The version appears in the "version" attribute of the <messageSchema> node. unsigned version() const; /// The schema semantic version. /// /// The semantic version appears in the "semanticVersion" attribute of the <messageSchema> node. const std::string& semanticVersion() const; /// The schema byte order. /// /// The byte order appears in the "byteOrder" attribute of the <messageSchema> node. SbeEndianness::Enum byteOrder() const; /// Checks if the schema has the message header composite. bool hasHeaderType() const; /// Returns the metadata of the message header composite. SbeTypeMetaData headerType() const; private: friend SbeSchemaMetaData createSbeSchemaMetaData(const void*); SbeSchemaMetaData() {} SbeSchemaMetaData(const void*); const void* details_; }; class ISbeManageCodingParameters; class ISbeFieldDecoder; class ISbeGroupDimensionDecoder; class ISbeCompositeDecoder; class ISbeFieldEncoder; class ISbeGroupDimensionEncoder; class ISbeCompositeEncoder; /// The coding modes management. /// /// The class allows to control different aspects of the coding without usage of custom coders. /// The request for the management is issued for each field of all %FIX messages unless the coding library /// has been provided a custom coder for the given %FIX field. class ONIXS_FIXENGINE_API SbeFieldCodingSettings { public: ~SbeFieldCodingSettings() ONIXS_FIXENGINE_DEFAULT; /// @name The handling of named values. /// The methods control how to handle fields that uses the name-value mapping. Such fields are set and enumeration fields. /// /// - When value names are not used externally (default) the raw value is exported to the %FIX message by the decoder or expected by the encoder. /// - When value names are used externally, the associated names are exported to %FIX messages by the decoder and expected by the encoder. /// @{ /// Controls the usage of value names. void useValueNamesExternally(bool); /// Checks if the value names are used externally. bool useValueNamesExternally() const; /// @} /// @name The Usage of the formatted date and time. /// The methods control how to handle fields that represents the date and time. /// /// - When usage of the formatted date and time specified (default), the raw value formatted into the %FIX-aware format like YYYYMMDD, etc. /// in dependency on the semantic type of the field. The formatted timestamps are produced by the decoder and expected by the encoder. /// /// - When usage of the formatted date and time is not specified, the raw numeric data is exported to the %FIX message by the decoder without an additional handling. /// The encoder also expects numeric data in such fields. /// @{ /// Controls the usage of the formatted date and time. void useFormattedDateTime(bool); /// Checks if the formatted date and time used. bool useFormattedDateTime() const; /// @} private: friend SbeFieldCodingSettings createSbeFieldCodingSettings(void*); SbeFieldCodingSettings() {} SbeFieldCodingSettings(void*); void* details_; }; /// The library that contains user-defined %SBE coders. class ONIXS_FIXENGINE_API ISbeCustomCoderLibrary { public: /// The destructor. virtual ~ISbeCustomCoderLibrary() ONIXS_FIXENGINE_DEFAULT; /// @name Attach and detach the library to a coder /// These methods used to inform the library about attaching and detaching of particular coders. /// /// @{ /// Attach the %SBE coder to the library. /// /// This method called one time during the initialization of the %SBE coder or decoder that will use this library. /// Exactly the same 'owner' parameter will be used for subsequent calls to create custom codecs or request for the management. /// /// @param owner The identifier of the attached coder. virtual void attach(ONIXS_FIXENGINE_UNUSED CoderOwnerId owner) {} /// Detaches the coder from the library. /// /// This method is called just before the destruction of the encoder or decoder that has been requested it for custom coders. /// The library can permanently remove codecs that were created for the given owner. /// /// @param owner The pointer to the object that owns removed coders. virtual void detach(ONIXS_FIXENGINE_UNUSED CoderOwnerId owner) {} /// @} /// @name The control coding without user-defined codecs /// /// The method allows to control the coding without creating of a custom coder. /// /// @{ /// Query for manage modes of the coding. /// /// This method is used to query the user code to manage modes of the coding that can be managed via the SbeFieldCodingSettings object. /// The method called once for each %FIX field. /// /// @param owner The owner of the request. /// @param field The field which coding modes will be controlled. /// @param settings The object that allows to control coding modes. virtual void queryCodingControl(ONIXS_FIXENGINE_UNUSED CoderOwnerId owner, ONIXS_FIXENGINE_UNUSED SbeFieldMetaData field, ONIXS_FIXENGINE_UNUSED SbeFieldCodingSettings settings) {} /// @} /// @name Custom decoders /// /// These methods are used to create custom decoders called by the Decoder or EventBasedDecoder. /// /// @{ /// Request for the custom decoder. /// /// Requests for the custom decoder that must be used to decode the particular field. The method should return a interface to the decoder instance or \c nullptr /// if the custom decoder should not be used. /// /// The main Decoder does not control life-cycle of the custom decoder and never deletes it directly. The pointer to the custom decoder must remain valid during /// all the time when the main Decoder appears. It is possible to delete the custom decoder only when the library receives the removeCoder callback. /// /// @param owner The object that owns the request. /// @param field The field that should be addressed by the custom decoder. virtual ISbeFieldDecoder* queryDecoder(ONIXS_FIXENGINE_UNUSED CoderOwnerId owner, ONIXS_FIXENGINE_UNUSED SbeFieldMetaData field) { return ONIXS_FIXENGINE_NULLPTR; } /// Request for the custom decoder of the group dimension. /// /// Requests for the custom decoder that must be used to decode the composite that keeps the group size. The method should return an interface to the decoder instance or \c nullptr /// if the custom decoder should not be used. /// /// The main Decoder does not control life-cycle of the custom decoder and never deletes it directly. The pointer to the custom decoder must remain valid during /// all the time when the main Decoder appears. It is possible to delete the custom decoder only when the library receives the removeCoder callback. /// /// @param owner The object that owns the request. /// @param field The field that should be addressed by the custom decoder. virtual ISbeGroupDimensionDecoder* queryGroupDimensionDecoder(ONIXS_FIXENGINE_UNUSED CoderOwnerId owner, ONIXS_FIXENGINE_UNUSED SbeFieldSetMetaData field) { return ONIXS_FIXENGINE_NULLPTR; } /// Request for the custom decoder of the separate composite. /// /// Requests for the decoder of such composite that never used within the message as a field. For now there is a single composite: the message header. /// @param owner The object that owns the request. /// @param composite The composite type that should be addressed by the custom decoder. virtual ISbeCompositeDecoder* queryDecoder(ONIXS_FIXENGINE_UNUSED CoderOwnerId owner, ONIXS_FIXENGINE_UNUSED SbeTypeMetaData composite) { return ONIXS_FIXENGINE_NULLPTR; } /// @} /// @name Custom encoders /// These methods are used to create custom encoders by the Encoder. /// /// @{ /// Request for the custom encoder. /// /// Requests for the custom encoder that must be used to encode the particular field. The method should return an interface to the encoder instance or \c nullptr /// if the custom encoder should not be used. /// /// The main Encoder does not control life-cycle of the custom encoder and never deletes it directly. The pointer to the custom encoder must remain valid during /// all the time when the main Encoder appears. It is possible to delete the custom encoder only when the library receives the detach callback. /// /// @param owner The object that owns the request. /// @param field The field that should be addressed by the custom encoder. virtual ISbeFieldEncoder* queryEncoder(ONIXS_FIXENGINE_UNUSED CoderOwnerId owner, ONIXS_FIXENGINE_UNUSED SbeFieldMetaData field) { return ONIXS_FIXENGINE_NULLPTR; } /// Request for the custom encoder of the group dimension. /// /// Requests for the custom encoder that must be used to decode composite that keeps the group size. The method should return an interface to the encoder instance or \c nullptr /// if the custom encoder should not be used. /// /// The main Encoder does not control life-cycle of the custom encoder and never deletes it directly. The pointer to the custom encoder must remain valid during /// all the time when the main Encoder appears. It is possible to delete the custom encoder only when the library receives the detach callback. /// /// @param owner The object that owns the request. /// @param group The group that should be addressed by the custom encoder. virtual ISbeGroupDimensionEncoder* queryGroupDimensionEncoder(ONIXS_FIXENGINE_UNUSED CoderOwnerId owner, ONIXS_FIXENGINE_UNUSED SbeFieldSetMetaData group) { return ONIXS_FIXENGINE_NULLPTR; } /// Request for the custom encoder of the separate composite. /// /// Requests for the encoder of such composite that never used within the message as a field. For now there is a single composite: the message header. /// /// @param owner The object that owns the request. /// @param composite The composite type that should be addressed by the custom encoder. virtual ISbeCompositeEncoder* queryEncoder(ONIXS_FIXENGINE_UNUSED CoderOwnerId owner, ONIXS_FIXENGINE_UNUSED SbeTypeMetaData composite) { return ONIXS_FIXENGINE_NULLPTR; } /// @} }; /// The output interface for the data decoded by the custom decoder. /// /// This class is used to assign data produced by the custom decoder to the particular field of the %FIX message or to report about such data via the IDecoderEvents interface. /// /// @note The class is copy-assignable and valid only during the appropriate callback of the custom decoder. class ONIXS_FIXENGINE_API SbeFieldDecoderOutput { public: ~SbeFieldDecoderOutput() ONIXS_FIXENGINE_DEFAULT; /// The field metadata for reference needs. SbeFieldMetaData field() const; /// Explicitly assigns Null value to the destination. void setNull(); /// Assigns the character value. void setChar(char value); /// Assigns the signed 16-bits value. void set(Int16 value); /// Assigns the unsigned 16-bits value. void set(UInt16 value); /// Assigns the signed 32-bits value. void set(Int32 value); /// Assigns the unsigned 32-bits value. void set(UInt32 value); /// Assigns the signed 64-bits value. void set(Int64 value); /// Assigns the unsigned 64-bits value. void set(UInt64 value); /// Assigns the float value. void set(float value); /// Assigns the double value. void set(double value); /// Assigns the plain data of the variadic length value. void set(const void* value, SbeWireSize length); /// Assigns the value as a string of the variadic length. void set(const char* value, SbeWireSize length); private: friend SbeFieldDecoderOutput createSbeFieldDecoderOutput(void*); SbeFieldDecoderOutput() {} SbeFieldDecoderOutput(void*); void* details_; }; /// The output interface for the data about the repeating group. /// /// This class is used by the custom decoder to report the core decoder about parameters of the repeating group, before the decoding of the repeating group itself. /// /// @note The class is copy-assignable and valid only during the appropriate callback of the custom decoder. class ONIXS_FIXENGINE_API SbeGroupDimensionOutput { public: /// The destructor. ~SbeGroupDimensionOutput() ONIXS_FIXENGINE_DEFAULT; /// The group metadata for reference needs. SbeFieldSetMetaData group() const; /// Reports data about the repeating group. /// /// @param blockLength The length of the fixed-length part of the repeating group item. /// @param itemCount The number of items in the repeating group. /// @param numGroups The number of nested groups of the given repeating group (optional). /// @param numVarDataFields The number of nested data fields of the given repeating group (optional). void set(SbeWireSize blockLength, SbeWireSize itemCount, SbeWireSize numGroups = UnusedWireSizeValue, SbeWireSize numVarDataFields = UnusedWireSizeValue); private: friend SbeGroupDimensionOutput createSbeGroupDimensionOutput(void*); SbeGroupDimensionOutput() {} SbeGroupDimensionOutput(void*); void* details_; }; /// The output interface for composites that are not used inside of %FIX messages. /// /// That class is used by the custom decoder to report the content of composites that are never incorporated into %FIX messages but must be used by the decoding process. /// For now there is a single only such composite: the message header composite. /// /// @note The class is copy-assignable and valid only during the appropriate callback of the custom decoder. class ONIXS_FIXENGINE_API SbeSpecialCompositeOutput { public: /// The destructor. ~SbeSpecialCompositeOutput() ONIXS_FIXENGINE_DEFAULT; /// The composite metadata for reference needs. SbeTypeMetaData type() const; /// Reports data about the message from the message header. /// /// @param blockLength The length of fixed-length part of the repeating group item. /// @param templateId The template Id of the message. /// @param schemaId The identifier of the schema. /// @param schemaVersion The version of the message. /// @param numGroups The number of nested groups of the given repeating group (optional). /// @param numVarDataFields The number of nested data fields of the given repeating group (optional). void setMessageHeader(SbeWireSize blockLength, unsigned templateId, UInt32 schemaId, unsigned schemaVersion, SbeWireSize numGroups = UnusedWireSizeValue, SbeWireSize numVarDataFields = UnusedWireSizeValue); private: friend SbeSpecialCompositeOutput createSbeSpecialCompositeOutput(void*); SbeSpecialCompositeOutput() {} SbeSpecialCompositeOutput(void*); void* details_; }; /// The interface of the custom decoder for the %FIX field. /// /// The interface must be implemented by the custom decoder that decodes a %FIX field. /// /// The decoder is attached to the particular field during the ISbeCustomCoderLibrary::queryDecoder. class ONIXS_FIXENGINE_API ISbeFieldDecoder { public: /// The destructor. virtual ~ISbeFieldDecoder() ONIXS_FIXENGINE_DEFAULT; /// Decode data for the field. /// /// This method is used to read wire-level data and convert it into the %FIX field value. The core decoder calls it if the user code /// provided the custom decoder for the particular %FIX field. /// /// @param output The destination for the decoded data. /// @param version The version of the message being decoded. /// @param data The wire-level data. /// @param available The number of wire-level bytes available to analyze. /// @return The number of used bytes. virtual size_t decode(SbeFieldDecoderOutput output, unsigned version, const void* data, size_t available) = 0; }; /// The interface of the custom decoder for the group dimension composite. /// /// The interface must be implemented by the decoder that decodes the group dimension composite. /// /// The decoder is attached to the particular %FIX group during the ISbeCustomCoderLibrary::queryGroupDimensionDecoder. class ONIXS_FIXENGINE_API ISbeGroupDimensionDecoder { public: /// The virtual destructor. virtual ~ISbeGroupDimensionDecoder() ONIXS_FIXENGINE_DEFAULT; /// Decode the group size data. /// /// This method is used to read wire-level data and restore repeating group parameters. The core decoder calls this method /// before the decoding of the repeating group content. /// /// @param output The destination for the decoded data. /// @param version The version of the message being decoded. /// @param data The wire-level data. /// @param available The number of wire-level bytes available to analyze. /// @return The number of used bytes. virtual size_t decode(SbeGroupDimensionOutput output, unsigned version, const void* data, size_t available) = 0; }; /// The interface of the custom decoder for composites that are not used inside of %FIX messages. /// /// The decoder is attached to the particular composite during the ISbeCustomCoderLibrary::queryDecoder. class ONIXS_FIXENGINE_API ISbeCompositeDecoder { public: /// The virtual destructor. virtual ~ISbeCompositeDecoder() ONIXS_FIXENGINE_DEFAULT; /// Decode composite data. /// /// This method is used to read wire-level data and restore the content of the required composite data. /// /// @param output The destination for the decoded data. /// @param version The version of the message being decoded. /// @param data The wire-level data. /// @param available The number of wire-level bytes available to analyze. /// @return The number of used bytes. virtual size_t decode(SbeSpecialCompositeOutput output, unsigned version, const void* data, size_t available) = 0; }; /// The stream to write the encoded data. class ONIXS_FIXENGINE_API SbeBinaryOutputStream { public: ~SbeBinaryOutputStream() ONIXS_FIXENGINE_DEFAULT; /// Write data. /// /// The method writes data to the destination binary stream and moves the stream pointer to the end of the written data. /// Subsequent writing will add new data to the end of the previously written ones. /// /// @param data The data to write. /// @param size The number of bytes to write. void put(const void* data, SbeWireSize size); private: friend SbeBinaryOutputStream createSbeBinaryOutputStream(void*); SbeBinaryOutputStream() {} SbeBinaryOutputStream(void*); void* details_; }; /// The Accessor to the field content. class ONIXS_FIXENGINE_API SbeConstFieldAccess { public: ~SbeConstFieldAccess() ONIXS_FIXENGINE_DEFAULT; /// The tag of the field that is being encoded. Tag tag() const; /// The complete metadata of the field that is encoded (contains the same tag as one returned by the tag() method). SbeFieldMetaData fieldMetaData() const; /// Checks if the field value is null. bool present() const; /// Tries to convert the field value to the string. bool toString(std::string&) const; /// Tries to convert the field value to the char. bool toChar(Char&) const; /// Tries to convert the field value to the 32-bits signed integer. bool toNumber(Int32&) const; /// Tries to convert the field value to the 32-bits unsigned integer. bool toNumber(UInt32&) const; /// Tries to convert the field value to the 64-bits signed integer. bool toNumber(Int64&) const; /// Tries to convert the field value to the 64-bits unsigned integer. bool toNumber(UInt64&) const; /// Tries to convert the field value to the double value. bool toNumber(Double&) const; /// Tries to convert the field value to the decimal. bool toNumber(Decimal&) const; /// Tries to convert the field value to the timestamp using the particular formatter. bool toTimestamp(Timestamp&, TimestampFormat::Enum = TimestampFormat::YYYYMMDDHHMMSSNsec) const; /// Tries to convert the field value to the timespan using the particular formatter. bool toTimeSpan(TimeSpan&, TimeSpanFormat::Enum = TimeSpanFormat::HHMMSSMsec) const; protected: friend SbeConstFieldAccess createSbeConstFieldAccess(Tag tag, const void*, const void*); SbeConstFieldAccess() {} SbeConstFieldAccess(Tag tag, const void*, const void*); Tag tag_; const void* details_; const void* details2_; }; /// The input interface for composites that are not used inside of %FIX messages. /// /// That class is used by custom encoders to get the content for composites that are never incorporated into %FIX messages but must be used by the encoding process. /// For now there is a single only such composite: the message header composite. /// /// @note The class is copy-assignable and valid only during the appropriate callback of the custom decoder. class ONIXS_FIXENGINE_API SbeSpecialCompositeInput { public: ~SbeSpecialCompositeInput() ONIXS_FIXENGINE_DEFAULT; /// Metadata of the composite which data are reported via this object. SbeTypeMetaData typeMetaData() const; /// Gets the message header data. /// /// Requests all or particular data for the %SBE message header. /// The data is provided in its most common form, as unsigned 32-bits integer values that is too wide for most of message headers. /// Thus the obtained values can (and usually - should) be converted by the encoder to other data types, for example, to the UInt16. /// /// @param blockLength The length of the 'root segment' of the message. /// @param templateId The required template Id to encode. /// @param schemaId The schema Id. /// @param schemaVersion The version of the template to use for the subsequent %FIX message. /// @param numOfGroups The number of groups in the top-level field set of the message. /// @param numOfVarDataFields The number of <data> fields in the top-level field set of the message. void getMessageHeaderData(UInt32* blockLength = ONIXS_FIXENGINE_NULLPTR, UInt32* templateId = ONIXS_FIXENGINE_NULLPTR, UInt32* schemaId = ONIXS_FIXENGINE_NULLPTR, UInt32* schemaVersion = ONIXS_FIXENGINE_NULLPTR, UInt32* numOfGroups = ONIXS_FIXENGINE_NULLPTR, UInt32* numOfVarDataFields = ONIXS_FIXENGINE_NULLPTR) const; protected: friend SbeSpecialCompositeInput createSbeSpecialCompositeInput(const void*); SbeSpecialCompositeInput() {} SbeSpecialCompositeInput(const void*); const void* details_; }; /// The input interface for the data about the repeating group. /// /// This class is used by the custom encoder to read parameters of the repeating group before the encoding of the repeating group itself. /// /// @note The class is copy-assignable and valid only during the appropriate callback of the custom decoder. class ONIXS_FIXENGINE_API SbeGroupDimensionInput { public: ~SbeGroupDimensionInput() ONIXS_FIXENGINE_DEFAULT; /// The field set of the group which dimensions are reported via this object. SbeFieldSetMetaData groupMetaData() const; /// Gets the group dimension data. /// /// @param blockLength The length of fixed-length part of the repeating group item. /// @param itemCount The number of items in the repeating group. /// @param numGroups The number of nested groups of the given repeating group (optional). /// @param numVarDataFields The number of nested data fields of the given repeating group (optional). void getGroupDimensionData(SbeWireSize* blockLength = ONIXS_FIXENGINE_NULLPTR, size_t* itemCount = ONIXS_FIXENGINE_NULLPTR, SbeWireSize* numGroups = ONIXS_FIXENGINE_NULLPTR, SbeWireSize* numVarDataFields = ONIXS_FIXENGINE_NULLPTR) const; protected: friend SbeGroupDimensionInput createSbeGroupDimensionInput(const void*); SbeGroupDimensionInput() {} SbeGroupDimensionInput(const void*); const void* details_; }; /// The interface of custom encoder for the %FIX field. /// /// The interface must be implemented by the custom encoder that encodes a %FIX field. /// /// The encoder is attached to the particular field during the ISbeCustomCoderLibrary::queryEncoder. class ONIXS_FIXENGINE_API ISbeFieldEncoder { public: virtual ~ISbeFieldEncoder() ONIXS_FIXENGINE_DEFAULT; /// Query for the size of the encoded field. /// /// This method should return the size of the encoded field if the field has a fixed binary size. /// In a case of a variable-length field, the method is **not called** and is considered to return zero. virtual SbeWireSize queryFixedSize(unsigned version) = 0; /// Encodes the %FIX field to the binary stream. /// /// This method is used to encode the %FIX field value to the binary data. The core encoder calls it if user code /// provided the custom encoder for the particular %FIX field. /// /// @note If the field is a fixed-length field, the number of written bytes must be exactly the same as reported via queryFixedSize. /// /// @param out The binary data stream for the encoded data. /// @param version The version of the %FIX message being encoded. /// @param field The %FIX field to encode. virtual void encode(SbeBinaryOutputStream out, unsigned version, const SbeConstFieldAccess &field) = 0; }; /// The interface of the custom encoder for composites that are not used inside of %FIX messages. /// /// The encoder is attached to the particular composite during the ISbeCustomCoderLibrary::queryEncoder. class ONIXS_FIXENGINE_API ISbeCompositeEncoder { public: virtual ~ISbeCompositeEncoder() ONIXS_FIXENGINE_DEFAULT; /// The encode composite data. /// /// This method is used to encode the composite to the binary data. /// /// @param out The binary data stream for the encoded data. /// @param version The version of the composite being encoded. /// @param input The content of the composite to encode. virtual void encode(SbeBinaryOutputStream out, unsigned version, SbeSpecialCompositeInput input) = 0; }; /// The interface of the custom encoder for the group dimension composite. /// /// The interface must be implemented by the encoder that encodes the group dimension composite. /// /// The encoder is attached to the particular %FIX group during the ISbeCustomCoderLibrary::queryGroupDimensionEncoder. class ONIXS_FIXENGINE_API ISbeGroupDimensionEncoder { public: virtual ~ISbeGroupDimensionEncoder() ONIXS_FIXENGINE_DEFAULT; /// Encodes the group size data. /// /// This method is used to encode the group dimension data to the output binary data. The core encoder calls this method /// before encoding of the repeating group content. /// /// @param out The binary data stream for the encoded data. /// @param version The version of the composite being encoded. /// @param input The data of the group to be encoded. virtual void encode(SbeBinaryOutputStream out, unsigned version, SbeGroupDimensionInput input) = 0; }; } } }