fix8  version 1.4.0
Open Source C++ FIX Framework
FIX8::Message Class Reference

A complete Fix message with header, body and trailer. More...

#include <message.hpp>

Inheritance diagram for FIX8::Message:
FIX8::MessageBase FIX8::TEX::AdjustedPositionReport FIX8::TEX::Advertisement FIX8::TEX::AllocationInstruction FIX8::TEX::AllocationInstructionAck FIX8::TEX::AllocationInstructionAlert FIX8::TEX::AllocationReport FIX8::TEX::AllocationReportAck FIX8::TEX::ApplicationMessageReport FIX8::TEX::ApplicationMessageRequest FIX8::TEX::ApplicationMessageRequestAck FIX8::TEX::AssignmentReport FIX8::TEX::BidRequest FIX8::TEX::BidResponse FIX8::TEX::BusinessMessageReject FIX8::TEX::CollateralAssignment FIX8::TEX::CollateralInquiry FIX8::TEX::CollateralInquiryAck FIX8::TEX::CollateralReport FIX8::TEX::CollateralRequest FIX8::TEX::CollateralResponse FIX8::TEX::Confirmation FIX8::TEX::ConfirmationAck FIX8::TEX::ConfirmationRequest FIX8::TEX::ContraryIntentionReport FIX8::TEX::CrossOrderCancelReplaceRequest FIX8::TEX::CrossOrderCancelRequest FIX8::TEX::DerivativeSecurityList FIX8::TEX::DerivativeSecurityListRequest FIX8::TEX::DerivativeSecurityListUpdateReport FIX8::TEX::DontKnowTrade FIX8::TEX::Email FIX8::TEX::ExecutionAcknowledgement FIX8::TEX::ExecutionReport FIX8::TEX::ExecutionReport FIX8::TEX::Heartbeat FIX8::TEX::Heartbeat FIX8::TEX::IOI FIX8::TEX::ListCancelRequest FIX8::TEX::ListExecute FIX8::TEX::ListStatus FIX8::TEX::ListStatusRequest FIX8::TEX::ListStrikePrice FIX8::TEX::Logon FIX8::TEX::Logon FIX8::TEX::Logout FIX8::TEX::Logout FIX8::TEX::MarketDataIncrementalRefresh FIX8::TEX::MarketDataRequest FIX8::TEX::MarketDataRequestReject FIX8::TEX::MarketDataSnapshotFullRefresh FIX8::TEX::MarketDefinition FIX8::TEX::MarketDefinitionRequest FIX8::TEX::MarketDefinitionUpdateReport FIX8::TEX::MassQuote FIX8::TEX::MassQuoteAcknowledgement FIX8::TEX::MultilegOrderCancelReplace FIX8::TEX::NetworkCounterpartySystemStatusRequest FIX8::TEX::NetworkCounterpartySystemStatusResponse FIX8::TEX::NewOrderCross FIX8::TEX::NewOrderList FIX8::TEX::NewOrderMultileg FIX8::TEX::NewOrderSingle FIX8::TEX::NewOrderSingle FIX8::TEX::News FIX8::TEX::OrderCancelReject FIX8::TEX::OrderCancelReplaceRequest FIX8::TEX::OrderCancelRequest FIX8::TEX::OrderMassActionReport FIX8::TEX::OrderMassActionRequest FIX8::TEX::OrderMassCancelReport FIX8::TEX::OrderMassCancelRequest FIX8::TEX::OrderMassStatusRequest FIX8::TEX::OrderStatusRequest FIX8::TEX::PartyDetailsListReport FIX8::TEX::PartyDetailsListRequest FIX8::TEX::PositionMaintenanceReport FIX8::TEX::PositionMaintenanceRequest FIX8::TEX::PositionReport FIX8::TEX::Quote FIX8::TEX::QuoteCancel FIX8::TEX::QuoteRequest FIX8::TEX::QuoteRequestReject FIX8::TEX::QuoteResponse FIX8::TEX::QuoteStatusReport FIX8::TEX::QuoteStatusRequest FIX8::TEX::RegistrationInstructions FIX8::TEX::RegistrationInstructionsResponse FIX8::TEX::Reject FIX8::TEX::Reject FIX8::TEX::RequestForPositions FIX8::TEX::RequestForPositionsAck FIX8::TEX::ResendRequest FIX8::TEX::ResendRequest FIX8::TEX::RFQRequest FIX8::TEX::SecurityDefinition FIX8::TEX::SecurityDefinitionRequest FIX8::TEX::SecurityDefinitionUpdateReport FIX8::TEX::SecurityList FIX8::TEX::SecurityListRequest FIX8::TEX::SecurityListUpdateReport FIX8::TEX::SecurityStatus FIX8::TEX::SecurityStatusRequest FIX8::TEX::SecurityTypeRequest FIX8::TEX::SecurityTypes FIX8::TEX::SequenceReset FIX8::TEX::SequenceReset FIX8::TEX::SettlementInstructionRequest FIX8::TEX::SettlementInstructions FIX8::TEX::SettlementObligationReport FIX8::TEX::StreamAssignmentReport FIX8::TEX::StreamAssignmentReportACK FIX8::TEX::StreamAssignmentRequest FIX8::TEX::TestRequest FIX8::TEX::TestRequest FIX8::TEX::TradeCaptureReport FIX8::TEX::TradeCaptureReportAck FIX8::TEX::TradeCaptureReportRequest FIX8::TEX::TradeCaptureReportRequestAck FIX8::TEX::TradingSessionList FIX8::TEX::TradingSessionListRequest FIX8::TEX::TradingSessionListUpdateReport FIX8::TEX::TradingSessionStatus FIX8::TEX::TradingSessionStatusRequest FIX8::TEX::UserNotification FIX8::TEX::UserRequest FIX8::TEX::UserResponse

Public Member Functions

template<typename InputIterator >
 Message (const F8MetaCntx &ctx, const f8String &msgType, const InputIterator begin, const size_t cnt, const FieldTrait_Hash_Array *ftha)
 
virtual ~Message ()
 Dtor. More...
 
