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 | #include "deserializers/object_deserializer.hpp" | ||
8 | |||
9 | 165 | ObjectDeserializer::ObjectDeserializer(const std::string& param_name, char start, bool skip_name, char kv_separator, | |
10 | 165 | char vk_separator, bool is_deep_obj, const ObjKTMap& kt_map) | |
11 | : BaseDeserializer(param_name, start, skip_name) | ||
12 | 165 | , kv_separator_(kv_separator) | |
13 | 165 | , vk_separator_(vk_separator) | |
14 | 165 | , is_deep_obj_(is_deep_obj) | |
15 |
1/2✓ Branch 2 taken 165 times.
✗ Branch 3 not taken.
|
165 | , kt_map_(kt_map) |
16 | { | ||
17 | 165 | } | |
18 | |||
19 | 38 | std::string ObjectDeserializer::Deserialize(const char* beg, const char* const end) | |
20 | { | ||
21 | 38 | const char* cursor = beg; | |
22 | |||
23 |
2/2✓ Branch 1 taken 37 times.
✓ Branch 2 taken 1 times.
|
38 | CheckNSkipStart(cursor); |
24 | |||
25 |
4/4✓ Branch 0 taken 10 times.
✓ Branch 1 taken 27 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 1 times.
|
37 | if (skip_name_ && !is_deep_obj_) { |
26 |
1/2✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
|
9 | CheckNSkipName(cursor, end); |
27 |
1/2✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
|
9 | CheckNSkipChar(cursor, end, '='); |
28 | } | ||
29 | |||
30 |
1/2✓ Branch 1 taken 37 times.
✗ Branch 2 not taken.
|
37 | CheckData(cursor, end); |
31 | |||
32 | 37 | std::string ret; | |
33 |
1/2✓ Branch 1 taken 37 times.
✗ Branch 2 not taken.
|
37 | ret.reserve(static_cast<size_t>(end - beg + 128)); |
34 | |||
35 |
1/2✓ Branch 1 taken 37 times.
✗ Branch 2 not taken.
|
37 | ret.push_back('{'); |
36 | |||
37 | 37 | std::string key; | |
38 |
1/2✓ Branch 1 taken 37 times.
✗ Branch 2 not taken.
|
37 | key.reserve(128); |
39 | |||
40 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 35 times.
|
37 | if (is_deep_obj_) { |
41 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2 times.
|
12 | while (cursor < end) { |
42 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | CheckNSkipName(cursor, end); |
43 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | CheckNSkipChar(cursor, end, '['); |
44 | 10 | key.clear(); | |
45 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | DeserializeKey(cursor, end, ']', key); |
46 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | CheckNSkipChar(cursor, end, '='); |
47 | try { | ||
48 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | auto param_type = kt_map_.at(key); |
49 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | ret.append(key); |
50 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | ret.push_back(':'); |
51 |
4/5✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
10 | switch (param_type) { |
52 | 4 | case PrimitiveType::BOOLEAN: | |
53 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | DeserializeBoolean(cursor, end, ret); |
54 | 4 | break; | |
55 | |||
56 | 2 | case PrimitiveType::INTEGER: | |
57 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | DeserializeInteger(cursor, end, ret); |
58 | 2 | break; | |
59 | |||
60 | 2 | case PrimitiveType::NUMBER: | |
61 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | DeserializeNumber(cursor, end, ret); |
62 | 2 | break; | |
63 | |||
64 | 2 | case PrimitiveType::STRING: | |
65 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | DeserializeString(cursor, end, vk_separator_, ret); |
66 | 2 | break; | |
67 | ✗ | default: | |
68 | ✗ | throw DeserializationException("Invalid primitive type for '" + param_name_ + "'"); | |
69 | } | ||
70 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 2 times.
|
10 | if (*cursor == vk_separator_) { |
71 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | ret.push_back(','); |
72 | 8 | ++cursor; | |
73 | } | ||
74 | ✗ | } catch (const std::out_of_range&) { | |
75 | ✗ | throw DeserializationException("Invalid format for '" + param_name_ + "'"); | |
76 | ✗ | } | |
77 | } | ||
78 | } else { | ||
79 |
2/2✓ Branch 0 taken 113 times.
✓ Branch 1 taken 24 times.
|
137 | while (cursor < end) { |
80 | 113 | key.clear(); | |
81 |
1/2✓ Branch 1 taken 113 times.
✗ Branch 2 not taken.
|
113 | DeserializeKey(cursor, end, kv_separator_, key); |
82 | try { | ||
83 |
2/2✓ Branch 1 taken 107 times.
✓ Branch 2 taken 6 times.
|
113 | auto param_type = kt_map_.at(key); |
84 |
1/2✓ Branch 1 taken 107 times.
✗ Branch 2 not taken.
|
107 | ret.append(key); |
85 |
1/2✓ Branch 1 taken 107 times.
✗ Branch 2 not taken.
|
107 | ret.push_back(':'); |
86 |
4/5✓ Branch 0 taken 37 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 25 times.
✗ Branch 4 not taken.
|
107 | switch (param_type) { |
87 | 37 | case PrimitiveType::BOOLEAN: | |
88 |
2/2✓ Branch 1 taken 36 times.
✓ Branch 2 taken 1 times.
|
37 | DeserializeBoolean(cursor, end, ret); |
89 | 36 | break; | |
90 | |||
91 | 28 | case PrimitiveType::INTEGER: | |
92 |
2/2✓ Branch 1 taken 26 times.
✓ Branch 2 taken 2 times.
|
28 | DeserializeInteger(cursor, end, ret); |
93 | 26 | break; | |
94 | |||
95 | 17 | case PrimitiveType::NUMBER: | |
96 |
2/2✓ Branch 1 taken 16 times.
✓ Branch 2 taken 1 times.
|
17 | DeserializeNumber(cursor, end, ret); |
97 | 16 | break; | |
98 | |||
99 | 25 | case PrimitiveType::STRING: | |
100 |
2/2✓ Branch 1 taken 24 times.
✓ Branch 2 taken 1 times.
|
25 | DeserializeString(cursor, end, vk_separator_, ret); |
101 | 24 | break; | |
102 | ✗ | default: | |
103 | ✗ | throw DeserializationException("Invalid primitive type for '" + param_name_ + "'"); | |
104 | } | ||
105 |
2/2✓ Branch 0 taken 78 times.
✓ Branch 1 taken 24 times.
|
102 | if (*cursor == vk_separator_) { |
106 |
1/2✓ Branch 1 taken 78 times.
✗ Branch 2 not taken.
|
78 | ret.push_back(','); |
107 | 78 | ++cursor; | |
108 | } | ||
109 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 6 times.
|
11 | } catch (const std::out_of_range&) { |
110 |
3/6✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
|
6 | throw DeserializationException("Invalid format for '" + param_name_ + "'"); |
111 | 6 | } | |
112 | } | ||
113 | } | ||
114 | |||
115 |
1/2✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
|
26 | CheckEnd(cursor, end); |
116 | |||
117 |
1/2✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
|
26 | ret.push_back('}'); |
118 | 52 | return ret; | |
119 | 48 | } | |
120 |