azure-core-amqp
Loading...
Searching...
No Matches
amqp_message.hpp
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4#pragma once
5
6#include "amqp_header.hpp"
7#include "amqp_properties.hpp"
8#include "amqp_value.hpp"
9
10#include <azure/core/nullable.hpp>
11
12#include <map>
13#include <vector>
14
15namespace Azure { namespace Core { namespace Amqp { namespace Models { namespace _detail {
16 class AmqpMessageFactory;
17}}}}} // namespace Azure::Core::Amqp::Models::_detail
18
19namespace Azure { namespace Core { namespace Amqp { namespace Models {
24 enum class MessageBodyType
25 {
26 Invalid,
27 None,
28 Data,
29 Sequence,
30 Value,
31 };
32
33 constexpr int AmqpDefaultMessageFormatValue
34 = 0; // Specifies the message format for an AMQP message.
35
47 class AmqpMessage final {
48 public:
50 AmqpMessage() = default;
51
53 ~AmqpMessage() = default;
54
57
59 AmqpMessage(AmqpMessage const&) = default;
60
64 AmqpMessage& operator=(AmqpMessage const&) = default;
65
70
72 bool operator==(AmqpMessage const& that) const noexcept;
73
75 bool operator!=(AmqpMessage const& that) const noexcept { return !(*this == that); }
76
78 AmqpMessage(std::nullptr_t) : m_hasValue{false} {}
79
84 operator bool() const noexcept { return m_hasValue; }
85
94 uint32_t MessageFormat = AmqpDefaultMessageFormatValue;
95
103
110
117
124
130 std::map<std::string, AmqpValue> ApplicationProperties;
131
138
145
155 MessageBodyType BodyType{MessageBodyType::None};
156
172 void SetBody(std::vector<AmqpList> const& bodySequence);
173
193 void SetBody(AmqpList const& bodySequence);
194
211 void SetBody(std::vector<AmqpBinaryData> const& bodyBinarySequence);
212
231 void SetBody(AmqpBinaryData const& bodyBinary);
232
248 void SetBody(AmqpValue const& bodyValue);
249
254 std::vector<AmqpList> const& GetBodyAsAmqpList() const;
255
260 AmqpValue const& GetBodyAsAmqpValue() const;
261
266 std::vector<AmqpBinaryData> const& GetBodyAsBinary() const;
267
272 static std::vector<uint8_t> Serialize(AmqpMessage const& message);
273
278 static AmqpMessage Deserialize(std::uint8_t const* buffer, size_t size);
279
280 friend class _detail::AmqpMessageFactory;
281
282 private:
283 std::vector<AmqpBinaryData> m_binaryDataBody;
284 std::vector<AmqpList> m_amqpSequenceBody;
285 AmqpValue m_amqpValueBody;
286 bool m_hasValue{true}; // By default, an AmqpMessage has a value.
287 };
288 std::ostream& operator<<(std::ostream&, AmqpMessage const&);
289}}}} // namespace Azure::Core::Amqp::Models
An AMQP binary value, a sequence of octets.
Definition amqp_value.hpp:784
An AMQP List is a sequence of polymorphic values. It has the behavioral characteristics of an AMQP ar...
Definition amqp_value.hpp:744
An AmqpMap represents an AMQP "map" type.
Definition amqp_value.hpp:681
An AmqpMessage object represents a received AMQP message.
Definition amqp_message.hpp:47
AmqpMessage(AmqpMessage &&)=default
Create a new AMQP Message from an existing message moving the contents.
static AmqpMessage Deserialize(std::uint8_t const *buffer, size_t size)
Deserialize the message from a buffer.
Definition amqp_message.cpp:745
~AmqpMessage()=default
Destroy an instance of an AMQP Message object.
AmqpValue const & GetBodyAsAmqpValue() const
Returns an Amqp Value message body.
Definition amqp_message.cpp:396
AmqpMessage()=default
Construct a new AMQP Message object.
std::vector< AmqpBinaryData > const & GetBodyAsBinary() const
Returns an Amqp Binary message body.
Definition amqp_message.cpp:404
uint32_t MessageFormat
The message format.
Definition amqp_message.hpp:94
AmqpMessage & operator=(AmqpMessage &&)=default
Move an AMQP message object to another object.
void SetBody(std::vector< AmqpList > const &bodySequence)
Sets the body of the message to a list of sequence sections.
Definition amqp_message.cpp:385
std::map< std::string, AmqpValue > ApplicationProperties
Application Properties for the message.
Definition amqp_message.hpp:130
AmqpMap MessageAnnotations
Message Annotations for the message.
Definition amqp_message.hpp:116
MessageBodyType BodyType
Definition amqp_message.hpp:155
AmqpMessage & operator=(AmqpMessage const &)=default
Copy an AMQP message object to another object.
std::vector< AmqpList > const & GetBodyAsAmqpList() const
Returns a list of Amqp Sequence values.
Definition amqp_message.cpp:361
AmqpMessage(AmqpMessage const &)=default
Construct a new AMQP message object from an existing object.
MessageHeader Header
The header for the message.
Definition amqp_message.hpp:102
AmqpValue DeliveryTag
Delivery Tag for the message.
Definition amqp_message.hpp:137
MessageProperties Properties
Immutable Properties for the message.
Definition amqp_message.hpp:123
static std::vector< uint8_t > Serialize(AmqpMessage const &message)
Serialize the message into a buffer.
Definition amqp_message.cpp:423
bool operator!=(AmqpMessage const &that) const noexcept
Compare two AmqpMessage values.
Definition amqp_message.hpp:75
AmqpMap Footer
Footer for the message.
Definition amqp_message.hpp:144
bool operator==(AmqpMessage const &that) const noexcept
Compare two AmqpMessages for equality.
Definition amqp_message.cpp:413
AmqpMap DeliveryAnnotations
Delivery Annotations for the message.
Definition amqp_message.hpp:109
AmqpMessage(std::nullptr_t)
Construct an empty AMQP Message.
Definition amqp_message.hpp:78
Definition amqp_value.hpp:104
The message header section carries standard delivery details about the transfer of a message through ...
Definition amqp_header.hpp:24
Represents the immutable properties of an AMQP message.
Definition amqp_properties.hpp:24