MessageBaseHeader () const
 
MessageBaseTrailer () const
 
MessageBaseHeader ()
 
MessageBaseTrailer ()
 
unsigned decode (const f8String &from, unsigned offset=0, unsigned ignore=0, bool permissive_mode=false)
 
F8API size_t encode (f8String &to) const
 
F8API size_t encode (char **to) const
 Encode message with minimal copying. More...
 
F8API Messageclone () const
 
virtual bool process (Router &rt) const
 
virtual bool is_admin () const
 
virtual void clear (bool reuse=true)
 
virtual void set_custom_seqnum (unsigned seqnum)
 
unsigned get_custom_seqnum () const
 
virtual void set_no_increment (bool flag=true)
 
virtual bool get_no_increment () const
 
bool get_end_of_batch () const
 
void set_end_of_batch (bool is_end_of_batch)
 
void setup_reuse ()
 
void push_unknown (Message *to) const
 
BaseFieldget_field_flattened (const unsigned short fnum) const
 
BaseFieldget_field_by_name_flattened (const char *tag) const
 
virtual F8API void print (std::ostream &os, int depth=0) const
 
- Public Member Functions inherited from FIX8::MessageBase
template<typename InputIterator >
 MessageBase (const struct F8MetaCntx &ctx, const f8String &msgType, const InputIterator begin, const size_t cnt, const FieldTrait_Hash_Array *ftha)
 
F8API MessageBase (const MessageBase &from)
 Copy ctor. More...
 
F8API MessageBaseoperator= (const MessageBase &that)
 Assignment operator. More...
 
virtual ~MessageBase ()
 Dtor. More...
 
void clear_positions ()
 empty the positions map More...
 
size_t size () const
 
F8API unsigned decode (const f8String &from, unsigned offset, unsigned ignore=0, bool permissive_mode=false)
 
unsigned decode_group (GroupBase *grpbase, const unsigned short fnum, const f8String &from, unsigned s_offset, unsigned ignore)
 
F8API size_t encode (std::ostream &to) const
 
F8API size_t encode (char *to) const
 
F8API size_t encode_group (const unsigned short fnum, std::ostream &to) const
 
F8API size_t encode_group (const unsigned short fnum, char *to) const
 
virtual GroupBasecreate_nested_group (unsigned short fnum) const
 
F8API unsigned check_positions ()
 
F8API unsigned copy_legal (MessageBase *to, bool force=false) const
 
F8API unsigned move_legal (MessageBase *to, bool force=false)
 
void push_unknown (MessageBase *to) const
 
void check_set_rlm (BaseField *where) const
 
const f8Stringget_msgtype () const
 
void add_field_decoder (const unsigned short fnum, const unsigned pos, BaseField *what)
 
void add_field (const unsigned short fnum, Presence::const_iterator itr, const unsigned pos, BaseField *what, bool check)
 
void add_field (const unsigned short fnum, Fields::iterator fitr, const unsigned pos, BaseField *what, bool check=true)
 
void add_field (const unsigned short fnum, const unsigned pos, BaseField *what, bool check=true)
 
void set (const unsigned short field, FieldTrait::TraitTypes type=FieldTrait::present)
 
template<typename T >
bool add_field (T *what)
 
bool add_field (BaseField *what)
 
Groupsget_groups ()
 
template<typename T >
bool operator+= (T *what)
 
template<typename T >
MessageBaseoperator<< (T *what)
 
template<typename T >
bool get (T &to) const
 
template<typename T >
bool has () const
 
bool is_legal (unsigned short fnum) const
 
template<typename T >
bool is_legal () const
 
template<typename T >
const T * get () const
 
template<typename T >
bool operator() (T &to) const
 
template<typename T >
const T * operator() () const
 
bool have (const unsigned short fnum) const
 
Fields::const_iterator find_field (const unsigned short fnum) const
 
BaseFieldget_field (const unsigned short fnum) const
 
BaseFieldget_field_by_name (const char *tag) const
 
Fields::const_iterator fields_begin () const
 
Fields::const_iterator fields_end () const
 
F8API BaseFieldreplace (const unsigned short fnum, Presence::const_iterator itr, BaseField *with)
 
F8API BaseFieldreplace (const unsigned short fnum, BaseField *with)
 
F8API GroupBasereplace (const unsigned short fnum, GroupBase *with)
 
F8API BaseFieldremove (const unsigned short fnum, Presence::const_iterator itr)
 
F8API BaseFieldremove (const unsigned short fnum)
 
template<typename T >
GroupBasefind_group () const
 
GroupBasefind_group (const unsigned short fnum) const
 
template<typename T >
GroupBasefind_add_group (GroupBase *grpbase=nullptr)
 
GroupBasefind_add_group (const unsigned short fnum, GroupBase *grpbase=nullptr)
 
template<typename T >
void append_group (T *what)
 
void add_group (GroupBase *what)
 
MessageBaseoperator<< (GroupBase *what)
 
void operator+= (GroupBase *what)
 
unsigned short getPos (const unsigned short field) const
 
bool add_trait (const FieldTrait &what)
 
template<typename InputIterator >
void add_trait (const InputIterator begin, const size_t cnt)
 
virtual F8API void print_field (const unsigned short fnum, std::ostream &os) const
 
virtual F8API void print_group (const unsigned short fnum, std::ostream &os, int depth=0) const
 
const FieldTraitsget_fp () const
 
void print_fp (std::ostream &os)
 
virtual begin_stringget_begin_string ()
 
virtual body_lengthget_body_length ()
 
virtual msg_typeget_msg_type ()
 
virtual check_sumget_check_sum ()
 
const f8Stringget_unknown () const
 

Static Public Member Functions

static unsigned calc_chksum (const char *from, const size_t sz, const unsigned offset=0, const int len=-1)
 
static unsigned calc_chksum (const f8String &from, const unsigned offset=0, const int len=-1)
 
static f8String fmt_chksum (const unsigned val)
 
static Messagefactory (const F8MetaCntx &ctx, const char *from, bool no_chksum=false, bool permissive_mode=false)
 
