GCC Code Coverage Report


Directory: ./
File: include/deserializers/object_deserializer.hpp
Date: 2024-07-09 12:21:25
Exec Total Coverage
Lines: 10 10 100.0%
Functions: 2 2 100.0%
Branches: 7 8 87.5%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2024 Muhammad Nawaz
3 * Licensed under the MIT License. See LICENSE file for more information.
4 */
5 // [ END OF LICENSE c6bd0f49d040fca8d8a9cb05868e66aa63f0e2e0 ]
6
7 #ifndef OBJECT_DESERIALIZER_HPP
8 #define OBJECT_DESERIALIZER_HPP
9
10 #include "deserializers/base_deserializer.hpp"
11 #include <unordered_map>
12
13 using ObjKTMap = std::unordered_map<std::string, PrimitiveType>; // Object Key-name to PrimitiveType
14
15 class ObjectDeserializer final: public BaseDeserializer
16 {
17 public:
18 explicit ObjectDeserializer(const std::string& param_name, char start, bool skip_name, char kv_separator,
19 char vk_separator, bool is_deep_obj, const ObjKTMap& kt_map);
20
21 std::string Deserialize(const char* beg, const char* const end) override;
22 60 ~ObjectDeserializer() override = default;
23
24 private:
25 const char kv_separator_; // key-value separator
26 const char vk_separator_; // value-key separator
27 const bool is_deep_obj_;
28 const ObjKTMap kt_map_; // key-type map
29
30 123 inline void DeserializeKey(const char*& cursor, const char* const end, const char terminator,
31 std::string& key) const
32 {
33 123 key.push_back('"');
34
4/4
✓ Branch 0 taken 1027 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 906 times.
✓ Branch 3 taken 121 times.
1029 while (cursor < end && *cursor != terminator) {
35 906 key.push_back(*cursor);
36 906 ++cursor;
37 }
38
3/4
✓ Branch 0 taken 121 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 121 times.
✗ Branch 3 not taken.
123 if (cursor < end && *cursor == terminator) {
39 121 ++cursor;
40 }
41 123 key.push_back('"');
42 123 }
43 };
44
45 #endif // OBJECT_DESERIALIZER_HPP
46