libbmq  a5f8a06ba1d16cb5a65643e1fa7f1a1d6aadef40
bmqa_messageproperties.h
Go to the documentation of this file.
1 // Copyright 2016-2023 Bloomberg Finance L.P.
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 // bmqa_messageproperties.h -*-C++-*-
17 #ifndef INCLUDED_BMQA_MESSAGEPROPERTIES
18 #define INCLUDED_BMQA_MESSAGEPROPERTIES
19 
59 
60 // BMQ
61 
62 #include <bmqt_propertytype.h>
63 #include <bmqt_resultcode.h>
64 
65 // BDE
66 #include <bdlbb_blob.h>
67 #include <bsl_cstdint.h>
68 #include <bsl_string.h>
69 #include <bslma_allocator.h>
70 #include <bslma_usesbslmaallocator.h>
71 #include <bslmf_nestedtraitdeclaration.h>
72 #include <bsls_alignedbuffer.h>
73 #include <bsls_types.h>
74 
75 namespace BloombergLP {
76 
77 // FORWARD DECLARATION
78 namespace bmqp {
79 class MessageProperties;
80 }
81 namespace bmqp {
82 class MessagePropertiesIterator;
83 }
84 
85 namespace bmqa {
86 
87 // =======================
88 // class MessageProperties
89 // =======================
90 
93  // FRIENDS
95 
96  private:
97  // PRIVATE CONSTANTS
98 
102  static const int k_MAX_SIZEOF_BMQP_MESSAGEPROPERTIES = 184;
103 
104  // PRIVATE TYPES
105  typedef bsls::AlignedBuffer<k_MAX_SIZEOF_BMQP_MESSAGEPROPERTIES>
106  ImplBuffer;
107 
108  private:
109  // DATA
110 
115  mutable bmqp::MessageProperties* d_impl_p;
116 
118  ImplBuffer d_buffer;
119 
120  bslma::Allocator* d_allocator_p;
121 
122  public:
123  // PUBLIC CONSTANTS
124 
126  static const int k_MAX_NUM_PROPERTIES = 255;
127 
131  static const int k_MAX_PROPERTIES_AREA_LENGTH = (64 * 1024 * 1024) - 8;
132 
134  static const int k_MAX_PROPERTY_NAME_LENGTH = 4095;
135 
141  static const int k_MAX_PROPERTY_VALUE_LENGTH = 67104745;
142 
143  public:
144  // TRAITS
145  BSLMF_NESTED_TRAIT_DECLARATION(MessageProperties,
146  bslma::UsesBslmaAllocator)
147 
148  // CREATORS
149 
150 
155  explicit MessageProperties(bslma::Allocator* basicAllocator = 0);
156 
161  bslma::Allocator* basicAllocator = 0);
162 
165 
166  // MANIPULATORS
167 
169  MessageProperties& operator=(const MessageProperties& rhs);
170 
175  bool remove(const bsl::string& name, bmqt::PropertyType::Enum* buffer = 0);
176 
179  void clear();
180 
181  int setPropertyAsBool(const bsl::string& name, bool value);
182  int setPropertyAsChar(const bsl::string& name, char value);
183  int setPropertyAsShort(const bsl::string& name, short value);
184  int setPropertyAsInt32(const bsl::string& name, bsl::int32_t value);
185  int setPropertyAsInt64(const bsl::string& name, bsls::Types::Int64 value);
186  int setPropertyAsString(const bsl::string& name, const bsl::string& value);
187 
194  int setPropertyAsBinary(const bsl::string& name,
195  const bsl::vector<char>& value);
196 
200  int streamIn(const bdlbb::Blob& blob);
201 
202  // ACCESSORS
203 
205  int numProperties() const;
206 
210  int totalSize() const;
211 
215  bool hasProperty(const bsl::string& name,
216  bmqt::PropertyType::Enum* type = 0) const;
217 
221  bmqt::PropertyType::Enum propertyType(const bsl::string& name) const;
222 
223  bool getPropertyAsBool(const bsl::string& name) const;
224  char getPropertyAsChar(const bsl::string& name) const;
225  short getPropertyAsShort(const bsl::string& name) const;
226  bsl::int32_t getPropertyAsInt32(const bsl::string& name) const;
227  bsls::Types::Int64 getPropertyAsInt64(const bsl::string& name) const;
228  const bsl::string& getPropertyAsString(const bsl::string& name) const;
229 
232  const bsl::vector<char>&
233  getPropertyAsBinary(const bsl::string& name) const;
234 
235  bool getPropertyAsBoolOr(const bsl::string& name, bool value) const;
236  char getPropertyAsCharOr(const bsl::string& name, char value) const;
237  short getPropertyAsShortOr(const bsl::string& name, short value) const;
238  bsl::int32_t getPropertyAsInt32Or(const bsl::string& name,
239  bsl::int32_t value) const;
240  bsls::Types::Int64 getPropertyAsInt64Or(const bsl::string& name,
241  bsls::Types::Int64 value) const;
242  const bsl::string& getPropertyAsStringOr(const bsl::string& name,
243  const bsl::string& value) const;
244 
248  const bsl::vector<char>&
249  getPropertyAsBinaryOr(const bsl::string& name,
250  const bsl::vector<char>& value) const;
251 
258  const bdlbb::Blob&
259  streamOut(bdlbb::BlobBufferFactory* bufferFactory) const;
260 
270  bsl::ostream&
271  print(bsl::ostream& stream, int level = 0, int spacesPerLevel = 4) const;
272 };
273 
274 // FREE OPERATORS
275 
278 bsl::ostream& operator<<(bsl::ostream& stream, const MessageProperties& rhs);
279 
280 // ===============================
281 // class MessagePropertiesIterator
282 // ===============================
283 
291  private:
292  // PRIVATE CONSTANTS
293 
294  // Constant representing the maximum size of a
295  // `bmqp::MessagePropertiesIterator` object, so that the below
296  // AlignedBuffer is big enough.
297  static const int k_MAX_SIZEOF_BMQP_MESSAGEPROPERTIESITER = 64;
298 
299  // PRIVATE TYPES
300  typedef bsls::AlignedBuffer<k_MAX_SIZEOF_BMQP_MESSAGEPROPERTIESITER>
301  ImplBuffer;
302 
303  private:
304  // DATA
305  mutable bmqp::MessagePropertiesIterator* d_impl_p;
306  // Pointer to the implementation object
307  // in 'd_buffer'. This variable *must*
308  // *be* the first member of this class.
309  // If the value is null, the object
310  // has not been constructed in the
311  // 'd_buffer'.
312 
313  ImplBuffer d_buffer;
314  // Buffer containing the implementation
315  // object
316 
317  public:
318  // CREATORS
319 
324 
327  explicit MessagePropertiesIterator(const MessageProperties* properties);
328 
331 
334 
335  // MANIPULATORS
336 
339 
346  bool hasNext();
347 
348  // ACCESSORS
349 
353  const bsl::string& name() const;
354 
358 
359  bool getAsBool() const;
360  char getAsChar() const;
361  short getAsShort() const;
362  bsl::int32_t getAsInt32() const;
363  bsls::Types::Int64 getAsInt64() const;
364  const bsl::string& getAsString() const;
365 
370  const bsl::vector<char>& getAsBinary() const;
371 };
372 
373 } // close package namespace
374 
375 // ============================================================================
376 // INLINE DEFINITIONS
377 // ============================================================================
378 
379 // -----------------------
380 // class MessageProperties
381 // -----------------------
382 
383 inline bsl::ostream& bmqa::operator<<(bsl::ostream& stream,
384  const bmqa::MessageProperties& rhs)
385 {
386  return rhs.print(stream, 0, -1);
387 }
388 
389 } // close enterprise namespace
390 
391 #endif
Provide enum for the supported data types for a message property.
Provide enums for various publicly exposed result code.
Definition: bmqa_messageproperties.h:290
MessagePropertiesIterator & operator=(const MessagePropertiesIterator &rhs)
Assignment operator from the specified rhs.
bmqt::PropertyType::Enum type() const
~MessagePropertiesIterator()
Destroy this iterator.
const bsl::vector< char > & getAsBinary() const
MessagePropertiesIterator(const MessagePropertiesIterator &other)
Copy constructor from the specified other.
const bsl::string & getAsString() const
MessagePropertiesIterator(const MessageProperties *properties)
Provide a VST representing message properties.
Definition: bmqa_messageproperties.h:92
bmqt::PropertyType::Enum propertyType(const bsl::string &name) const
static const int k_MAX_PROPERTY_VALUE_LENGTH
Definition: bmqa_messageproperties.h:141
bool getPropertyAsBool(const bsl::string &name) const
int setPropertyAsShort(const bsl::string &name, short value)
bsls::Types::Int64 getPropertyAsInt64Or(const bsl::string &name, bsls::Types::Int64 value) const
bsls::Types::Int64 getPropertyAsInt64(const bsl::string &name) const
bsl::int32_t getPropertyAsInt32(const bsl::string &name) const
const bsl::string & getPropertyAsString(const bsl::string &name) const
const bsl::string & getPropertyAsStringOr(const bsl::string &name, const bsl::string &value) const
bool remove(const bsl::string &name, bmqt::PropertyType::Enum *buffer=0)
int setPropertyAsString(const bsl::string &name, const bsl::string &value)
int setPropertyAsInt64(const bsl::string &name, bsls::Types::Int64 value)
short getPropertyAsShortOr(const bsl::string &name, short value) const
char getPropertyAsCharOr(const bsl::string &name, char value) const
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
static const int k_MAX_PROPERTIES_AREA_LENGTH
Definition: bmqa_messageproperties.h:131
short getPropertyAsShort(const bsl::string &name) const
bool hasProperty(const bsl::string &name, bmqt::PropertyType::Enum *type=0) const
char getPropertyAsChar(const bsl::string &name) const
int setPropertyAsBinary(const bsl::string &name, const bsl::vector< char > &value)
const bsl::vector< char > & getPropertyAsBinary(const bsl::string &name) const
int setPropertyAsChar(const bsl::string &name, char value)
int numProperties() const
Return the total number of properties set in this instance.
static const int k_MAX_PROPERTY_NAME_LENGTH
Maximum length of a property name.
Definition: bmqa_messageproperties.h:134
const bdlbb::Blob & streamOut(bdlbb::BlobBufferFactory *bufferFactory) const
bool getPropertyAsBoolOr(const bsl::string &name, bool value) const
int setPropertyAsBool(const bsl::string &name, bool value)
int setPropertyAsInt32(const bsl::string &name, bsl::int32_t value)
int streamIn(const bdlbb::Blob &blob)
const bsl::vector< char > & getPropertyAsBinaryOr(const bsl::string &name, const bsl::vector< char > &value) const
static const int k_MAX_NUM_PROPERTIES
Maximum number of properties that can appear in a bmqa::Message.
Definition: bmqa_messageproperties.h:126
bsl::int32_t getPropertyAsInt32Or(const bsl::string &name, bsl::int32_t value) const
bsl::ostream & operator<<(bsl::ostream &stream, const CloseQueueStatus &rhs)
Definition: bmqa_closequeuestatus.h:227
Definition: bmqa_abstractsession.h:42
Enum
Definition: bmqt_propertytype.h:61