static F8API Messagefactory (const F8MetaCntx &ctx, const f8String &from, bool no_chksum=false, bool permissive_mode=false)
 
- Static Public Member Functions inherited from FIX8::MessageBase
static unsigned extract_element (const char *from, const unsigned sz, char *tag, char *val)
 
static unsigned extract_element_fixed_width (const char *from, const unsigned sz, const unsigned val_sz, char *tag, char *val)
 
static unsigned extract_element (const char *from, const unsigned sz, f8String &tag, f8String &val)
 
static void set_tabsize (unsigned tabsize)
 
static unsigned get_tabsize ()
 
static bool has_group_count (const BaseField *bf)
 

Protected Attributes

MessageBase_header
 
MessageBase_trailer
 
unsigned _custom_seqnum
 
bool _no_increment
 
bool _end_of_batch
 
- Protected Attributes inherited from FIX8::MessageBase
Fields _fields
 
FieldTraits _fp
 
Positions _pos
 
Groups _groups
 
const f8String_msgType
 
const F8MetaCntx_ctx
 

Friends

std::ostream & operator<< (std::ostream &os, const Message &what)
 

Additional Inherited Members

- Static Protected Member Functions inherited from FIX8::MessageBase
static unsigned extract_header (const f8String &from, char *len, char *mtype)
 
static unsigned extract_trailer (const f8String &from, f8String &chksum)
 
- Static Protected Attributes inherited from FIX8::MessageBase
static F8API unsigned _tabsize = defaults::tabsize
 

Detailed Description

A complete Fix message with header, body and trailer.

Definition at line 1058 of file message.hpp.

Constructor & Destructor Documentation

template<typename InputIterator >
FIX8::Message::Message ( const F8MetaCntx ctx,
const f8String msgType,
const InputIterator  begin,
const size_t  cnt,
const FieldTrait_Hash_Array ftha 
)
inline

Ctor.

Template Parameters
InputIteratorinput iterator type
Parameters
ctx- reference to generated metadata
msgType- reference to Fix message type
begin- InputIterator pointing to begining of field trait table
cnt- number of elements in field trait table
fthafield trait hash array

Definition at line 1087 of file message.hpp.

1089  : MessageBase(ctx, msgType, begin, cnt, ftha),_header(ctx._mk_hdr(true)),
1091  {}
MessageBase(const struct F8MetaCntx &ctx, const f8String &msgType, const InputIterator begin, const size_t cnt, const FieldTrait_Hash_Array *ftha)
Definition: message.hpp:419
const F8MetaCntx & ctx()
Compiler generated metadata object, accessed through this function.
MessageBase * _trailer
Definition: message.hpp:1065
msg_create _mk_trl
Definition: message.hpp:226
unsigned _custom_seqnum
Definition: message.hpp:1066
msg_create _mk_hdr
References to the header and trailer create functions.
Definition: message.hpp:226
bool _no_increment
Definition: message.hpp:1067
bool _end_of_batch
Definition: message.hpp:1067
MessageBase * _header
Definition: message.hpp:1065
virtual FIX8::Message::~Message ( )
inlinevirtual

Dtor.

Definition at line 1094 of file message.hpp.

References _header, and _trailer.

1094 { delete _header; delete _trailer; }
MessageBase * _trailer
Definition: message.hpp:1065
MessageBase * _header
Definition: message.hpp:1065

Member Function Documentation

static unsigned FIX8::Message::calc_chksum ( const char *  from,
const size_t  sz,
const unsigned  offset = 0,
const int  len = -1 
)
inlinestatic

Generate a checksum from an encoded buffer, ULL version.

Parameters
fromchar *buffer encoded Fix message
szsize of msg
offsetstarting offset
lenmaximum length
Returns
calculated checknum

Definition at line 1170 of file message.hpp.

Referenced by calc_chksum().

1171  {
1172 #if defined FIX8_SIZEOF_UNSIGNED_LONG && FIX8_SIZEOF_UNSIGNED_LONG == 8
1173  // steroid chksum algorithm by charles.cooper@lambda-tg.com
1174  // Basic strategy is to unroll the loop. normally adding in a loop
1175  // is slow because of the dependency, the cpu has to finish each loop
1176  // before it starts the next one and is unable to pipeline. one
1177  // way to get around this is to have multiple registers and have
1178  // multiple adds per loop, then consolidating at the end
1179  // as in unroll_checksum.
1180  // that is slow though because there is a lot of wasted space and
1181  // the cpu has to do a lot of adds.
1182  // key is that addition of a word is going to be faster
1183  // than addition of two chars, and also each word has 8 chars in it.
1184  // so we get 8 adds per loop. long1 + long2 is almost like
1185  // looping over two arrays of 8 chars and adding them element wise.
1186  // except for the overflow. so we have to keep track of the overflow
1187  // and get rid of it at the end.
1188 
1189  const unsigned long OVERFLOW_MASK (1UL << 8 | 1UL << 16 | 1UL << 24 | 1UL << 32 | 1UL << 40 | 1UL << 48 | 1UL << 56);
1190  unsigned long ret{}, overflow{};
1191  from += offset;
1192  const unsigned long elen (len != -1 ? len : sz);
1193  size_t ii{};
1194  for (; ii < (elen - elen % 8); ii += 8)
1195  {
1196  unsigned long expected_overflow((ret & OVERFLOW_MASK) ^ (OVERFLOW_MASK & *reinterpret_cast<const unsigned long*>(from + ii)));
1197  ret += *reinterpret_cast<const unsigned long*>(from + ii);
1198  overflow += (expected_overflow ^ ret) & OVERFLOW_MASK;
1199  }
1200  ret = COLLAPSE_INT64(ret);
1201  overflow = COLLAPSE_INT64(overflow);
1202  for (; ii < elen; ret += from[ii++]); // add up rest one by one
1203  return (ret - overflow) & 0xff;
1204 #else
1205  // native chksum algorithm
1206  unsigned val(0);
1207  const char *eptr(from + (len != -1 ? len + offset : sz - offset));
1208  for (const char *ptr(from + offset); ptr < eptr; val += *ptr++);
1209  return val % 256;
1210 #endif
1211  }
static unsigned FIX8::Message::calc_chksum ( const f8String from,
const unsigned  offset = 0,
const int  len = -1 
)
inlinestatic

