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 ARRAY_DESERIALIZER_HPP | ||
8 | #define ARRAY_DESERIALIZER_HPP | ||
9 | |||
10 | #include "deserializers/base_deserializer.hpp" | ||
11 | |||
12 | class ArrayDeserializer final: public BaseDeserializer | ||
13 | { | ||
14 | public: | ||
15 | explicit ArrayDeserializer(const std::string& param_name, char start, bool skip_name, PrimitiveType items_type, | ||
16 | char separator, bool has_running_name, bool has_20_separator); | ||
17 | |||
18 | std::string Deserialize(const char* beg, const char* const end) override; | ||
19 | 140 | ~ArrayDeserializer() override = default; | |
20 | |||
21 | private: | ||
22 | const PrimitiveType items_type_; | ||
23 | const char separator_; | ||
24 | const bool has_running_name_; | ||
25 | const bool has_20_separator_; // style=spaceDelimited, explode=true separator is %20 | ||
26 | |||
27 | 192 | inline void CheckElementData(const char*& cursor, const char* const end) const | |
28 | { | ||
29 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 192 times.
|
192 | if (cursor >= end) { |
30 | ✗ | throw DeserializationException("Data for item of parameter '" + param_name_ + "' is missing"); | |
31 | } | ||
32 | 192 | } | |
33 | |||
34 | 213 | inline void CheckSeparator(const char*& cursor, const char* const end) const | |
35 | { | ||
36 |
2/2✓ Branch 0 taken 130 times.
✓ Branch 1 taken 83 times.
|
213 | if (cursor < end) { |
37 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 115 times.
|
130 | if (has_20_separator_) { |
38 | 15 | CheckNSkipChar(cursor, end, '%'); | |
39 | 15 | CheckNSkipChar(cursor, end, '2'); | |
40 | 15 | CheckNSkipChar(cursor, end, '0'); | |
41 | } else { | ||
42 | 115 | CheckNSkipChar(cursor, end, separator_); | |
43 | } | ||
44 | 124 | CheckElementData(cursor, end); | |
45 | } | ||
46 | 207 | } | |
47 | |||
48 | 31 | inline void DeserializeBooleanArray(const char*& cursor, const char* const end, std::string& ret) const | |
49 | { | ||
50 |
2/2✓ Branch 0 taken 63 times.
✓ Branch 1 taken 26 times.
|
89 | while (cursor < end) { |
51 |
2/2✓ Branch 0 taken 17 times.
✓ Branch 1 taken 46 times.
|
63 | if (has_running_name_) { |
52 | 17 | CheckNSkipName(cursor, end); | |
53 | 17 | CheckNSkipChar(cursor, end, '='); | |
54 | 17 | CheckElementData(cursor, end); | |
55 | } | ||
56 | 63 | DeserializeBoolean(cursor, end, ret); | |
57 | 59 | CheckSeparator(cursor, end); | |
58 | 58 | ret.push_back(','); | |
59 | } | ||
60 | 26 | } | |
61 | |||
62 | 30 | inline void DeserializeIntegerArray(const char*& cursor, const char* const end, std::string& ret) const | |
63 | { | ||
64 |
2/2✓ Branch 0 taken 60 times.
✓ Branch 1 taken 19 times.
|
79 | while (cursor < end) { |
65 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 42 times.
|
60 | if (has_running_name_) { |
66 | 18 | CheckNSkipName(cursor, end); | |
67 | 18 | CheckNSkipChar(cursor, end, '='); | |
68 | 18 | CheckElementData(cursor, end); | |
69 | } | ||
70 | 60 | DeserializeInteger(cursor, end, ret); | |
71 | 54 | CheckSeparator(cursor, end); | |
72 | 49 | ret.push_back(','); | |
73 | } | ||
74 | 19 | } | |
75 | |||
76 | 21 | inline void DeserializeNumberArray(const char*& cursor, const char* const end, std::string& ret) const | |
77 | { | ||
78 |
2/2✓ Branch 0 taken 47 times.
✓ Branch 1 taken 16 times.
|
63 | while (cursor < end) { |
79 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 31 times.
|
47 | if (has_running_name_) { |
80 | 16 | CheckNSkipName(cursor, end); | |
81 | 16 | CheckNSkipChar(cursor, end, '='); | |
82 | 16 | CheckElementData(cursor, end); | |
83 | } | ||
84 | 47 | DeserializeNumber(cursor, end, ret); | |
85 | 42 | CheckSeparator(cursor, end); | |
86 | 42 | ret.push_back(','); | |
87 | } | ||
88 | 16 | } | |
89 | |||
90 | 23 | inline void DeserializeStringArray(const char*& cursor, const char* const end, std::string& ret) const | |
91 | { | ||
92 |
2/2✓ Branch 0 taken 59 times.
✓ Branch 1 taken 22 times.
|
81 | while (cursor < end) { |
93 |
2/2✓ Branch 0 taken 17 times.
✓ Branch 1 taken 42 times.
|
59 | if (has_running_name_) { |
94 | 17 | CheckNSkipName(cursor, end); | |
95 | 17 | CheckNSkipChar(cursor, end, '='); | |
96 | 17 | CheckElementData(cursor, end); | |
97 | } | ||
98 | 59 | DeserializeString(cursor, end, separator_, ret); | |
99 | 58 | CheckSeparator(cursor, end); | |
100 | 58 | ret.push_back(','); | |
101 | } | ||
102 | 22 | } | |
103 | }; | ||
104 | |||
105 | #endif // ARRAY_DESERIALIZER_HPP | ||
106 |