OnixS C++ B3 BOE Binary Order Entry 1.3.0
API Documentation
Loading...
Searching...
No Matches
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
31{
32public:
36 , size_(0)
37 {}
38
42 , size_(0)
43 {
44 assert(size >= sizeof(SimpleOpenFramingHeader));
45
46 const SimpleOpenFramingHeader* const header = reinterpret_cast<const SimpleOpenFramingHeader*>(data);
47
48 assert(header->encoding() == B3BOESbeEncodingType);
49 assert(header->size() <= size);
50
51#ifndef NDEBUG
52 SbeMessage(toByteBlock(toMutable(data)) + sizeof(SimpleOpenFramingHeader), header->size() - sizeof(SimpleOpenFramingHeader));
53#endif
54
55 data_ = data;
56 size_ = header->size();
57 }
58
60 NetworkMessage(const void* data, size_t size)
62 , size_(0)
63 {
64 if ONIXS_B3_BOE_UNLIKELY(size < sizeof(SimpleOpenFramingHeader))
65 throwBinaryBlockIsTooSmall(static_cast<MessageSize>(size), sizeof(SimpleOpenFramingHeader), "SimpleOpenFramingHeader");
66
67 const SimpleOpenFramingHeader* const header = reinterpret_cast<const SimpleOpenFramingHeader*>(data);
68
69 if ONIXS_B3_BOE_UNLIKELY(header->encoding() != B3BOESbeEncodingType)
70 throwIncorrectEncoding(header->encoding(), data, static_cast<MessageSize>(size));
71
72 if ONIXS_B3_BOE_UNLIKELY(header->size() > size)
73 throwNetPacketIsTooSmall(static_cast<MessageSize>(size), header->size());
74
75 SbeMessage(toByteBlock(toMutable(data)) + sizeof(SimpleOpenFramingHeader), header->size() - sizeof(SimpleOpenFramingHeader));
76
77 data_ = data;
78 size_ = header->size();
79 }
80
82 const void* data() const ONIXS_B3_BOE_NOTHROW
83 {
84 return data_;
85 }
86
89 {
90 return size_;
91 }
92
95 {
96 *this = NetworkMessage();
97 assert(!valid());
98 }
99
101
103 {
104 return (ONIXS_B3_BOE_NULLPTR != data_);
105 }
106
108
110 {
111 assert(valid());
112
113#ifndef NDEBUG
114 SbeMessage(toByteBlock(toMutable(data_)) + sizeof(SimpleOpenFramingHeader), size_ - sizeof(SimpleOpenFramingHeader));
115#endif
116
117 return SbeMessage(
118 toByteBlock(toMutable(data_)) + sizeof(SimpleOpenFramingHeader),
120 }
121
122private:
123 const void* data_;
124 MessageSize size_;
125};
126
129void toStr(std::string&, const NetworkMessage&);
130
131inline
132std::string toStr(const NetworkMessage& message)
133{
134 std::string res;
135 toStr(res, message);
136 return res;
137}
138
#define ONIXS_B3_BOE_MESSAGING_NAMESPACE_END
Definition ABI.h:144
#define ONIXS_B3_BOE_MESSAGING_NAMESPACE_BEGIN
Definition ABI.h:140
#define ONIXS_B3_BOE_LTWT_CLASS
Definition ABI.h:84
#define ONIXS_B3_BOE_UNUSED
Definition Compiler.h:207
#define ONIXS_B3_BOE_NULLPTR
Definition Compiler.h:188
#define ONIXS_B3_BOE_EXPORTED
Definition Compiler.h:181
#define ONIXS_B3_BOE_NOTHROW
Definition Compiler.h:182
void clear() noexcept
Blank the instance.
NetworkMessage(const void *data, size_t size, SbeMessage::NoCheck) noexcept
Constructs NetworkMessage from a data block. Performs no checks.
NetworkMessage(const void *data, size_t size)
Constructs NetworkMessage from a data block.
NetworkMessage() noexcept
Constructs an empty instance.
const void * data() const noexcept
MessageSize size() const noexcept
SbeMessage message() const noexcept
Retrieves the underlying SBE message.
std::string toStr(const FixedPointDecimal< Mantissa, Exponent > &)
Serializes a fixed-point decimal into a string.
UInt16 MessageSize
Message length type.
Definition Aliases.h:29