Generate a checksum from an encoded buffer, string version.

Parameters
fromsource buffer encoded Fix message
offsetstarting offset
lenmaximum length
Returns
calculated checknum

Definition at line 1218 of file message.hpp.

References calc_chksum().

1219  { return calc_chksum(from.c_str(), from.size(), offset, len); }
static unsigned calc_chksum(const char *from, const size_t sz, const unsigned offset=0, const int len=-1)
Definition: message.hpp:1170
virtual void FIX8::Message::clear ( bool  reuse = true)
inlinevirtual

Empty messages from container

Parameters
reuseif true clear vector

Reimplemented from FIX8::MessageBase.

Definition at line 1155 of file message.hpp.

References FIX8::MessageBase::clear().

1156  {
1157  if (_header)
1158  _header->clear(reuse);
1159  if (_trailer)
1160  _trailer->clear(reuse);
1161  MessageBase::clear(reuse);
1162  }
MessageBase * _trailer
Definition: message.hpp:1065
virtual void clear(bool reuse=true)
Definition: message.hpp:433
MessageBase * _header
Definition: message.hpp:1065
Message * Message::clone ( ) const

Clone this message. Performs a deep copy.

Returns
pointer to copy of this message

Definition at line 668 of file message.cpp.

References FIX8::BaseMsgEntry::_create, and FIX8::Minst::_do.

Referenced by FIX8::ConsoleMenu::RemoveMsg().

669 {
670  const BaseMsgEntry& bme(_ctx._bme.find_ref(_msgType.c_str()));
671  Message *msg(bme._create._do(true));
672  // important not to pass force as true with copy_legal here
673  copy_legal(msg);
674  _header->copy_legal(msg->_header);
675  _trailer->copy_legal(msg->_trailer);
676  return msg;
677 }
const MsgTable & _bme
Framework generated lookup table to generate Fix messages.
Definition: message.hpp:216
Message instantiation table entry.
Definition: message.hpp:192
F8API unsigned copy_legal(MessageBase *to, bool force=false) const
Definition: message.cpp:275
const F8MetaCntx & _ctx
Definition: message.hpp:392
MessageBase * _trailer
Definition: message.hpp:1065
A complete Fix message with header, body and trailer.
Definition: message.hpp:1058
const Val & find_ref(const Key &key) const
Definition: f8types.hpp:143
const f8String & _msgType
Definition: message.hpp:391
MessageBase * _header
Definition: message.hpp:1065
unsigned FIX8::Message::decode ( const f8String from,
unsigned  offset = 0,
unsigned  ignore = 0,
bool  permissive_mode = false 
)
inline

Decode from string.

Parameters
fromsource string
offsetin bytes to decode from
ignorebytes to ignore counting back from end of message
permissive_modeif true, ignore unknown fields
Returns
number of bytes consumed

Definition at line 1118 of file message.hpp.

References FIX8::MessageBase::decode().

1119  {
1120  const unsigned hlen(_header->decode(from, offset, 0, permissive_mode));
1121  const unsigned blen(MessageBase::decode(from, hlen, 0, permissive_mode));
1122 #if defined FIX8_RAW_MSG_SUPPORT
1123  _begin_payload = hlen;
1124  _payload_len = blen;
1125  _rawmsg = from;
1126 #endif
1127  return _trailer->decode(from, blen, ignore, permissive_mode);
1128  }
F8API unsigned decode(const f8String &from, unsigned offset, unsigned ignore=0, bool permissive_mode=false)
Definition: message.cpp:87
MessageBase * _trailer
Definition: message.hpp:1065
MessageBase * _header
Definition: message.hpp:1065
size_t Message::encode ( f8String to) const

Encode message to stream.

Parameters
tostream to encode to
Returns
number of bytes encoded

Definition at line 500 of file message.cpp.

References FIX8_MAX_MSG_LENGTH, and FIX8::HEADER_CALC_OFFSET().

501 {
502  char output[FIX8_MAX_MSG_LENGTH + HEADER_CALC_OFFSET], *ptr(output);
503  const size_t msgLen(encode(&ptr));
504  to.assign(ptr, msgLen);
505  return to.size();
506 }
F8API size_t encode(f8String &to) const
Definition: message.cpp:500
const size_t HEADER_CALC_OFFSET(32)
#define FIX8_MAX_MSG_LENGTH
Definition: f8config.h:576
size_t Message::encode ( char **  to) const

Encode message with minimal copying.

Encode message to stream. Perform absolutely minimal copying of output buffer.

Parameters
topointer to pointer to buffer
Returns
number of bytes encoded; to ptr is updated with address of start of encoded message string

Definition at line 422 of file message.cpp.

References FIX8::IntervalTimer::AsDouble(), FIX8::IntervalTimer::Calculate(), FIX8::Common_BeginString(), FIX8::Common_BodyLength(), FIX8::Common_CheckSum(), FIX8::MessageBase::encode(), FIX8::HEADER_CALC_OFFSET(), and FIX8::FieldTrait::suppress.

