Skip to content

Commit 35088a1

Browse files
committed
move typed_array from visitor to cursor
1 parent 5b64398 commit 35088a1

4 files changed

Lines changed: 16 additions & 14 deletions

File tree

include/jsoncons/reflect/decode_traits.hpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,16 @@ template <typename T>
4040
typename std::enable_if<ext_traits::is_back_insertable<T>::value,void>::type
4141
read_typed_array(jsoncons::span<uint8_t> typed_array, typed_array_element_type element_type, T& v)
4242
{
43+
using value_type = typename T::value_type;
44+
4345
switch (element_type)
4446
{
4547
case typed_array_element_type::uint8:
4648
{
4749
auto ta = typed_array_cast<const uint8_t>(typed_array);
4850
for (auto item : ta)
4951
{
50-
v.push_back(item);
52+
v.push_back(static_cast<value_type>(item));
5153
}
5254
break;
5355
}
@@ -56,7 +58,7 @@ read_typed_array(jsoncons::span<uint8_t> typed_array, typed_array_element_type e
5658
auto ta = typed_array_cast<const uint16_t>(typed_array);
5759
for (auto item : ta)
5860
{
59-
v.push_back(item);
61+
v.push_back(static_cast<value_type>(item));
6062
}
6163
break;
6264
}
@@ -65,7 +67,7 @@ read_typed_array(jsoncons::span<uint8_t> typed_array, typed_array_element_type e
6567
auto ta = typed_array_cast<const uint32_t>(typed_array);
6668
for (auto item : ta)
6769
{
68-
v.push_back(item);
70+
v.push_back(static_cast<value_type>(item));
6971
}
7072
break;
7173
}
@@ -74,7 +76,7 @@ read_typed_array(jsoncons::span<uint8_t> typed_array, typed_array_element_type e
7476
auto ta = typed_array_cast<const uint64_t>(typed_array);
7577
for (auto item : ta)
7678
{
77-
v.push_back(item);
79+
v.push_back(static_cast<value_type>(item));
7880
}
7981
break;
8082
}
@@ -83,7 +85,7 @@ read_typed_array(jsoncons::span<uint8_t> typed_array, typed_array_element_type e
8385
auto ta = typed_array_cast<const int8_t>(typed_array);
8486
for (auto item : ta)
8587
{
86-
v.push_back(item);
88+
v.push_back(static_cast<value_type>(item));
8789
}
8890
break;
8991
}
@@ -92,7 +94,7 @@ read_typed_array(jsoncons::span<uint8_t> typed_array, typed_array_element_type e
9294
auto ta = typed_array_cast<const int16_t>(typed_array);
9395
for (auto item : ta)
9496
{
95-
v.push_back(item);
97+
v.push_back(static_cast<value_type>(item));
9698
}
9799
break;
98100
}
@@ -101,7 +103,7 @@ read_typed_array(jsoncons::span<uint8_t> typed_array, typed_array_element_type e
101103
auto ta = typed_array_cast<const int32_t>(typed_array);
102104
for (auto item : ta)
103105
{
104-
v.push_back(item);
106+
v.push_back(static_cast<value_type>(item));
105107
}
106108
break;
107109
}
@@ -110,7 +112,7 @@ read_typed_array(jsoncons::span<uint8_t> typed_array, typed_array_element_type e
110112
auto ta = typed_array_cast<const int64_t>(typed_array);
111113
for (auto item : ta)
112114
{
113-
v.push_back(item);
115+
v.push_back(static_cast<value_type>(item));
114116
}
115117
break;
116118
}
@@ -119,7 +121,7 @@ read_typed_array(jsoncons::span<uint8_t> typed_array, typed_array_element_type e
119121
auto ta = typed_array_cast<const int16_t>(typed_array);
120122
for (auto item : ta)
121123
{
122-
v.push_back(item);
124+
v.push_back(static_cast<value_type>(item));
123125
}
124126
break;
125127
}
@@ -128,7 +130,7 @@ read_typed_array(jsoncons::span<uint8_t> typed_array, typed_array_element_type e
128130
auto ta = typed_array_cast<const float>(typed_array);
129131
for (auto item : ta)
130132
{
131-
v.push_back(item);
133+
v.push_back(static_cast<value_type>(item));
132134
}
133135
break;
134136
}
@@ -137,7 +139,7 @@ read_typed_array(jsoncons::span<uint8_t> typed_array, typed_array_element_type e
137139
auto ta = typed_array_cast<const double>(typed_array);
138140
for (auto item : ta)
139141
{
140-
v.push_back(item);
142+
v.push_back(static_cast<value_type>(item));
141143
}
142144
break;
143145
}

include/jsoncons/staj_cursor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ class basic_staj_cursor
315315
return typed_array_element_type{};
316316
}
317317

318-
virtual jsoncons::span<uint8_t> typed_array() const
318+
virtual jsoncons::span<uint8_t> typed_array()
319319
{
320320
return jsoncons::span<uint8_t>{};
321321
}

include/jsoncons_ext/cbor/cbor_cursor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class basic_cbor_cursor : public basic_staj_cursor<char>, private virtual ser_co
173173
return parser_.element_type();
174174
}
175175

176-
jsoncons::span<uint8_t> typed_array() const final
176+
jsoncons::span<uint8_t> typed_array() final
177177
{
178178
return parser_.typed_array();
179179
}

include/jsoncons_ext/cbor/cbor_parser.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ class basic_cbor_parser : public ser_context
289289
return element_type_;
290290
}
291291

292-
jsoncons::span<uint8_t> typed_array() const
292+
jsoncons::span<uint8_t> typed_array()
293293
{
294294
return typed_array_;
295295
}

0 commit comments

Comments
 (0)