Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 1 | /* |
| 2 | Copyright (c) 2018-2019 Nokia. |
| 3 | |
| 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 |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 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. |
| 15 | */ |
| 16 | |
Timo Tietavainen | a0745d2 | 2019-11-28 09:55:22 +0200 | [diff] [blame^] | 17 | /* |
| 18 | * This source code is part of the near-RT RIC (RAN Intelligent Controller) |
| 19 | * platform project (RICP). |
| 20 | */ |
| 21 | |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 22 | #include "private/redis/contentsbuilder.hpp" |
| 23 | #include "private/redis/contents.hpp" |
| 24 | |
| 25 | using namespace shareddatalayer; |
| 26 | using namespace shareddatalayer::redis; |
| 27 | |
| 28 | ContentsBuilder::ContentsBuilder(const char nsKeySeparator): |
| 29 | nsKeySeparator(nsKeySeparator) |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | ContentsBuilder::~ContentsBuilder() |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | Contents ContentsBuilder::build(const std::string& string) const |
| 38 | { |
| 39 | Contents contents; |
| 40 | addString(contents, string); |
| 41 | return contents; |
| 42 | } |
| 43 | |
| 44 | Contents ContentsBuilder::build(const std::string& string, |
| 45 | const std::string& string2) const |
| 46 | { |
| 47 | Contents contents; |
| 48 | addString(contents, string); |
| 49 | addString(contents, string2); |
| 50 | return contents; |
| 51 | } |
| 52 | |
| 53 | Contents ContentsBuilder::build(const std::string& string, |
| 54 | const std::string& string2, |
| 55 | const std::string& string3) const |
| 56 | { |
| 57 | Contents contents; |
| 58 | addString(contents, string); |
| 59 | addString(contents, string2); |
| 60 | addString(contents, string3); |
| 61 | return contents; |
| 62 | } |
| 63 | |
| 64 | Contents ContentsBuilder::build(const std::string& string, |
| 65 | const AsyncConnection::Namespace& ns, |
| 66 | const AsyncConnection::DataMap& dataMap) const |
| 67 | { |
| 68 | Contents contents; |
| 69 | addString(contents, string); |
| 70 | addDataMap(contents, ns, dataMap); |
| 71 | return contents; |
| 72 | } |
| 73 | |
| 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 |
| 79 | { |
| 80 | Contents contents; |
| 81 | addString(contents, string); |
| 82 | addDataMap(contents, ns, dataMap); |
| 83 | addString(contents, string2); |
| 84 | addString(contents, string3); |
| 85 | return contents; |
| 86 | } |
| 87 | |
| 88 | Contents ContentsBuilder::build(const std::string& string, |
| 89 | const AsyncConnection::Namespace& ns, |
| 90 | const AsyncConnection::Key& key, |
| 91 | const AsyncConnection::Data& data) const |
| 92 | { |
| 93 | Contents contents; |
| 94 | addString(contents, string); |
| 95 | addKey(contents, ns, key); |
| 96 | addData(contents, data); |
| 97 | return contents; |
| 98 | } |
| 99 | |
| 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 |
| 106 | { |
| 107 | Contents contents; |
| 108 | addString(contents, string); |
| 109 | addKey(contents, ns, key); |
| 110 | addData(contents, data); |
| 111 | addString(contents, string2); |
| 112 | addString(contents, string3); |
| 113 | return contents; |
| 114 | } |
| 115 | |
| 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 |
| 121 | { |
| 122 | Contents contents; |
| 123 | addString(contents, string); |
| 124 | addKey(contents, ns, key); |
| 125 | addData(contents, data); |
| 126 | addData(contents, data2); |
| 127 | return contents; |
| 128 | } |
| 129 | |
| 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 |
| 137 | { |
| 138 | Contents contents; |
| 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); |
| 145 | return contents; |
| 146 | } |
| 147 | |
| 148 | Contents ContentsBuilder::build(const std::string& string, |
| 149 | const AsyncConnection::Namespace& ns, |
| 150 | const AsyncConnection::Keys& keys) const |
| 151 | { |
| 152 | Contents contents; |
| 153 | addString(contents, string); |
| 154 | addKeys(contents, ns, keys); |
| 155 | return contents; |
| 156 | } |
| 157 | |
| 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 |
| 163 | { |
| 164 | Contents contents; |
| 165 | addString(contents, string); |
| 166 | addKeys(contents, ns, keys); |
| 167 | addString(contents, string2); |
| 168 | addString(contents, string3); |
| 169 | return contents; |
| 170 | } |
| 171 | |
| 172 | void ContentsBuilder::addString(Contents& contents, |
| 173 | const std::string& string) const |
| 174 | { |
| 175 | contents.stack.push_back(string); |
| 176 | contents.sizes.push_back(string.size()); |
| 177 | } |
| 178 | |
| 179 | void ContentsBuilder::addDataMap(Contents& contents, |
| 180 | const AsyncConnection::Namespace& ns, |
| 181 | const AsyncConnection::DataMap& dataMap) const |
| 182 | { |
| 183 | for (const auto& i : dataMap) |
| 184 | { |
| 185 | addKey(contents, ns, i.first); |
| 186 | addData(contents, i.second); |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | void ContentsBuilder::addKey(Contents& contents, |
| 191 | const AsyncConnection::Namespace& ns, |
| 192 | const AsyncConnection::Key& key) const |
| 193 | { |
| 194 | auto content('{' + ns + '}' + nsKeySeparator + key); |
| 195 | contents.stack.push_back(content); |
| 196 | contents.sizes.push_back((content).size()); |
| 197 | } |
| 198 | |
| 199 | void ContentsBuilder::addData(Contents& contents, |
| 200 | const AsyncConnection::Data& data) const |
| 201 | { |
| 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()); |
| 205 | } |
| 206 | |
| 207 | void ContentsBuilder::addKeys(Contents& contents, |
| 208 | const AsyncConnection::Namespace& ns, |
| 209 | const AsyncConnection::Keys& keys) const |
| 210 | { |
| 211 | for (const auto& i : keys) |
| 212 | addKey(contents, ns, i); |
| 213 | } |