423 {
424  char *moffs(*hmsg_store + HEADER_CALC_OFFSET), *msg(moffs);
425 
426 #if defined FIX8_CODECTIMING
427  IntervalTimer itm;
428 #endif
429 
430  if (!_header)
431  throw MissingMessageComponent("header");
432  _header->get_msg_type()->set(_msgType);
433 
434 #if defined FIX8_RAW_MSG_SUPPORT
435  msg += (_begin_payload = _header->encode(msg)); // start
436 #if defined FIX8_PREENCODE_MSG_SUPPORT
437  if (_preencode_len)
438  {
439  ::memcpy(msg, _preencode.data(), _payload_len =_preencode_len);
440  msg += _preencode_len;
441  }
442  else
443 #endif
444  msg += (_payload_len = MessageBase::encode(msg));
445 #else
446  msg += _header->encode(msg); // start
447 #if defined FIX8_PREENCODE_MSG_SUPPORT
448  if (_preencode_len)
449  {
450  ::memcpy(msg, _preencode.data(), _preencode_len);
451  msg += _preencode_len;
452  }
453  else
454 #endif
455  msg += MessageBase::encode(msg);
456 #endif
457 
458  if (!_trailer)
459  throw MissingMessageComponent("trailer");
460  msg += _trailer->encode(msg);
461  const size_t msgLen(msg - moffs); // checksummable msglength
462  const size_t hlen(_ctx._preamble_sz +
463  (msgLen < 10 ? 1 : msgLen < 100 ? 2 : msgLen < 1000 ? 3 : msgLen < 10000 ? 4 :
464  msgLen < 100000 ? 5 : msgLen < 1000000 ? 6 : 7));
465  char *hmsg(moffs - hlen);
466  *hmsg_store = hmsg;
467 
468  if (!_header->get_begin_string())
471  hmsg += _header->get_begin_string()->encode(hmsg);
472 
473  if (!_header->get_body_length())
476 
477  _header->get_body_length()->set(static_cast<int>(msgLen));
478  hmsg += _header->get_body_length()->encode(hmsg);
479 
480  if (!_trailer->get_check_sum())
482  _trailer->get_check_sum()->set(fmt_chksum(calc_chksum(moffs - hlen, msgLen + hlen)));
484  msg += _trailer->get_check_sum()->encode(msg);
485 
486 #if defined FIX8_CODECTIMING
487  _encode_timings._cpu_used += itm.Calculate().AsDouble();
488  ++_encode_timings._msg_count;
489 #endif
490 
491  *msg = 0;
492  const size_t rlen(msg - *hmsg_store);
493 #if defined FIX8_RAW_MSG_SUPPORT
494  _rawmsg.assign(*hmsg_store, rlen);
495 #endif
496  return rlen;
497 }
const IntervalTimer & Calculate()
Definition: timer.hpp:262
size_t encode(std::ostream &os) const
Definition: field.hpp:184
An outbound message was missing a header or trailer.
FieldTraits _fp
Definition: message.hpp:388
const unsigned short Common_CheckSum(10)
void clear(const unsigned short field, Presence::const_iterator &itr, FieldTrait::TraitTypes type=FieldTrait::present)
Definition: traits.hpp:550
virtual body_length * get_body_length()
Definition: message.hpp:1011
static f8String fmt_chksum(const unsigned val)
Definition: message.hpp:1224
static unsigned calc_chksum(const char *from, const size_t sz, const unsigned offset=0, const int len=-1)
Definition: message.hpp:1170
const size_t HEADER_CALC_OFFSET(32)
const F8MetaCntx & _ctx
Definition: message.hpp:392
virtual begin_string * get_begin_string()
Definition: message.hpp:1007
virtual check_sum * get_check_sum()
Definition: message.hpp:1019
const size_t _preamble_sz
Preamble length.
Definition: message.hpp:230
MessageBase * _trailer
Definition: message.hpp:1065
const unsigned short Common_BodyLength(9)
double AsDouble() const
Definition: timer.hpp:278
virtual msg_type * get_msg_type()
Definition: message.hpp:1015
const unsigned short Common_BeginString(8)
F8API size_t encode(std::ostream &to) const
Definition: message.cpp:373
An outbound message was missing a mandatory field.
const f8String & _msgType
Definition: message.hpp:391
MessageBase * _header
Definition: message.hpp:1065
High resolution interval timer.
Definition: timer.hpp:241
static Message* FIX8::Message::factory ( const F8MetaCntx ctx,
const char *  from,
bool  no_chksum = false,
bool  permissive_mode = false 
)
inlinestatic

Using supplied metatdata context and raw input buffer, decode and create appropriate Fix message

Parameters
ctxreference to metadata object
frompointer to raw buffer containing one complete FIX message string only, no trailing or leading characters
no_chksumif true, do not perform chksum verification
permissive_modeif true, ignore unknown fields
Returns
pointer to newly created Message (which will be a super class of the generated type)

Definition at line 1238 of file message.hpp.

Referenced by FIX8::Session::process(), and FIX8::Session::retrans_callback().

1239  {
1240  const f8String to(from);
1241  return factory(ctx, to, no_chksum, permissive_mode);
1242  }
const F8MetaCntx & ctx()
Compiler generated metadata object, accessed through this function.
static Message * factory(const F8MetaCntx &ctx, const char *from, bool no_chksum=false, bool permissive_mode=false)
Definition: message.hpp:1238
std::string f8String
Definition: f8types.hpp:47
Message * Message::factory ( const F8MetaCntx ctx,
const f8String from,
bool  no_chksum = false,
bool  permissive_mode = false 
)
static

Using supplied metatdata context and raw input buffer, decode and create appropriate Fix message

Parameters
ctxreference to metadata object
fromreference to string raw buffer containing one complete FIX message string only, no trailing or leading characters
no_chksumif true, do not perform chksum verification
permissive_modeif true, ignore unknown fields
Returns
pointer to newly created Message (which will be a super class of the generated type)

Definition at line 224 of file message.cpp.

References FIX8::F8MetaCntx::_bme, FIX8::IntervalTimer::AsDouble(), FIX8::IntervalTimer::Calculate(), FILE_LINE, FIX8::GeneratedTable< Key, Val >::find_ptr(), glout_debug, and FIX8::MAX_MSGTYPE_FIELD_LEN().

