OnixS C++ CME iLink 3 Binary Order Entry Handler  1.18.9
API Documentation
NetworkMessage.h
Go to the documentation of this file.
1 // Copyright Onix Solutions Limited [OnixS]. All rights reserved.
2 //
3 // This software owned by Onix Solutions Limited [OnixS] and is
4 // protected by copyright law and international copyright treaties.
5 //
6 // Access to and use of the software is governed by the terms of the applicable
7 // OnixS Software Services Agreement (the Agreement) and Customer end user license
8 // agreements granting a non-assignable, non-transferable and non-exclusive license
9 // to use the software for it's own data processing purposes under the terms defined
10 // in the Agreement.
11 //
12 // Except as otherwise granted within the terms of the Agreement, copying or
13 // reproduction of any part of this source code or associated reference material
14 // to any other location for further reproduction or redistribution, and any
15 // amendments to this copyright notice, are expressly prohibited.
16 //
17 // Any reproduction or redistribution for sale or hiring of the Software not in
18 // accordance with the terms of the Agreement is a violation of copyright law.
19 //
20 
21 #pragma once
22 
26 
28 
29 /// A network iLink3 message.
30 
31 /// https://www.cmegroup.com/confluence/display/EPICSANDBOX/iLink+3+-+Simple+Binary+Encoding
33 {
34 public:
35  /// Constructs an empty instance.
37  : data_(ONIXS_ILINK3_NULLPTR)
38  , size_(0)
39  {}
40 
41  /// Constructs NetworkMessage from a data block. Performs no checks.
43  : data_(ONIXS_ILINK3_NULLPTR)
44  , size_(0)
45  {
46  assert(size >= sizeof(SimpleOpenFramingHeader));
47 
48  const SimpleOpenFramingHeader* const header = reinterpret_cast<const SimpleOpenFramingHeader*>(data);
49 
50  assert(header->encoding() == CmeSbeEncodingType);
51  assert(header->size() <= size);
52 
53 #ifndef NDEBUG
54  SbeMessage(toByteBlock(toMutable(data)) + sizeof(SimpleOpenFramingHeader), header->size() - sizeof(SimpleOpenFramingHeader));
55 #endif
56 
57  data_ = data;
58  size_ = header->size();
59  }
60 
61  /// Constructs NetworkMessage from a data block.
62  NetworkMessage(const void* data, size_t size)
63  : data_(ONIXS_ILINK3_NULLPTR)
64  , size_(0)
65  {
66  if ONIXS_ILINK3_UNLIKELY(size < sizeof(SimpleOpenFramingHeader))
67  throwBinaryBlockIsTooSmall(static_cast<MessageSize>(size), sizeof(SimpleOpenFramingHeader), "SimpleOpenFramingHeader");
68 
69  const SimpleOpenFramingHeader* const header = reinterpret_cast<const SimpleOpenFramingHeader*>(data);
70 
71  if ONIXS_ILINK3_UNLIKELY(header->encoding() != CmeSbeEncodingType)
72  throwIncorrectEncoding(header->encoding(), data, static_cast<MessageSize>(size));
73 
74  if ONIXS_ILINK3_UNLIKELY(header->size() > size)
75  throwNetPacketIsTooSmall(static_cast<MessageSize>(size), header->size());
76 
77  SbeMessage(toByteBlock(toMutable(data)) + sizeof(SimpleOpenFramingHeader), header->size() - sizeof(SimpleOpenFramingHeader));
78 
79  data_ = data;
80  size_ = header->size();
81  }
82 
83  ///
84  const void* data() const ONIXS_ILINK3_NOTHROW
85  {
86  return data_;
87  }
88 
89  ///
91  {
92  return size_;
93  }
94 
95  /// Blank the instance.
97  {
98  *this = NetworkMessage();
99  assert(!valid());
100  }
101 
102  /// \return `true` if the instance refers to a valid packet, otherwise - `false`.
103 
105  {
106  return (ONIXS_ILINK3_NULLPTR != data_);
107  }
108 
109  /// Retrieves the underlying SBE message.
110 
112  {
113  assert(valid());
114 
115 #ifndef NDEBUG
116  SbeMessage(toByteBlock(toMutable(data_)) + sizeof(SimpleOpenFramingHeader), size_ - sizeof(SimpleOpenFramingHeader));
117 #endif
118 
119  return SbeMessage(
120  toByteBlock(toMutable(data_)) + sizeof(SimpleOpenFramingHeader),
121  size_ - sizeof(SimpleOpenFramingHeader), SbeMessage::NoCheck());
122  }
123 
124 private:
125  const void* data_;
126  MessageSize size_;
127 };
128 
129 /// Serializes into a string.
131 void toStr(std::string&, const NetworkMessage&);
132 
133 inline
134 std::string toStr(const NetworkMessage& message)
135 {
136  std::string res;
137  toStr(res, message);
138  return res;
139 }
140 
#define ONIXS_ILINK3_NULLPTR
Definition: Compiler.h:182
std::string toStr(const NetworkMessage &message)
NetworkMessage() noexcept
Constructs an empty instance.
#define ONIXS_ILINK3_LTWT_CLASS
Definition: ABI.h:84
NetworkMessage(const void *data, size_t size, SbeMessage::NoCheck) noexcept
Constructs NetworkMessage from a data block. Performs no checks.
#define ONIXS_ILINK3_MESSAGING_NAMESPACE_END
Definition: ABI.h:144
#define ONIXS_ILINK3_EXPORTED
Definition: Compiler.h:175
UInt16 MessageSize
Message length type.
Definition: Aliases.h:29
NetworkMessage(const void *data, size_t size)
Constructs NetworkMessage from a data block.
#define ONIXS_ILINK3_MESSAGING_NAMESPACE_BEGIN
Definition: ABI.h:140
#define ONIXS_ILINK3_UNUSED
Definition: Compiler.h:201
SbeMessage message() const noexcept
Retrieves the underlying SBE message.
#define ONIXS_ILINK3_NOTHROW
Definition: Compiler.h:176
void clear() noexcept
Blank the instance.