2 Copyright (c) 2018-2019 Nokia.
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
8 http://www.apache.org/licenses/LICENSE-2.0
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.
18 * This source code is part of the near-RT RIC (RAN Intelligent Controller)
19 * platform project (RICP).
22 #include "private/redis/contentsbuilder.hpp"
23 #include "private/redis/contents.hpp"
25 using namespace shareddatalayer;
26 using namespace shareddatalayer::redis;
28 ContentsBuilder::ContentsBuilder(const char nsKeySeparator):
29 nsKeySeparator(nsKeySeparator)
33 ContentsBuilder::~ContentsBuilder()
37 Contents ContentsBuilder::build(const std::string& string) const
40 addString(contents, string);
44 Contents ContentsBuilder::build(const std::string& string,
45 const std::string& string2) const
48 addString(contents, string);
49 addString(contents, string2);
53 Contents ContentsBuilder::build(const std::string& string,
54 const std::string& string2,
55 const std::string& string3) const
58 addString(contents, string);
59 addString(contents, string2);
60 addString(contents, string3);
64 Contents ContentsBuilder::build(const std::string& string,
65 const AsyncConnection::Namespace& ns,
66 const AsyncConnection::DataMap& dataMap) const
69 addString(contents, string);
70 addDataMap(contents, ns, dataMap);
74 Contents ContentsBuilder::build(const std::string& string,
75 const AsyncConnection::Namespace& ns,
76 const AsyncConnection::DataMap& dataMap,
77 const std::string& string2,
78 const std::string& string3) const
81 addString(contents, string);
82 addDataMap(contents, ns, dataMap);
83 addString(contents, string2);
84 addString(contents, string3);
88 Contents ContentsBuilder::build(const std::string& string,
89 const AsyncConnection::Namespace& ns,
90 const AsyncConnection::Key& key,
91 const AsyncConnection::Data& data) const
94 addString(contents, string);
95 addKey(contents, ns, key);
96 addData(contents, data);
100 Contents ContentsBuilder::build(const std::string& string,
101 const AsyncConnection::Namespace& ns,
102 const AsyncConnection::Key& key,
103 const AsyncConnection::Data& data,
104 const std::string& string2,
105 const std::string& string3) const
108 addString(contents, string);
109 addKey(contents, ns, key);
110 addData(contents, data);
111 addString(contents, string2);
112 addString(contents, string3);
116 Contents ContentsBuilder::build(const std::string& string,
117 const AsyncConnection::Namespace& ns,
118 const AsyncConnection::Key& key,
119 const AsyncConnection::Data& data,
120 const AsyncConnection::Data& data2) const
123 addString(contents, string);
124 addKey(contents, ns, key);
125 addData(contents, data);
126 addData(contents, data2);
130 Contents ContentsBuilder::build(const std::string& string,
131 const AsyncConnection::Namespace& ns,
132 const AsyncConnection::Key& key,
133 const AsyncConnection::Data& data,
134 const AsyncConnection::Data& data2,
135 const std::string& string2,
136 const std::string& string3) const
139 addString(contents, string);
140 addKey(contents, ns, key);
141 addData(contents, data);
142 addData(contents, data2);
143 addString(contents, string2);
144 addString(contents, string3);
148 Contents ContentsBuilder::build(const std::string& string,
149 const AsyncConnection::Namespace& ns,
150 const AsyncConnection::Keys& keys) const
153 addString(contents, string);
154 addKeys(contents, ns, keys);
158 Contents ContentsBuilder::build(const std::string& string,
159 const AsyncConnection::Namespace& ns,
160 const AsyncConnection::Keys& keys,
161 const std::string& string2,
162 const std::string& string3) const
165 addString(contents, string);
166 addKeys(contents, ns, keys);
167 addString(contents, string2);
168 addString(contents, string3);
172 void ContentsBuilder::addString(Contents& contents,
173 const std::string& string) const
175 contents.stack.push_back(string);
176 contents.sizes.push_back(string.size());
179 void ContentsBuilder::addDataMap(Contents& contents,
180 const AsyncConnection::Namespace& ns,
181 const AsyncConnection::DataMap& dataMap) const
183 for (const auto& i : dataMap)
185 addKey(contents, ns, i.first);
186 addData(contents, i.second);
190 void ContentsBuilder::addKey(Contents& contents,
191 const AsyncConnection::Namespace& ns,
192 const AsyncConnection::Key& key) const
194 auto content('{' + ns + '}' + nsKeySeparator + key);
195 contents.stack.push_back(content);
196 contents.sizes.push_back((content).size());
199 void ContentsBuilder::addData(Contents& contents,
200 const AsyncConnection::Data& data) const
202 contents.stack.push_back(std::string(reinterpret_cast<const char*>(data.data()),
203 static_cast<size_t>(data.size())));
204 contents.sizes.push_back(data.size());
207 void ContentsBuilder::addKeys(Contents& contents,
208 const AsyncConnection::Namespace& ns,
209 const AsyncConnection::Keys& keys) const
211 for (const auto& i : keys)
212 addKey(contents, ns, i);