225 {
226  char mtype[MAX_MSGTYPE_FIELD_LEN] {}, len[MAX_MSGTYPE_FIELD_LEN] {};
227  const unsigned hlen(extract_header(from, len, mtype));
228 
229  if (!hlen)
230  {
231  glout_debug << "Message::factory throwing";
232  throw InvalidMessage(from, FILE_LINE);
233  }
234 
235  const unsigned mlen(fast_atoi<unsigned>(len));
236  const BaseMsgEntry *bme(ctx._bme.find_ptr(mtype));
237  if (!bme)
238  throw InvalidMessage(mtype, FILE_LINE);
239  Message *msg(bme->_create._do(false)); // shallow create
240 #if defined FIX8_CODECTIMING
241  IntervalTimer itm;
242 #endif
243  msg->decode(from, hlen, 7, permissive_mode); // skip already decoded mandatory 8, 9, 35 and 10
244 #if defined FIX8_CODECTIMING
245  _decode_timings._cpu_used += itm.Calculate().AsDouble();
246  ++_decode_timings._msg_count;
247 #endif
248 
249  msg->_header->get_body_length()->set(mlen);
250  msg->_header->get_msg_type()->set(mtype);
251 #if defined FIX8_POPULATE_METADATA
252  msg->check_set_rlm(fitr->second);
253 #endif
254 
255  const char *pp(from.data() + from.size() - 7); // FIXME: assumes supplied string is one complete message only
256  if (*pp != '1' || *(pp + 1) != '0') // 10=XXX^A
257  throw InvalidMessage(from, FILE_LINE);
258  if (!no_chksum) // permit chksum calculation to be skipped
259  {
260  const f8String chksum(pp + 3, 3);
261  msg->_trailer->get_check_sum()->set(chksum);
262  const unsigned chkval(fast_atoi<unsigned>(chksum.c_str())), mchkval(calc_chksum(from, 0, static_cast<unsigned>(from.size()) - 7));
263  if (chkval != mchkval)
264  throw BadCheckSum(mchkval);
265  }
266 
267  return msg;
268 }
const IntervalTimer & Calculate()
Definition: timer.hpp:262
const MsgTable & _bme
Framework generated lookup table to generate Fix messages.
Definition: message.hpp:216
const size_t MAX_MSGTYPE_FIELD_LEN(32)
An inbound message had an invalid (incorrect) checksum.
#define FILE_LINE
Definition: f8utils.hpp:68
Message instantiation table entry.
Definition: message.hpp:192
static unsigned calc_chksum(const char *from, const size_t sz, const unsigned offset=0, const int len=-1)
Definition: message.hpp:1170
#define glout_debug
Definition: logger.hpp:614
static unsigned extract_header(const f8String &from, char *len, char *mtype)
Definition: message.cpp:51
A complete Fix message with header, body and trailer.
Definition: message.hpp:1058
double AsDouble() const
Definition: timer.hpp:278
An invalid message was requested or decoded.
const Val * find_ptr(const Key &key) const
Definition: f8types.hpp:154
std::string f8String
Definition: f8types.hpp:47
High resolution interval timer.
Definition: timer.hpp:241
static f8String FIX8::Message::fmt_chksum ( const unsigned  val)
inlinestatic

Format a checksum into the required 3 digit, 0 padded string.

Parameters
valchecksum value
Returns
string containing formatted value

Definition at line 1224 of file message.hpp.

1225  {
1226  char buf[4] { '0', '0', '0', 0 };
1227  itoa<unsigned>(val, buf + (val > 99 ? 0 : val > 9 ? 1 : 2), 10);
1228  return f8String(buf);
1229  }
std::string f8String
Definition: f8types.hpp:47
unsigned FIX8::Message::get_custom_seqnum ( ) const
inline

Get the custom sequence number.

Returns
seqnum the outbound sequence number to use for this message.

Definition at line 1259 of file message.hpp.

References _custom_seqnum.

Referenced by FIX8::Session::send_process().

1259 { return _custom_seqnum; }
unsigned _custom_seqnum
Definition: message.hpp:1066
bool FIX8::Message::get_end_of_batch ( ) const
inline

Get the end of batch flag

Returns
true or false

Definition at line 1271 of file message.hpp.

References _end_of_batch.

1271 { return _end_of_batch; }
bool _end_of_batch
Definition: message.hpp:1067
BaseField* FIX8::Message::get_field_by_name_flattened ( const char *  tag) const
inline

Search for field by longname in this message (either header, body or trailer).

Parameters
tagfield longname
Returns
pointer to field or 0 if not found

Definition at line 1315 of file message.hpp.

References FIX8::MessageBase::_ctx, get_field_flattened(), and FIX8::F8MetaCntx::reverse_find_fnum().

1316  {
1318  }
BaseField * get_field_flattened(const unsigned short fnum) const
Definition: message.hpp:1304
const F8MetaCntx & _ctx
Definition: message.hpp:392
unsigned short reverse_find_fnum(const char *fieldstr) const
Definition: message.hpp:286
BaseField* FIX8::Message::get_field_flattened ( const unsigned short  fnum) const
inline

Search for field in this message (either header, body or trailer).

Parameters
fnumfield number
Returns
pointer to field or 0 if not found

Definition at line 1304 of file message.hpp.

References FIX8::MessageBase::_fields.

Referenced by get_field_by_name_flattened().

1305  {
1306  auto itr (_fields.find(fnum));
1307  return itr != _fields.end() ? itr->second
1308  : (itr = _header->_fields.find(fnum)) != _header->_fields.end() ? itr->second
1309  : (itr = _trailer->_fields.find(fnum)) != _trailer->_fields.end() ? itr->second : nullptr;
1310  }
MessageBase * _trailer
Definition: message.hpp:1065
MessageBase * _header
Definition: message.hpp:1065
virtual bool FIX8::Message::get_no_increment ( ) const
inlinevirtual

Get the no increment flag.

Returns
value of _no_increment flag

Definition at line 1267 of file message.hpp.

References _no_increment.

1267 { return _no_increment; }
bool _no_increment
Definition: message.hpp:1067
MessageBase* FIX8::Message::Header ( ) const
inline

Get a pointer to the message header.

Returns
pointer to header

Definition at line 1098 of file message.hpp.

References _header.

Referenced by FIX8::Session::compid_check(), FIX8::Session::handle_logon(), MyMenu::load_msgs(), FIX8::Session::send_process(), and FIX8::Session::sequence_check().

