| 210 | |
| 211 | |
| 212 | class MessageMarshalling { |
| 213 | private: |
| 214 | /// Only optional fields are listed here, if node (no need for field id) |
| 215 | enum Field { |
| 216 | LABEL = 0, |
| 217 | NOGOOD = 1, |
| 218 | INFO = 2, |
| 219 | VERSION = 3 |
| 220 | }; |
| 221 | |
| 222 | Message msg; |
| 223 | |
| 224 | typedef char* iter; |
| 225 | |
| 226 | static void serializeType(std::vector<char>& data, MsgType f) { |
| 227 | data.push_back(static_cast<char>(f)); |
| 228 | } |
| 229 | |
| 230 | static void serializeField(std::vector<char>& data, Field f) { |
| 231 | data.push_back(static_cast<char>(f)); |
| 232 | } |
| 233 | |
| 234 | static void serialize(std::vector<char>& data, int32_t i) { |
| 235 | data.push_back(static_cast<char>((i & 0xFF000000) >> 24)); |
| 236 | data.push_back(static_cast<char>((i & 0xFF0000) >> 16)); |
| 237 | data.push_back(static_cast<char>((i & 0xFF00) >> 8)); |
| 238 | data.push_back(static_cast<char>((i & 0xFF))); |
| 239 | } |
| 240 | |
| 241 | static void serialize(std::vector<char>& data, NodeStatus s) { |
| 242 | data.push_back(static_cast<char>(s)); |
| 243 | } |
| 244 | |
| 245 | static void serialize(std::vector<char>& data, const std::string& s) { |
| 246 | serialize(data, static_cast<int32_t>(s.size())); |
| 247 | for (char c : s) { |
| 248 | data.push_back(c); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | static MsgType deserializeMsgType(iter& it) { |
| 253 | auto m = static_cast<MsgType>(*it); |
| 254 | ++it; |
| 255 | return m; |
| 256 | } |
| 257 | |
| 258 | static Field deserializeField(iter& it) { |
| 259 | auto f = static_cast<Field>(*it); |
| 260 | ++it; |
| 261 | return f; |
| 262 | } |
| 263 | |
| 264 | static int32_t deserializeInt(iter& it) { |
| 265 | auto b1 = static_cast<uint32_t>(reinterpret_cast<uint8_t&>(*it++)); |
| 266 | auto b2 = static_cast<uint32_t>(reinterpret_cast<uint8_t&>(*it++)); |
| 267 | auto b3 = static_cast<uint32_t>(reinterpret_cast<uint8_t&>(*it++)); |
| 268 | auto b4 = static_cast<uint32_t>(reinterpret_cast<uint8_t&>(*it++)); |
| 269 |
nothing calls this directly
no test coverage detected