-
Notifications
You must be signed in to change notification settings - Fork 17
/
rmqt_properties.cpp
90 lines (80 loc) · 3.15 KB
/
rmqt_properties.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2020-2023 Bloomberg Finance L.P.
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <rmqt_properties.h>
#include <bsl_memory.h>
#include <bsl_ostream.h>
#include <bslim_printer.h>
namespace BloombergLP {
namespace rmqt {
namespace {
bool headersEquality(const bsl::shared_ptr<rmqt::FieldTable>& lhs,
const bsl::shared_ptr<rmqt::FieldTable>& rhs)
{
return (lhs == rhs) || ((lhs && rhs) && (*lhs == *rhs));
}
} // namespace
bsl::ostream& Properties::print(bsl::ostream& stream,
BSLA_MAYBE_UNUSED int level,
BSLA_MAYBE_UNUSED int spacesPerLevel) const
{
const bsl::string_view deliveryModeValue =
deliveryMode.value_or(rmqt::DeliveryMode::NON_PERSISTENT) ==
rmqt::DeliveryMode::NON_PERSISTENT
? "non persistent"
: "persistent";
bslim::Printer printer(&stream, 0, -1);
printer.start();
printer.printAttribute("contentType", contentType);
printer.printAttribute("contentEncoding", contentEncoding);
printer.printAttribute("headers", headers);
printer.printAttribute("deliveryMode", deliveryModeValue);
printer.printAttribute("priority", priority);
printer.printAttribute("correlationId", correlationId);
printer.printAttribute("replyTo", replyTo);
printer.printAttribute("expiration", expiration);
printer.printAttribute("messageId", messageId);
printer.printAttribute("timestamp", timestamp);
printer.printAttribute("type", type);
printer.printAttribute("userId", userId);
printer.printAttribute("appId", appId);
printer.end();
return stream;
}
bsl::ostream& operator<<(bsl::ostream& os, const Properties& p)
{
return p.print(os, 0, -1);
}
bool operator==(const Properties& lhs, const Properties& rhs)
{
#define RMQT_PROPERTY_EQUALS(prop) lhs.prop == rhs.prop
return (&lhs == &rhs) ||
(RMQT_PROPERTY_EQUALS(contentType) &&
RMQT_PROPERTY_EQUALS(contentEncoding) &&
headersEquality(lhs.headers, rhs.headers) &&
RMQT_PROPERTY_EQUALS(deliveryMode) &&
RMQT_PROPERTY_EQUALS(priority) &&
RMQT_PROPERTY_EQUALS(correlationId) &&
RMQT_PROPERTY_EQUALS(replyTo) && RMQT_PROPERTY_EQUALS(expiration) &&
RMQT_PROPERTY_EQUALS(messageId) &&
RMQT_PROPERTY_EQUALS(timestamp) && RMQT_PROPERTY_EQUALS(type) &&
RMQT_PROPERTY_EQUALS(userId) && RMQT_PROPERTY_EQUALS(appId));
#undef RMQT_PROPERTY_EQUALS
}
bool operator!=(const Properties& lhs, const Properties& rhs)
{
return !(lhs == rhs);
}
} // namespace rmqt
} // namespace BloombergLP