Qpid Proton C++ API  0.36.0
message.hpp
Go to the documentation of this file.
1 #ifndef PROTON_MESSAGE_HPP
2 #define PROTON_MESSAGE_HPP
3 
4 /*
5  *
6  * Licensed to the Apache Software Foundation (ASF) under one
7  * or more contributor license agreements. See the NOTICE file
8  * distributed with this work for additional information
9  * regarding copyright ownership. The ASF licenses this file
10  * to you under the Apache License, Version 2.0 (the
11  * "License"); you may not use this file except in compliance
12  * with the License. You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing,
17  * software distributed under the License is distributed on an
18  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19  * KIND, either express or implied. See the License for the
20  * specific language governing permissions and limitations
21  * under the License.
22  *
23  */
24 
25 #include "./fwd.hpp"
26 #include "./internal/export.hpp"
27 #include "./duration.hpp"
28 #include "./timestamp.hpp"
29 #include "./value.hpp"
30 #include "./map.hpp"
31 
32 #include "./internal/pn_unique_ptr.hpp"
33 
34 #include <proton/type_compat.h>
35 
36 #include <string>
37 #include <vector>
38 
41 
42 struct pn_message_t;
43 
44 namespace proton {
45 
50 class message {
51  public:
54 
57 
59  PN_CPP_EXTERN message();
60 
62  PN_CPP_EXTERN message(const message&);
63 
65  PN_CPP_EXTERN message& operator=(const message&);
66 
68  PN_CPP_EXTERN message(message&&);
69 
71  PN_CPP_EXTERN message& operator=(message&&);
72 
75  PN_CPP_EXTERN message(const value& x);
76 
77  PN_CPP_EXTERN ~message();
78 
81 
83  PN_CPP_EXTERN void clear();
84 
89  PN_CPP_EXTERN void id(const message_id&);
90 
92  PN_CPP_EXTERN message_id id() const;
93 
95  PN_CPP_EXTERN void user(const std::string&);
96 
98  PN_CPP_EXTERN std::string user() const;
99 
102  PN_CPP_EXTERN void encode(std::vector<char>&) const;
103 
105  PN_CPP_EXTERN std::vector<char> encode() const;
106 
108  PN_CPP_EXTERN void decode(const std::vector<char>&);
109 
111 
114 
116  PN_CPP_EXTERN void to(const std::string&);
117 
119  PN_CPP_EXTERN std::string to() const;
120 
123  PN_CPP_EXTERN void address(const std::string&);
124  PN_CPP_EXTERN std::string address() const;
126 
128  PN_CPP_EXTERN void reply_to(const std::string&);
129 
131  PN_CPP_EXTERN std::string reply_to() const;
132 
134  PN_CPP_EXTERN void correlation_id(const message_id&);
135 
137  PN_CPP_EXTERN message_id correlation_id() const;
138 
140 
143 
145  PN_CPP_EXTERN void body(const value& x);
146 
148  PN_CPP_EXTERN const value& body() const;
149 
151  PN_CPP_EXTERN value& body();
152 
154  PN_CPP_EXTERN void subject(const std::string&);
155 
157  PN_CPP_EXTERN std::string subject() const;
158 
160  PN_CPP_EXTERN void content_type(const std::string&);
161 
163  PN_CPP_EXTERN std::string content_type() const;
164 
166  PN_CPP_EXTERN void content_encoding(const std::string&);
167 
169  PN_CPP_EXTERN std::string content_encoding() const;
170 
172  PN_CPP_EXTERN void expiry_time(timestamp);
173 
175  PN_CPP_EXTERN timestamp expiry_time() const;
176 
178  PN_CPP_EXTERN void creation_time(timestamp);
179 
181  PN_CPP_EXTERN timestamp creation_time() const;
182 
192  PN_CPP_EXTERN bool inferred() const;
193 
195  PN_CPP_EXTERN void inferred(bool);
196 
198 
201 
206  PN_CPP_EXTERN bool durable() const;
207 
209  PN_CPP_EXTERN void durable(bool);
210 
218  PN_CPP_EXTERN duration ttl() const;
219 
221  PN_CPP_EXTERN void ttl(duration);
222 
230  PN_CPP_EXTERN uint8_t priority() const;
231 
233  PN_CPP_EXTERN void priority(uint8_t);
234 
243 
244  // XXX The triple-not in the last sentence above is confusing.
245 
246  PN_CPP_EXTERN bool first_acquirer() const;
247 
249  PN_CPP_EXTERN void first_acquirer(bool);
250 
255  PN_CPP_EXTERN uint32_t delivery_count() const;
256 
258  PN_CPP_EXTERN void delivery_count(uint32_t);
259 
261 
264 
266  PN_CPP_EXTERN void group_id(const std::string&);
267 
269  PN_CPP_EXTERN std::string group_id() const;
270 
272  PN_CPP_EXTERN void reply_to_group_id(const std::string&);
273 
275  PN_CPP_EXTERN std::string reply_to_group_id() const;
276 
282  PN_CPP_EXTERN int32_t group_sequence() const;
283 
285  PN_CPP_EXTERN void group_sequence(int32_t);
286 
288 
291 
294  PN_CPP_EXTERN property_map& properties();
295 
297  PN_CPP_EXTERN const property_map& properties() const;
298 
302 
304  PN_CPP_EXTERN const annotation_map& message_annotations() const;
305 
309 
311  PN_CPP_EXTERN const annotation_map& delivery_annotations() const;
312 
314 
316  PN_CPP_EXTERN static const uint8_t default_priority;
317 
319  friend PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, const message&);
320 
322  private:
323  struct impl;
324  pn_message_t* pn_msg() const;
325  struct impl& impl() const;
326 
327  mutable pn_message_t* pn_msg_;
328 
329  PN_CPP_EXTERN friend void swap(message&, message&);
331 };
332 
334 PN_CPP_EXTERN std::string to_string(const message&);
335 
336 } // proton
337 
338 #endif // PROTON_MESSAGE_HPP
A span of time in milliseconds.
Definition: duration.hpp:39
A collection of key-value pairs.
Definition: map.hpp:67
An AMQP message ID.
Definition: message_id.hpp:47
An AMQP message.
Definition: message.hpp:50
void encode(std::vector< char > &) const
Encode entire message into a byte vector, growing it if necessary.
const annotation_map & message_annotations() const
Examine the message annotations map.
map< std::string, scalar > property_map
A map of string keys and AMQP scalar values.
Definition: message.hpp:53
bool inferred() const
Get the inferred flag.
void user(const std::string &)
Set the user name or ID.
void inferred(bool)
Set the inferred flag.
timestamp creation_time() const
Get the creation time.
static const uint8_t default_priority
Default priority assigned to new messages.
Definition: message.hpp:316
value & body()
Get a reference to the body that can be modified in place.
void group_sequence(int32_t)
Set the group sequence for a message.
void to(const std::string &)
Set the destination address.
void subject(const std::string &)
Set the subject.
map< annotation_key, value > annotation_map
A map of AMQP annotation keys and AMQP values.
Definition: message.hpp:56
void reply_to(const std::string &)
Set the address for replies.
void expiry_time(timestamp)
Set the expiration time.
void content_encoding(const std::string &)
Set the content encoding of the body.
void creation_time(timestamp)
Set the creation time.
void decode(const std::vector< char > &)
Decode from string data into the message.
bool durable() const
Get the durable flag.
message(const message &)
Copy a message.
annotation_map & message_annotations()
Get the message annotations map.
const annotation_map & delivery_annotations() const
Examine the delivery annotations map.
void ttl(duration)
Set the TTL.
std::string group_id() const
Get the message group ID.
bool first_acquirer() const
Get the first acquirer flag.
void first_acquirer(bool)
Set the first acquirer flag.
friend std::ostream & operator<<(std::ostream &, const message &)
Human readable string representation.
void priority(uint8_t)
Set the priority.
timestamp expiry_time() const
Get the expiration time.
duration ttl() const
Get the TTL.
std::string to() const
Get the destination address.
void reply_to_group_id(const std::string &)
Set the reply-to group ID.
std::string subject() const
Get the subject.
void id(const message_id &)
Set the message ID.
void durable(bool)
Set the durable flag.
std::string user() const
Get the user name or ID.
std::string content_type() const
Get the content type of the body.
const value & body() const
Get the body.
std::string reply_to_group_id() const
Get the reply-to group ID.
message(const value &x)
Create a message with its body set from any value that can be converted to a proton::value.
void delivery_count(uint32_t)
Get the delivery count.
std::string content_encoding() const
Get the content encoding of the body.
uint8_t priority() const
Get the priority.
uint32_t delivery_count() const
Get the delivery count.
message()
Create an empty message.
property_map & properties()
Get the application properties map.
void group_id(const std::string &)
Set the message group ID.
message(message &&)
Move a message.
message & operator=(message &&)
Move a message.
const property_map & properties() const
Examine the application properties map.
void clear()
Clear the message content and properties.
void correlation_id(const message_id &)
Set the ID for matching related messages.
annotation_map & delivery_annotations()
Get the delivery annotations map.
message_id id() const
Get the message ID.
void body(const value &x)
Set the body. Equivalent to body() = x.
void content_type(const std::string &)
Set the content type of the body.
std::vector< char > encode() const
Return encoded message as a byte vector.
message_id correlation_id() const
Get the ID for matching related messages.
message & operator=(const message &)
Copy a message.
int32_t group_sequence() const
Get the group sequence.
std::string reply_to() const
Get the address for replies.
A 64-bit timestamp in milliseconds since the Unix epoch.
Definition: timestamp.hpp:35
A holder for any AMQP value, simple or complex.
Definition: value.hpp:57
A span of time in milliseconds.
Forward declarations.
A collection of key-value pairs.
The main Proton namespace.
Definition: annotation_key.hpp:33
std::string to_string(const message &)
Human readable string representation.
void swap(map< K, T > &, map< K, T > &)
Swap proton::map instances.
A 64-bit timestamp in milliseconds since the Unix epoch.
A holder for any AMQP value, simple or complex.