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.
17 #include "private/redis/contentsbuilder.hpp"
18 #include "private/redis/contents.hpp"
20 using namespace shareddatalayer;
21 using namespace shareddatalayer::redis;
23 ContentsBuilder::ContentsBuilder(const char nsKeySeparator):
24 nsKeySeparator(nsKeySeparator)
28 ContentsBuilder::~ContentsBuilder()
32 Contents ContentsBuilder::build(const std::string& string) const
35 addString(contents, string);
39 Contents ContentsBuilder::build(const std::string& string,
40 const std::string& string2) const
43 addString(contents, string);
44 addString(contents, string2);
48 Contents ContentsBuilder::build(const std::string& string,
49 const std::string& string2,
50 const std::string& string3) const
53 addString(contents, string);
54 addString(contents, string2);
55 addString(contents, string3);
59 Contents ContentsBuilder::build(const std::string& string,
60 const AsyncConnection::Namespace& ns,
61 const AsyncConnection::DataMap& dataMap) const
64 addString(contents, string);
65 addDataMap(contents, ns, dataMap);
69 Contents ContentsBuilder::build(const std::string& string,
70 const AsyncConnection::Namespace& ns,
71 const AsyncConnection::DataMap& dataMap,
72 const std::string& string2,
73 const std::string& string3) const
76 addString(contents, string);
77 addDataMap(contents, ns, dataMap);
78 addString(contents, string2);
79 addString(contents, string3);
83 Contents ContentsBuilder::build(const std::string& string,
84 const AsyncConnection::Namespace& ns,
85 const AsyncConnection::Key& key,
86 const AsyncConnection::Data& data) const
89 addString(contents, string);
90 addKey(contents, ns, key);
91 addData(contents, data);
95 Contents ContentsBuilder::build(const std::string& string,
96 const AsyncConnection::Namespace& ns,
97 const AsyncConnection::Key& key,
98 const AsyncConnection::Data& data,
99 const std::string& string2,
100 const std::string& string3) const
103 addString(contents, string);
104 addKey(contents, ns, key);
105 addData(contents, data);
106 addString(contents, string2);
107 addString(contents, string3);
111 Contents ContentsBuilder::build(const std::string& string,
112 const AsyncConnection::Namespace& ns,
113 const AsyncConnection::Key& key,
114 const AsyncConnection::Data& data,
115 const AsyncConnection::Data& data2) const
118 addString(contents, string);
119 addKey(contents, ns, key);
120 addData(contents, data);
121 addData(contents, data2);
125 Contents ContentsBuilder::build(const std::string& string,
126 const AsyncConnection::Namespace& ns,
127 const AsyncConnection::Key& key,
128 const AsyncConnection::Data& data,
129 const AsyncConnection::Data& data2,
130 const std::string& string2,
131 const std::string& string3) const
134 addString(contents, string);
135 addKey(contents, ns, key);
136 addData(contents, data);
137 addData(contents, data2);
138 addString(contents, string2);
139 addString(contents, string3);
143 Contents ContentsBuilder::build(const std::string& string,
144 const AsyncConnection::Namespace& ns,
145 const AsyncConnection::Keys& keys) const
148 addString(contents, string);
149 addKeys(contents, ns, keys);
153 Contents ContentsBuilder::build(const std::string& string,
154 const AsyncConnection::Namespace& ns,
155 const AsyncConnection::Keys& keys,
156 const std::string& string2,
157 const std::string& string3) const
160 addString(contents, string);
161 addKeys(contents, ns, keys);
162 addString(contents, string2);
163 addString(contents, string3);
167 void ContentsBuilder::addString(Contents& contents,
168 const std::string& string) const
170 contents.stack.push_back(string);
171 contents.sizes.push_back(string.size());
174 void ContentsBuilder::addDataMap(Contents& contents,
175 const AsyncConnection::Namespace& ns,
176 const AsyncConnection::DataMap& dataMap) const
178 for (const auto& i : dataMap)
180 addKey(contents, ns, i.first);
181 addData(contents, i.second);
185 void ContentsBuilder::addKey(Contents& contents,
186 const AsyncConnection::Namespace& ns,
187 const AsyncConnection::Key& key) const
189 auto content('{' + ns + '}' + nsKeySeparator + key);
190 contents.stack.push_back(content);
191 contents.sizes.push_back((content).size());
194 void ContentsBuilder::addData(Contents& contents,
195 const AsyncConnection::Data& data) const
197 contents.stack.push_back(std::string(reinterpret_cast<const char*>(data.data()),
198 static_cast<size_t>(data.size())));
199 contents.sizes.push_back(data.size());
202 void ContentsBuilder::addKeys(Contents& contents,
203 const AsyncConnection::Namespace& ns,
204 const AsyncConnection::Keys& keys) const
206 for (const auto& i : keys)
207 addKey(contents, ns, i);