OnixS C++ CME MDP Conflated TCP Handler  1.2.1
API Documentation
MaxMessageSize.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 
25 
29 
31 
33 
34 /// Maximum supported message size.
36 
37 #if defined(ONIXS_CONFLATEDTCP_COMPILER_CXX_CONSTEXPR) && ONIXS_CONFLATEDTCP_COMPILER_CXX_CONSTEXPR
38 
39 /// \private
40 template <typename Message>
41 struct MaxMessageSizeTraits
42 {
43  static constexpr bool UseCustomValue = false;
44 };
45 
46 /// Calculates the buffer size for a message with the given number of repeating group items.
47 template<typename Message>
48 constexpr
49 MessageSize calculateMaxMessageSize(UInt8 maxGroupItems)
50 {
51  return
52  ONIXS_CONFLATEDTCP_ASSERT(Message::getMaxMessageSize(maxGroupItems) <= MaxConflatedTcpMessageSize),
53  static_cast<MessageSize>(Message::getMaxMessageSize(maxGroupItems));
54 }
55 
56 /// Calculates the buffer size for a message with the given number of repeating group items.
57 template<typename Message>
58 constexpr
59 typename std::enable_if<MaxMessageSizeTraits<Message>::UseCustomValue, MessageSize>::type
60 getMaxMessageSize(UInt8)
61 {
62  return
63  MaxMessageSizeTraits<Message>::calculateMaxMessageSize();
64 }
65 
66 /// Calculates the buffer size for a message with the given number of repeating group items.
67 template<typename Message>
68 constexpr
69 typename std::enable_if<!MaxMessageSizeTraits<Message>::UseCustomValue, MessageSize>::type
70 getMaxMessageSize(UInt8 maxGroupItems)
71 {
72  return calculateMaxMessageSize<Message>(maxGroupItems);
73 }
74 
75 /// \private
76 template<typename Message, UInt8 MaxGroupItems>
77 struct GetMaxMessageSize
78 {
79  enum {Size = getMaxMessageSize<Message>(MaxGroupItems)};
80 };
81 
82 /// \private
83 template<typename Message>
84 constexpr
85 UInt16 getMinMessageSize()
86 {
87  return
88  Message::blockLength(Message::Schema::Version)
89  + MessageHeader::Size
90  + Message::getMinimalVariableFieldsSize(Message::Schema::Version);
91 }
92 
93 /// \private
94 template<typename Message>
95 struct GetMinMessageSize
96 {
97  enum {Size = getMinMessageSize<Message>()};
98 };
99 
100 #else
101 
102 /// \private
103 template<typename Message, UInt8>
104 struct GetMaxMessageSize
105 {
106  enum {Size = MaxConflatedTcpMessageSize};
107 };
108 
109 /// \private
110 template<typename Message>
111 struct GetMinMessageSize
112 {
113  enum {Size = sizeof(SimpleOpenFramingHeader) + sizeof(MessageHeader) + 1};
114 };
115 
116 #endif
117 
#define ONIXS_CONFLATEDTCP_MESSAGING_NAMESPACE_END
Definition: ABI.h:144
Template ID and length of message root.
Definition: Composites.h:144
#define ONIXS_CONFLATEDTCP_CONST_OR_CONSTEXPR
Definition: Compiler.h:191
constexpr UInt16 MaxConflatedTcpMessageSize
Maximum supported message size.
UInt16 MessageSize
Message length type.
Definition: Aliases.h:29
#define ONIXS_CONFLATEDTCP_MESSAGING_NAMESPACE_BEGIN
Definition: ABI.h:140