OnixS C++ CME iLink 3 Binary Order Entry Handler  1.18.0
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 
23 #include <OnixS/CME/iLink3/ABI.h>
25 
29 
31 
33 
34 /// Maximum supported message size.
36 
37 #if defined(ONIXS_ILINK3_CXX11)
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
50 {
51  return
52  ONIXS_ILINK3_ASSERT(Message::getMaxMessageSize(maxGroupItems) <= MaxILink3MessageSize),
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
61 {
62  return
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 = MaxILink3MessageSize};
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 
constexpr MessageSize calculateMaxMessageSize(UInt8 maxGroupItems)
Calculates the buffer size for a message with the given number of repeating group items...
#define ONIXS_ILINK3_CONST_OR_CONSTEXPR
Definition: Compiler.h:178
Template ID and length of message root.
Definition: Composites.h:204
UInt16 UInt16
uInt16.
Definition: Fields.h:296
#define ONIXS_ILINK3_MESSAGING_NAMESPACE_END
Definition: ABI.h:144
constexpr std::enable_if<!MaxMessageSizeTraits< Message >::UseCustomValue, MessageSize >::type getMaxMessageSize(UInt8 maxGroupItems)
Calculates the buffer size for a message with the given number of repeating group items...
UInt16 MessageSize
Message length type.
Definition: Aliases.h:29
constexpr UInt16 MaxILink3MessageSize
Maximum supported message size.
#define ONIXS_ILINK3_MESSAGING_NAMESPACE_BEGIN
Definition: ABI.h:140