1098 { return _header; }
MessageBase * _header
Definition: message.hpp:1065
MessageBase* FIX8::Message::Header ( )
inline

Get a pointer to the message header, non const version.

Returns
pointer to header

Definition at line 1106 of file message.hpp.

References _header.

1106 { return _header; }
MessageBase * _header
Definition: message.hpp:1065
virtual bool FIX8::Message::is_admin ( ) const
inlinevirtual
void Message::print ( std::ostream &  os,
int  depth = 0 
) const
virtual

Print the message to the specified stream.

Parameters
osrefererence to stream to print to
depthnot used

Reimplemented from FIX8::MessageBase.

Definition at line 680 of file message.cpp.

References FIX8::MessageBase::print().

681 {
682  if (_header)
683  os << *_header;
684  else
685  os << "Null Header" << endl;
686  MessageBase::print(os);
687  if (_trailer)
688  os << *_trailer;
689  else
690  os << "Null Trailer" << endl;
691 }
MessageBase * _trailer
Definition: message.hpp:1065
virtual F8API void print(std::ostream &os, int depth=0) const
Definition: message.cpp:509
MessageBase * _header
Definition: message.hpp:1065
virtual bool FIX8::Message::process ( Router rt) const
inlinevirtual

Initiate callback to appropriate process method from metadata.

Parameters
rtreference to router instance
Returns
true if correctly processed

Reimplemented in FIX8::TEX::DerivativeSecurityListRequest, FIX8::TEX::SecurityList, FIX8::TEX::SecurityListRequest, FIX8::TEX::SecurityTypes, FIX8::TEX::SecurityTypeRequest, FIX8::TEX::CrossOrderCancelRequest, FIX8::TEX::CrossOrderCancelReplaceRequest, FIX8::TEX::NewOrderCross, FIX8::TEX::OrderMassCancelReport, FIX8::TEX::OrderMassCancelRequest, FIX8::TEX::RegistrationInstructionsResponse, FIX8::TEX::RegistrationInstructions, FIX8::TEX::ListStrikePrice, FIX8::TEX::BidResponse, FIX8::TEX::BidRequest, FIX8::TEX::BusinessMessageReject, FIX8::TEX::MassQuote, FIX8::TEX::TradingSessionStatus, FIX8::TEX::TradingSessionStatusRequest, FIX8::TEX::SecurityStatus, FIX8::TEX::SecurityStatusRequest, FIX8::TEX::SecurityDefinition, FIX8::TEX::SecurityDefinitionRequest, FIX8::TEX::MassQuoteAcknowledgement, FIX8::TEX::QuoteStatusRequest, FIX8::TEX::QuoteCancel, FIX8::TEX::MarketDataRequestReject, FIX8::TEX::MarketDataIncrementalRefresh, FIX8::TEX::MarketDataSnapshotFullRefresh, FIX8::TEX::MarketDataRequest, FIX8::TEX::SettlementInstructions, FIX8::TEX::Quote, FIX8::TEX::QuoteRequest, FIX8::TEX::DontKnowTrade, FIX8::TEX::AllocationInstructionAck, FIX8::TEX::ListStatus, FIX8::TEX::ListStatusRequest, FIX8::TEX::ListExecute, FIX8::TEX::ListCancelRequest, FIX8::TEX::AllocationInstruction, FIX8::TEX::OrderStatusRequest, FIX8::TEX::OrderCancelReplaceRequest, FIX8::TEX::OrderCancelRequest, FIX8::TEX::NewOrderList, FIX8::TEX::NewOrderSingle, FIX8::TEX::PartyDetailsListReport, FIX8::TEX::PartyDetailsListRequest, FIX8::TEX::StreamAssignmentReportACK, FIX8::TEX::StreamAssignmentReport, FIX8::TEX::StreamAssignmentRequest, FIX8::TEX::UserNotification, FIX8::TEX::OrderMassActionRequest, FIX8::TEX::Email, FIX8::TEX::OrderMassActionReport, FIX8::TEX::ApplicationMessageReport, FIX8::TEX::ApplicationMessageRequestAck, FIX8::TEX::ApplicationMessageRequest, FIX8::TEX::MarketDefinitionUpdateReport, FIX8::TEX::MarketDefinition, FIX8::TEX::MarketDefinitionRequest, FIX8::TEX::TradingSessionListUpdateReport, FIX8::TEX::DerivativeSecurityListUpdateReport, FIX8::TEX::SettlementObligationReport, FIX8::TEX::SecurityDefinitionUpdateReport, FIX8::TEX::ContraryIntentionReport, FIX8::TEX::ExecutionAcknowledgement, FIX8::TEX::AllocationInstructionAlert, FIX8::TEX::AdjustedPositionReport, FIX8::TEX::SecurityListUpdateReport, FIX8::TEX::TradingSessionList, FIX8::TEX::TradingSessionListRequest, FIX8::TEX::ConfirmationRequest, FIX8::TEX::CollateralInquiryAck, FIX8::TEX::UserResponse, FIX8::TEX::UserRequest, FIX8::TEX::NetworkCounterpartySystemStatusResponse, FIX8::TEX::NetworkCounterpartySystemStatusRequest, FIX8::TEX::CollateralInquiry, FIX8::TEX::CollateralReport, FIX8::TEX::News, FIX8::TEX::CollateralResponse, FIX8::TEX::CollateralAssignment, FIX8::TEX::CollateralRequest, FIX8::TEX::AssignmentReport, FIX8::TEX::SettlementInstructionRequest, FIX8::TEX::ConfirmationAck, FIX8::TEX::AllocationReportAck, FIX8::TEX::AllocationReport, FIX8::TEX::TradeCaptureReportAck, FIX8::TEX::TradeCaptureReportRequestAck, FIX8::TEX::PositionReport, FIX8::TEX::RequestForPositionsAck, FIX8::TEX::RequestForPositions, FIX8::TEX::PositionMaintenanceReport, FIX8::TEX::PositionMaintenanceRequest, FIX8::TEX::Confirmation, FIX8::TEX::QuoteResponse, FIX8::TEX::QuoteStatusReport, FIX8::TEX::RFQRequest, FIX8::TEX::QuoteRequestReject, FIX8::TEX::OrderMassStatusRequest, FIX8::TEX::TradeCaptureReport, FIX8::TEX::TradeCaptureReportRequest, FIX8::TEX::MultilegOrderCancelReplace, FIX8::TEX::NewOrderMultileg, FIX8::TEX::DerivativeSecurityList, FIX8::TEX::Logon, FIX8::TEX::OrderCancelReject, FIX8::TEX::ExecutionReport, FIX8::TEX::Advertisement, FIX8::TEX::NewOrderSingle, FIX8::TEX::Logon, FIX8::TEX::IOI, FIX8::TEX::ExecutionReport, FIX8::TEX::Logout, FIX8::TEX::Logout, FIX8::TEX::SequenceReset, FIX8::TEX::SequenceReset, FIX8::TEX::Reject, FIX8::TEX::Reject, FIX8::TEX::ResendRequest, FIX8::TEX::ResendRequest, FIX8::TEX::TestRequest, FIX8::TEX::TestRequest, FIX8::TEX::Heartbeat, and FIX8::TEX::Heartbeat.

