libbmq b6028b29b733bc7541593d2905a5f79a9f0192fc
Loading...
Searching...
No Matches
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_ostream.h>
69#include <bsl_string.h>
70#include <bsl_vector.h>
71#include <bslma_allocator.h>
72#include <bslma_usesbslmaallocator.h>
73#include <bslmf_nestedtraitdeclaration.h>
74#include <bsls_alignedbuffer.h>
75#include <bsls_types.h>
76
77namespace BloombergLP {
78
79// FORWARD DECLARATION
80namespace bmqp {
81class MessageProperties;
82}
83namespace bmqp {
84class MessagePropertiesIterator;
85}
86
87namespace bmqa {
88
89// =======================
90// class MessageProperties
91// =======================
92
95 // FRIENDS
97
98 private:
99 // PRIVATE CONSTANTS
100
104 static const int k_MAX_SIZEOF_BMQP_MESSAGEPROPERTIES = 184;
105
106 // PRIVATE TYPES
107 typedef bsls::AlignedBuffer<k_MAX_SIZEOF_BMQP_MESSAGEPROPERTIES>
108 ImplBuffer;
109
110 private:
111 // DATA
112
117 mutable bmqp::MessageProperties* d_impl_p;
118
120 ImplBuffer d_buffer;
121
122 bslma::Allocator* d_allocator_p;
123
124 public:
125 // PUBLIC CONSTANTS
126
128 static const int k_MAX_NUM_PROPERTIES = 255;
129
133 static const int k_MAX_PROPERTIES_AREA_LENGTH = (64 * 1024 * 1024) - 8;
134
136 static const int k_MAX_PROPERTY_NAME_LENGTH = 4095;
137
143 static const int k_MAX_PROPERTY_VALUE_LENGTH = 67104745;
144
145 public:
146 // TRAITS
147 BSLMF_NESTED_TRAIT_DECLARATION(MessageProperties,
148 bslma::UsesBslmaAllocator)
149
150 // CREATORS
151
152
157 explicit MessageProperties(bslma::Allocator* basicAllocator = 0);
158
163 bslma::Allocator* basicAllocator = 0);
164
167
168 // MANIPULATORS
169
171 MessageProperties& operator=(const MessageProperties& rhs);
172
177 bool remove(const bsl::string& name, bmqt::PropertyType::Enum* buffer = 0);
178
181 void clear();
182
183 int setPropertyAsBool(const bsl::string& name, bool value);
184 int setPropertyAsChar(const bsl::string& name, char value);
185 int setPropertyAsShort(const bsl::string& name, short value);
186 int setPropertyAsInt32(const bsl::string& name, bsl::int32_t value);
187 int setPropertyAsInt64(const bsl::string& name, bsls::Types::Int64 value);
188 int setPropertyAsString(const bsl::string& name, const bsl::string& value);
189
196 int setPropertyAsBinary(const bsl::string& name,
197 const bsl::vector<char>& value);
198
202 int streamIn(const bdlbb::Blob& blob);
203
204 // ACCESSORS
205
207 int numProperties() const;
208
212 int totalSize() const;
213
217 bool hasProperty(const bsl::string& name,
218 bmqt::PropertyType::Enum* type = 0) const;
219
223 bmqt::PropertyType::Enum propertyType(const bsl::string& name) const;
224
225 bool getPropertyAsBool(const bsl::string& name) const;
226 char getPropertyAsChar(const bsl::string& name) const;
227 short getPropertyAsShort(const bsl::string& name) const;
228 bsl::int32_t getPropertyAsInt32(const bsl::string& name) const;
229 bsls::Types::Int64 getPropertyAsInt64(const bsl::string& name) const;
230 const bsl::string& getPropertyAsString(const bsl::string& name) const;
231
234 const bsl::vector<char>&
235 getPropertyAsBinary(const bsl::string& name) const;
236
237 bool getPropertyAsBoolOr(const bsl::string& name, bool value) const;
238 char getPropertyAsCharOr(const bsl::string& name, char value) const;
239 short getPropertyAsShortOr(const bsl::string& name, short value) const;
240 bsl::int32_t getPropertyAsInt32Or(const bsl::string& name,
241 bsl::int32_t value) const;
242 bsls::Types::Int64 getPropertyAsInt64Or(const bsl::string& name,
243 bsls::Types::Int64 value) const;
244 const bsl::string& getPropertyAsStringOr(const bsl::string& name,
245 const bsl::string& value) const;
246
250 const bsl::vector<char>&
251 getPropertyAsBinaryOr(const bsl::string& name,
252 const bsl::vector<char>& value) const;
253
260 const bdlbb::Blob&
261 streamOut(bdlbb::BlobBufferFactory* bufferFactory) const;
262
272 bsl::ostream&
273 print(bsl::ostream& stream, int level = 0, int spacesPerLevel = 4) const;
274};
275
276// FREE OPERATORS
277
280bsl::ostream& operator<<(bsl::ostream& stream, const MessageProperties& rhs);
281
282// ===============================
283// class MessagePropertiesIterator
284// ===============================
285
293 private:
294 // PRIVATE CONSTANTS
295
296 // Constant representing the maximum size of a
297 // `bmqp::MessagePropertiesIterator` object, so that the below
298 // AlignedBuffer is big enough.
299 static const int k_MAX_SIZEOF_BMQP_MESSAGEPROPERTIESITER = 64;
300
301 // PRIVATE TYPES
302 typedef bsls::AlignedBuffer<k_MAX_SIZEOF_BMQP_MESSAGEPROPERTIESITER>
303 ImplBuffer;
304
305 private:
306 // DATA
307 mutable bmqp::MessagePropertiesIterator* d_impl_p;
308 // Pointer to the implementation object
309 // in 'd_buffer'. This variable *must*
310 // *be* the first member of this class.
311 // If the value is null, the object
312 // has not been constructed in the
313 // 'd_buffer'.
314
315 ImplBuffer d_buffer;
316 // Buffer containing the implementation
317 // object
318
319 public:
320 // CREATORS
321
326
329 explicit MessagePropertiesIterator(const MessageProperties* properties);
330
333
336
337 // MANIPULATORS
338
341
348 bool hasNext();
349
350 // ACCESSORS
351
355 const bsl::string& name() const;
356
360
361 bool getAsBool() const;
362 char getAsChar() const;
363 short getAsShort() const;
364 bsl::int32_t getAsInt32() const;
365 bsls::Types::Int64 getAsInt64() const;
366 const bsl::string& getAsString() const;
367
372 const bsl::vector<char>& getAsBinary() const;
373};
374
375} // close package namespace
376
377// ============================================================================
378// INLINE DEFINITIONS
379// ============================================================================
380
381// -----------------------
382// class MessageProperties
383// -----------------------
384
385inline bsl::ostream& bmqa::operator<<(bsl::ostream& stream,
386 const bmqa::MessageProperties& rhs)
387{
388 return rhs.print(stream, 0, -1);
389}
390
391} // close enterprise namespace
392
393#endif
Provide enum for the supported data types for a message property.
Provide enums for various publicly exposed result code.
Definition bmqa_messageproperties.h:292
const bsl::vector< char > & getAsBinary() const
bmqt::PropertyType::Enum type() const
~MessagePropertiesIterator()
Destroy this iterator.
MessagePropertiesIterator(const MessagePropertiesIterator &other)
Copy constructor from the specified other.
MessagePropertiesIterator & operator=(const MessagePropertiesIterator &rhs)
Assignment operator from the specified rhs.
MessagePropertiesIterator(const MessageProperties *properties)
const bsl::string & getAsString() const
Provide a VST representing message properties.
Definition bmqa_messageproperties.h:94
const bsl::vector< char > & getPropertyAsBinaryOr(const bsl::string &name, const bsl::vector< char > &value) const
bmqt::PropertyType::Enum propertyType(const bsl::string &name) const
static const int k_MAX_PROPERTY_VALUE_LENGTH
Definition bmqa_messageproperties.h:143
const bsl::string & getPropertyAsStringOr(const bsl::string &name, const bsl::string &value) const
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::vector< char > & getPropertyAsBinary(const bsl::string &name) const
const bdlbb::Blob & streamOut(bdlbb::BlobBufferFactory *bufferFactory) const
bool remove(const bsl::string &name, bmqt::PropertyType::Enum *buffer=0)
int setPropertyAsString(const bsl::string &name, const bsl::string &value)
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
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
static const int k_MAX_PROPERTIES_AREA_LENGTH
Definition bmqa_messageproperties.h:133
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)
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:136
bool getPropertyAsBoolOr(const bsl::string &name, bool value) const
const bsl::string & getPropertyAsString(const bsl::string &name) 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)
static const int k_MAX_NUM_PROPERTIES
Maximum number of properties that can appear in a bmqa::Message.
Definition bmqa_messageproperties.h:128
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