Definition at line 1147 of file message.hpp.

Referenced by myfix_session_client::handle_application(), hf_session_client::handle_application(), myfix_session_server::handle_application(), and hf_session_server::handle_application().

1147 { return (rt)(this); }
void FIX8::Message::push_unknown ( Message to) const
inline

Copy _unknown string from this message to given message

Definition at line 1292 of file message.hpp.

References _header, _trailer, and FIX8::MessageBase::push_unknown().

1293  {
1294  if (_header)
1295  _header->push_unknown(to->_header);
1297  if (_trailer)
1298  _trailer->push_unknown(to->_trailer);
1299  }
void push_unknown(MessageBase *to) const
Definition: message.hpp:518
MessageBase * _trailer
Definition: message.hpp:1065
MessageBase * _header
Definition: message.hpp:1065
virtual void FIX8::Message::set_custom_seqnum ( unsigned  seqnum)
inlinevirtual

Set the custom sequence number. Used to override and suppress automatic seqnum assignment.

Parameters
seqnumthe outbound sequence number to use for this message.

Definition at line 1255 of file message.hpp.

Referenced by FIX8::Session::send().

1255 { _custom_seqnum = seqnum; }
unsigned _custom_seqnum
Definition: message.hpp:1066
void FIX8::Message::set_end_of_batch ( bool  is_end_of_batch)
inline

Set the end of batch flag

Parameters
is_end_of_batchtrue or false

Definition at line 1275 of file message.hpp.

Referenced by FIX8::FIXWriter::write_batch().

1275 { _end_of_batch = is_end_of_batch; }
bool _end_of_batch
Definition: message.hpp:1067
virtual void FIX8::Message::set_no_increment ( bool  flag = true)
inlinevirtual

Set the no increment flag.

Parameters
flagtrue means don't increment the seqnum after sending

Definition at line 1263 of file message.hpp.

Referenced by FIX8::Session::send().

1263 { _no_increment = flag; }
bool _no_increment
Definition: message.hpp:1067
void FIX8::Message::setup_reuse ( )
inline

Setup this message to allow it to be resused This feature is experimental; do not use with pipelined mode

Definition at line 1279 of file message.hpp.

References FIX8::MessageBase::_fp, FIX8::Common_BeginString(), FIX8::Common_BodyLength(), FIX8::Common_CheckSum(), FIX8::Common_MsgSeqNum(), FIX8::MessageBase::remove(), FIX8::FieldTraits::set(), and FIX8::FieldTrait::suppress.

Referenced by MyMenu::load_msgs(), and MyMenu::new_order_single_recycled().

1280  {
1281  if (_header)
1282  {
1285  delete _header->remove(Common_MsgSeqNum);
1286  }
1287  if (_trailer)
1289  }
FieldTraits _fp
Definition: message.hpp:388
const unsigned short Common_CheckSum(10)
F8API BaseField * remove(const unsigned short fnum, Presence::const_iterator itr)
Definition: message.cpp:646
MessageBase * _trailer
Definition: message.hpp:1065
const unsigned short Common_MsgSeqNum(34)
const unsigned short Common_BodyLength(9)
const unsigned short Common_BeginString(8)
MessageBase * _header
Definition: message.hpp:1065
void set(const unsigned short field, Presence::const_iterator &itr, FieldTrait::TraitTypes type)
Definition: traits.hpp:524
MessageBase* FIX8::Message::Trailer ( ) const
inline

Get a pointer to the message trailer.

Returns
pointer to trailer

Definition at line 1102 of file message.hpp.

References _trailer.

1102 { return _trailer; }
MessageBase * _trailer
Definition: message.hpp:1065
MessageBase* FIX8::Message::Trailer ( )
inline

Get a pointer to the message trailer, non const version.

Returns
pointer to trailer

Definition at line 1110 of file message.hpp.

References _trailer.

1110 { return _trailer; }
MessageBase * _trailer
Definition: message.hpp:1065

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const Message what 
)
friend

Inserter friend.

Parameters
osstream to send to
whatmessage
Returns
stream

Definition at line 1364 of file message.hpp.

1364 { what.print(os); return os; }

Member Data Documentation

unsigned FIX8::Message::_custom_seqnum
protected

Definition at line 1066 of file message.hpp.

Referenced by get_custom_seqnum().

bool FIX8::Message::_end_of_batch
protected

Definition at line 1067 of file message.hpp.

Referenced by get_end_of_batch().

MessageBase* FIX8::Message::_header
protected

Definition at line 1065 of file message.hpp.

Referenced by Header(), push_unknown(), and ~Message().

bool FIX8::Message::_no_increment
protected

Definition at line 1067 of file message.hpp.

Referenced by get_no_increment().

MessageBase * FIX8::Message::_trailer
protected

Definition at line 1065 of file message.hpp.

Referenced by push_unknown(), Trailer(), and ~Message().


The documentation for this class was generated from the following files: