jsoncons 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/ext/jsoncons/extconf.rb +43 -0
- data/ext/jsoncons/jsoncons.cpp +161 -0
- data/ext/jsoncons/jsoncons.h +10 -0
- data/jsoncons.gemspec +44 -0
- data/lib/jsoncons/jsoncons/examples/input/address-book.json +13 -0
- data/lib/jsoncons/jsoncons/examples/input/books.json +28 -0
- data/lib/jsoncons/jsoncons/examples/input/countries.json +7 -0
- data/lib/jsoncons/jsoncons/examples/input/employees.json +30 -0
- data/lib/jsoncons/jsoncons/examples/input/jsonschema/name.json +15 -0
- data/lib/jsoncons/jsoncons/examples/input/multiple-json-objects.json +3 -0
- data/lib/jsoncons/jsoncons/examples/input/sales.csv +6 -0
- data/lib/jsoncons/jsoncons/examples/input/store.json +28 -0
- data/lib/jsoncons/jsoncons/examples/input/tasks.csv +6 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/allocator_holder.hpp +38 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/basic_json.hpp +5905 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/bigint.hpp +1611 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/byte_string.hpp +820 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/config/binary_config.hpp +226 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/config/compiler_support.hpp +375 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/config/jsoncons_config.hpp +309 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/config/version.hpp +40 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/conv_error.hpp +218 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/decode_json.hpp +209 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/decode_traits.hpp +651 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/endian.hpp +44 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/grisu3.hpp +312 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/optional.hpp +483 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/parse_number.hpp +1133 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/span.hpp +188 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/string_view.hpp +537 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/string_wrapper.hpp +370 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/write_number.hpp +567 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/encode_json.hpp +315 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/encode_traits.hpp +378 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json.hpp +18 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_array.hpp +324 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_content_handler.hpp +12 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_cursor.hpp +448 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_decoder.hpp +420 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_encoder.hpp +1587 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_error.hpp +156 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_exception.hpp +241 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_filter.hpp +653 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_fwd.hpp +23 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_object.hpp +1772 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_options.hpp +862 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_parser.hpp +2900 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_reader.hpp +731 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_traits_macros.hpp +1072 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_traits_macros_deprecated.hpp +144 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_type.hpp +206 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_type_traits.hpp +1830 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_visitor.hpp +1560 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_visitor2.hpp +2079 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/pretty_print.hpp +89 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/ser_context.hpp +62 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/sink.hpp +289 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/source.hpp +777 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/source_adaptor.hpp +148 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/staj2_cursor.hpp +1189 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/staj_cursor.hpp +1254 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/staj_iterator.hpp +449 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/tag_type.hpp +245 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/text_source_adaptor.hpp +144 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/traits_extension.hpp +884 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/typed_array_view.hpp +250 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/unicode_traits.hpp +1330 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/uri.hpp +635 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/value_converter.hpp +340 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson.hpp +23 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_cursor.hpp +320 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_decimal128.hpp +865 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_encoder.hpp +585 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_error.hpp +103 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_oid.hpp +245 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_options.hpp +75 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_parser.hpp +645 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_reader.hpp +92 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_type.hpp +44 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/decode_bson.hpp +201 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/encode_bson.hpp +144 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor.hpp +26 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_cursor.hpp +351 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_cursor2.hpp +265 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_detail.hpp +93 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_encoder.hpp +1766 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_error.hpp +105 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_options.hpp +113 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_parser.hpp +1942 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_reader.hpp +116 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/decode_cbor.hpp +203 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/encode_cbor.hpp +151 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv.hpp +17 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_cursor.hpp +358 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_encoder.hpp +954 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_error.hpp +85 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_options.hpp +973 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_parser.hpp +2099 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_reader.hpp +348 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_serializer.hpp +12 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/decode_csv.hpp +208 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/encode_csv.hpp +122 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jmespath/jmespath.hpp +5215 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jmespath/jmespath_error.hpp +215 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpatch/jsonpatch.hpp +579 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpatch/jsonpatch_error.hpp +121 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/expression.hpp +3329 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/flatten.hpp +432 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/json_location.hpp +445 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/json_query.hpp +115 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath.hpp +13 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_error.hpp +240 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp +2612 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_selector.hpp +1322 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpointer/jsonpointer.hpp +1577 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpointer/jsonpointer_error.hpp +119 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/format_validator.hpp +968 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/json_validator.hpp +120 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema.hpp +13 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema_error.hpp +105 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema_version.hpp +18 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/keyword_validator.hpp +1745 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/keyword_validator_factory.hpp +556 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_draft7.hpp +198 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_location.hpp +200 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_version.hpp +35 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/subschema.hpp +144 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/mergepatch/mergepatch.hpp +103 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/decode_msgpack.hpp +202 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/encode_msgpack.hpp +142 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack.hpp +24 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_cursor.hpp +343 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_cursor2.hpp +259 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_encoder.hpp +753 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_error.hpp +94 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_options.hpp +74 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_parser.hpp +748 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_reader.hpp +116 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_type.hpp +63 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/decode_ubjson.hpp +201 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/encode_ubjson.hpp +142 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson.hpp +23 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_cursor.hpp +307 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_encoder.hpp +502 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_error.hpp +100 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_options.hpp +87 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_parser.hpp +880 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_reader.hpp +92 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_type.hpp +43 -0
- data/lib/jsoncons/version.rb +5 -0
- data/lib/jsoncons.rb +33 -0
- data/test/jsoncons_test.rb +108 -0
- data/test/test_helper.rb +7 -0
- metadata +268 -0
|
@@ -0,0 +1,651 @@
|
|
|
1
|
+
// Copyright 2017 Daniel Parker
|
|
2
|
+
// Distributed under the Boost license, Version 1.0.
|
|
3
|
+
// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
4
|
+
|
|
5
|
+
// See https://github.com/danielaparker/jsoncons for latest version
|
|
6
|
+
|
|
7
|
+
#ifndef JSONCONS_DECODE_TRAITS_HPP
|
|
8
|
+
#define JSONCONS_DECODE_TRAITS_HPP
|
|
9
|
+
|
|
10
|
+
#include <string>
|
|
11
|
+
#include <tuple>
|
|
12
|
+
#include <array>
|
|
13
|
+
#include <memory>
|
|
14
|
+
#include <type_traits> // std::enable_if, std::true_type, std::false_type
|
|
15
|
+
#include <jsoncons/json_visitor.hpp>
|
|
16
|
+
#include <jsoncons/json_decoder.hpp>
|
|
17
|
+
#include <jsoncons/json_type_traits.hpp>
|
|
18
|
+
#include <jsoncons/staj_cursor.hpp>
|
|
19
|
+
#include <jsoncons/conv_error.hpp>
|
|
20
|
+
#include <jsoncons/traits_extension.hpp>
|
|
21
|
+
|
|
22
|
+
namespace jsoncons {
|
|
23
|
+
|
|
24
|
+
// decode_traits
|
|
25
|
+
|
|
26
|
+
template <class T, class CharT, class Enable = void>
|
|
27
|
+
struct decode_traits
|
|
28
|
+
{
|
|
29
|
+
template <class Json,class TempAllocator>
|
|
30
|
+
static T decode(basic_staj_cursor<CharT>& cursor,
|
|
31
|
+
json_decoder<Json,TempAllocator>& decoder,
|
|
32
|
+
std::error_code& ec)
|
|
33
|
+
{
|
|
34
|
+
decoder.reset();
|
|
35
|
+
cursor.read_to(decoder, ec);
|
|
36
|
+
if (ec)
|
|
37
|
+
{
|
|
38
|
+
JSONCONS_THROW(ser_error(ec, cursor.context().line(), cursor.context().column()));
|
|
39
|
+
}
|
|
40
|
+
else if (!decoder.is_valid())
|
|
41
|
+
{
|
|
42
|
+
JSONCONS_THROW(ser_error(conv_errc::conversion_failed, cursor.context().line(), cursor.context().column()));
|
|
43
|
+
}
|
|
44
|
+
return decoder.get_result().template as<T>();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// specializations
|
|
49
|
+
|
|
50
|
+
// primitive
|
|
51
|
+
|
|
52
|
+
template <class T, class CharT>
|
|
53
|
+
struct decode_traits<T,CharT,
|
|
54
|
+
typename std::enable_if<traits_extension::is_primitive<T>::value
|
|
55
|
+
>::type>
|
|
56
|
+
{
|
|
57
|
+
template <class Json,class TempAllocator>
|
|
58
|
+
static T decode(basic_staj_cursor<CharT>& cursor,
|
|
59
|
+
json_decoder<Json,TempAllocator>&,
|
|
60
|
+
std::error_code& ec)
|
|
61
|
+
{
|
|
62
|
+
T v = cursor.current().template get<T>(ec);
|
|
63
|
+
return v;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// string
|
|
68
|
+
|
|
69
|
+
template <class T, class CharT>
|
|
70
|
+
struct decode_traits<T,CharT,
|
|
71
|
+
typename std::enable_if<traits_extension::is_string<T>::value &&
|
|
72
|
+
std::is_same<typename T::value_type,CharT>::value
|
|
73
|
+
>::type>
|
|
74
|
+
{
|
|
75
|
+
template <class Json,class TempAllocator>
|
|
76
|
+
static T decode(basic_staj_cursor<CharT>& cursor,
|
|
77
|
+
json_decoder<Json,TempAllocator>&,
|
|
78
|
+
std::error_code& ec)
|
|
79
|
+
{
|
|
80
|
+
T v = cursor.current().template get<T>(ec);
|
|
81
|
+
return v;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
template <class T, class CharT>
|
|
86
|
+
struct decode_traits<T,CharT,
|
|
87
|
+
typename std::enable_if<traits_extension::is_string<T>::value &&
|
|
88
|
+
!std::is_same<typename T::value_type,CharT>::value
|
|
89
|
+
>::type>
|
|
90
|
+
{
|
|
91
|
+
template <class Json,class TempAllocator>
|
|
92
|
+
static T decode(basic_staj_cursor<CharT>& cursor,
|
|
93
|
+
json_decoder<Json,TempAllocator>&,
|
|
94
|
+
std::error_code& ec)
|
|
95
|
+
{
|
|
96
|
+
auto val = cursor.current().template get<std::basic_string<CharT>>(ec);
|
|
97
|
+
T s;
|
|
98
|
+
if (!ec)
|
|
99
|
+
{
|
|
100
|
+
unicode_traits::convert(val.data(), val.size(), s);
|
|
101
|
+
}
|
|
102
|
+
return s;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// std::pair
|
|
107
|
+
|
|
108
|
+
template <class T1, class T2, class CharT>
|
|
109
|
+
struct decode_traits<std::pair<T1, T2>, CharT>
|
|
110
|
+
{
|
|
111
|
+
template <class Json, class TempAllocator>
|
|
112
|
+
static std::pair<T1, T2> decode(basic_staj_cursor<CharT>& cursor,
|
|
113
|
+
json_decoder<Json, TempAllocator>& decoder,
|
|
114
|
+
std::error_code& ec)
|
|
115
|
+
{
|
|
116
|
+
using value_type = std::pair<T1, T2>;
|
|
117
|
+
cursor.array_expected(ec);
|
|
118
|
+
if (ec)
|
|
119
|
+
{
|
|
120
|
+
return value_type{};
|
|
121
|
+
}
|
|
122
|
+
if (cursor.current().event_type() != staj_event_type::begin_array)
|
|
123
|
+
{
|
|
124
|
+
ec = conv_errc::not_pair;
|
|
125
|
+
return value_type();
|
|
126
|
+
}
|
|
127
|
+
cursor.next(ec); // skip past array
|
|
128
|
+
if (ec)
|
|
129
|
+
{
|
|
130
|
+
return value_type();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
T1 v1 = decode_traits<T1,CharT>::decode(cursor, decoder, ec);
|
|
134
|
+
if (ec) {return value_type();}
|
|
135
|
+
cursor.next(ec);
|
|
136
|
+
if (ec) {return value_type();}
|
|
137
|
+
T2 v2 = decode_traits<T2, CharT>::decode(cursor, decoder, ec);
|
|
138
|
+
if (ec) {return value_type();}
|
|
139
|
+
cursor.next(ec);
|
|
140
|
+
|
|
141
|
+
if (cursor.current().event_type() != staj_event_type::end_array)
|
|
142
|
+
{
|
|
143
|
+
ec = conv_errc::not_pair;
|
|
144
|
+
return value_type();
|
|
145
|
+
}
|
|
146
|
+
return std::make_pair(v1, v2);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// vector like
|
|
151
|
+
template <class T, class CharT>
|
|
152
|
+
struct decode_traits<T,CharT,
|
|
153
|
+
typename std::enable_if<!is_json_type_traits_declared<T>::value &&
|
|
154
|
+
traits_extension::is_list_like<T>::value &&
|
|
155
|
+
traits_extension::is_back_insertable<T>::value &&
|
|
156
|
+
!traits_extension::is_typed_array<T>::value
|
|
157
|
+
>::type>
|
|
158
|
+
{
|
|
159
|
+
using value_type = typename T::value_type;
|
|
160
|
+
|
|
161
|
+
template <class Json,class TempAllocator>
|
|
162
|
+
static T decode(basic_staj_cursor<CharT>& cursor,
|
|
163
|
+
json_decoder<Json,TempAllocator>& decoder,
|
|
164
|
+
std::error_code& ec)
|
|
165
|
+
{
|
|
166
|
+
T v;
|
|
167
|
+
|
|
168
|
+
cursor.array_expected(ec);
|
|
169
|
+
if (ec)
|
|
170
|
+
{
|
|
171
|
+
return T{};
|
|
172
|
+
}
|
|
173
|
+
if (cursor.current().event_type() != staj_event_type::begin_array)
|
|
174
|
+
{
|
|
175
|
+
ec = conv_errc::not_vector;
|
|
176
|
+
return v;
|
|
177
|
+
}
|
|
178
|
+
cursor.next(ec);
|
|
179
|
+
while (cursor.current().event_type() != staj_event_type::end_array && !ec)
|
|
180
|
+
{
|
|
181
|
+
v.push_back(decode_traits<value_type,CharT>::decode(cursor, decoder, ec));
|
|
182
|
+
if (ec) {return T{};}
|
|
183
|
+
cursor.next(ec);
|
|
184
|
+
}
|
|
185
|
+
return v;
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
template <class T>
|
|
190
|
+
struct typed_array_visitor : public default_json_visitor
|
|
191
|
+
{
|
|
192
|
+
T& v_;
|
|
193
|
+
int level_;
|
|
194
|
+
public:
|
|
195
|
+
using value_type = typename T::value_type;
|
|
196
|
+
|
|
197
|
+
typed_array_visitor(T& v)
|
|
198
|
+
: default_json_visitor(false,conv_errc::not_vector), v_(v), level_(0)
|
|
199
|
+
{
|
|
200
|
+
}
|
|
201
|
+
private:
|
|
202
|
+
bool visit_begin_array(semantic_tag,
|
|
203
|
+
const ser_context&,
|
|
204
|
+
std::error_code& ec) override
|
|
205
|
+
{
|
|
206
|
+
if (++level_ != 1)
|
|
207
|
+
{
|
|
208
|
+
ec = conv_errc::not_vector;
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
return true;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
bool visit_begin_array(std::size_t size,
|
|
215
|
+
semantic_tag,
|
|
216
|
+
const ser_context&,
|
|
217
|
+
std::error_code& ec) override
|
|
218
|
+
{
|
|
219
|
+
if (++level_ != 1)
|
|
220
|
+
{
|
|
221
|
+
ec = conv_errc::not_vector;
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
if (size > 0)
|
|
225
|
+
{
|
|
226
|
+
reserve_storage(typename std::integral_constant<bool, traits_extension::has_reserve<T>::value>::type(), v_, size);
|
|
227
|
+
}
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
bool visit_end_array(const ser_context&,
|
|
232
|
+
std::error_code& ec) override
|
|
233
|
+
{
|
|
234
|
+
if (level_ != 1)
|
|
235
|
+
{
|
|
236
|
+
ec = conv_errc::not_vector;
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
bool visit_uint64(uint64_t value,
|
|
243
|
+
semantic_tag,
|
|
244
|
+
const ser_context&,
|
|
245
|
+
std::error_code&) override
|
|
246
|
+
{
|
|
247
|
+
v_.push_back(static_cast<value_type>(value));
|
|
248
|
+
return true;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
bool visit_int64(int64_t value,
|
|
252
|
+
semantic_tag,
|
|
253
|
+
const ser_context&,
|
|
254
|
+
std::error_code&) override
|
|
255
|
+
{
|
|
256
|
+
v_.push_back(static_cast<value_type>(value));
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
bool visit_half(uint16_t value,
|
|
261
|
+
semantic_tag,
|
|
262
|
+
const ser_context&,
|
|
263
|
+
std::error_code&) override
|
|
264
|
+
{
|
|
265
|
+
return visit_half_(typename std::integral_constant<bool, std::is_integral<value_type>::value>::type(), value);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
bool visit_half_(std::true_type, uint16_t value)
|
|
269
|
+
{
|
|
270
|
+
v_.push_back(static_cast<value_type>(value));
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
bool visit_half_(std::false_type, uint16_t value)
|
|
275
|
+
{
|
|
276
|
+
v_.push_back(static_cast<value_type>(binary::decode_half(value)));
|
|
277
|
+
return true;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
bool visit_double(double value,
|
|
281
|
+
semantic_tag,
|
|
282
|
+
const ser_context&,
|
|
283
|
+
std::error_code&) override
|
|
284
|
+
{
|
|
285
|
+
v_.push_back(static_cast<value_type>(value));
|
|
286
|
+
return true;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
bool visit_typed_array(const jsoncons::span<const value_type>& data,
|
|
290
|
+
semantic_tag,
|
|
291
|
+
const ser_context&,
|
|
292
|
+
std::error_code&) override
|
|
293
|
+
{
|
|
294
|
+
v_ = std::vector<value_type>(data.begin(),data.end());
|
|
295
|
+
return false;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
static
|
|
299
|
+
void reserve_storage(std::true_type, T& v, std::size_t new_cap)
|
|
300
|
+
{
|
|
301
|
+
v.reserve(new_cap);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
static
|
|
305
|
+
void reserve_storage(std::false_type, T&, std::size_t)
|
|
306
|
+
{
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
template <class T, class CharT>
|
|
311
|
+
struct decode_traits<T,CharT,
|
|
312
|
+
typename std::enable_if<!is_json_type_traits_declared<T>::value &&
|
|
313
|
+
traits_extension::is_list_like<T>::value &&
|
|
314
|
+
traits_extension::is_back_insertable_byte_container<T>::value &&
|
|
315
|
+
traits_extension::is_typed_array<T>::value
|
|
316
|
+
>::type>
|
|
317
|
+
{
|
|
318
|
+
using value_type = typename T::value_type;
|
|
319
|
+
|
|
320
|
+
template <class Json,class TempAllocator>
|
|
321
|
+
static T decode(basic_staj_cursor<CharT>& cursor,
|
|
322
|
+
json_decoder<Json,TempAllocator>&,
|
|
323
|
+
std::error_code& ec)
|
|
324
|
+
{
|
|
325
|
+
cursor.array_expected(ec);
|
|
326
|
+
if (ec)
|
|
327
|
+
{
|
|
328
|
+
return T{};
|
|
329
|
+
}
|
|
330
|
+
switch (cursor.current().event_type())
|
|
331
|
+
{
|
|
332
|
+
case staj_event_type::byte_string_value:
|
|
333
|
+
{
|
|
334
|
+
auto bytes = cursor.current().template get<byte_string_view>(ec);
|
|
335
|
+
if (!ec)
|
|
336
|
+
{
|
|
337
|
+
T v;
|
|
338
|
+
if (cursor.current().size() > 0)
|
|
339
|
+
{
|
|
340
|
+
reserve_storage(typename std::integral_constant<bool, traits_extension::has_reserve<T>::value>::type(), v, cursor.current().size());
|
|
341
|
+
}
|
|
342
|
+
for (auto ch : bytes)
|
|
343
|
+
{
|
|
344
|
+
v.push_back(static_cast<value_type>(ch));
|
|
345
|
+
}
|
|
346
|
+
cursor.next(ec);
|
|
347
|
+
return v;
|
|
348
|
+
}
|
|
349
|
+
else
|
|
350
|
+
{
|
|
351
|
+
return T{};
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
case staj_event_type::begin_array:
|
|
355
|
+
{
|
|
356
|
+
T v;
|
|
357
|
+
if (cursor.current().size() > 0)
|
|
358
|
+
{
|
|
359
|
+
reserve_storage(typename std::integral_constant<bool, traits_extension::has_reserve<T>::value>::type(), v, cursor.current().size());
|
|
360
|
+
}
|
|
361
|
+
typed_array_visitor<T> visitor(v);
|
|
362
|
+
cursor.read_to(visitor, ec);
|
|
363
|
+
return v;
|
|
364
|
+
}
|
|
365
|
+
default:
|
|
366
|
+
{
|
|
367
|
+
ec = conv_errc::not_vector;
|
|
368
|
+
return T{};
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
static void reserve_storage(std::true_type, T& v, std::size_t new_cap)
|
|
374
|
+
{
|
|
375
|
+
v.reserve(new_cap);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
static void reserve_storage(std::false_type, T&, std::size_t)
|
|
379
|
+
{
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
template <class T, class CharT>
|
|
384
|
+
struct decode_traits<T,CharT,
|
|
385
|
+
typename std::enable_if<!is_json_type_traits_declared<T>::value &&
|
|
386
|
+
traits_extension::is_list_like<T>::value &&
|
|
387
|
+
traits_extension::is_back_insertable<T>::value &&
|
|
388
|
+
!traits_extension::is_back_insertable_byte_container<T>::value &&
|
|
389
|
+
traits_extension::is_typed_array<T>::value
|
|
390
|
+
>::type>
|
|
391
|
+
{
|
|
392
|
+
using value_type = typename T::value_type;
|
|
393
|
+
|
|
394
|
+
template <class Json,class TempAllocator>
|
|
395
|
+
static T decode(basic_staj_cursor<CharT>& cursor,
|
|
396
|
+
json_decoder<Json,TempAllocator>&,
|
|
397
|
+
std::error_code& ec)
|
|
398
|
+
{
|
|
399
|
+
cursor.array_expected(ec);
|
|
400
|
+
if (ec)
|
|
401
|
+
{
|
|
402
|
+
return T{};
|
|
403
|
+
}
|
|
404
|
+
switch (cursor.current().event_type())
|
|
405
|
+
{
|
|
406
|
+
case staj_event_type::begin_array:
|
|
407
|
+
{
|
|
408
|
+
T v;
|
|
409
|
+
if (cursor.current().size() > 0)
|
|
410
|
+
{
|
|
411
|
+
reserve_storage(typename std::integral_constant<bool, traits_extension::has_reserve<T>::value>::type(), v, cursor.current().size());
|
|
412
|
+
}
|
|
413
|
+
typed_array_visitor<T> visitor(v);
|
|
414
|
+
cursor.read_to(visitor, ec);
|
|
415
|
+
return v;
|
|
416
|
+
}
|
|
417
|
+
default:
|
|
418
|
+
{
|
|
419
|
+
ec = conv_errc::not_vector;
|
|
420
|
+
return T{};
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
static void reserve_storage(std::true_type, T& v, std::size_t new_cap)
|
|
426
|
+
{
|
|
427
|
+
v.reserve(new_cap);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
static void reserve_storage(std::false_type, T&, std::size_t)
|
|
431
|
+
{
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
// set like
|
|
436
|
+
template <class T, class CharT>
|
|
437
|
+
struct decode_traits<T,CharT,
|
|
438
|
+
typename std::enable_if<!is_json_type_traits_declared<T>::value &&
|
|
439
|
+
traits_extension::is_list_like<T>::value &&
|
|
440
|
+
!traits_extension::is_back_insertable<T>::value &&
|
|
441
|
+
traits_extension::is_insertable<T>::value
|
|
442
|
+
>::type>
|
|
443
|
+
{
|
|
444
|
+
using value_type = typename T::value_type;
|
|
445
|
+
|
|
446
|
+
template <class Json,class TempAllocator>
|
|
447
|
+
static T decode(basic_staj_cursor<CharT>& cursor,
|
|
448
|
+
json_decoder<Json,TempAllocator>& decoder,
|
|
449
|
+
std::error_code& ec)
|
|
450
|
+
{
|
|
451
|
+
T v;
|
|
452
|
+
|
|
453
|
+
cursor.array_expected(ec);
|
|
454
|
+
if (ec)
|
|
455
|
+
{
|
|
456
|
+
return T{};
|
|
457
|
+
}
|
|
458
|
+
if (cursor.current().event_type() != staj_event_type::begin_array)
|
|
459
|
+
{
|
|
460
|
+
ec = conv_errc::not_vector;
|
|
461
|
+
return v;
|
|
462
|
+
}
|
|
463
|
+
if (cursor.current().size() > 0)
|
|
464
|
+
{
|
|
465
|
+
reserve_storage(typename std::integral_constant<bool, traits_extension::has_reserve<T>::value>::type(), v, cursor.current().size());
|
|
466
|
+
}
|
|
467
|
+
cursor.next(ec);
|
|
468
|
+
while (cursor.current().event_type() != staj_event_type::end_array && !ec)
|
|
469
|
+
{
|
|
470
|
+
v.insert(decode_traits<value_type,CharT>::decode(cursor, decoder, ec));
|
|
471
|
+
if (ec) {return T{};}
|
|
472
|
+
cursor.next(ec);
|
|
473
|
+
if (ec) {return T{};}
|
|
474
|
+
}
|
|
475
|
+
return v;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
static void reserve_storage(std::true_type, T& v, std::size_t new_cap)
|
|
479
|
+
{
|
|
480
|
+
v.reserve(new_cap);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
static void reserve_storage(std::false_type, T&, std::size_t)
|
|
484
|
+
{
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
// std::array
|
|
489
|
+
|
|
490
|
+
template <class T, class CharT, std::size_t N>
|
|
491
|
+
struct decode_traits<std::array<T,N>,CharT>
|
|
492
|
+
{
|
|
493
|
+
using value_type = typename std::array<T,N>::value_type;
|
|
494
|
+
|
|
495
|
+
template <class Json,class TempAllocator>
|
|
496
|
+
static std::array<T, N> decode(basic_staj_cursor<CharT>& cursor,
|
|
497
|
+
json_decoder<Json,TempAllocator>& decoder,
|
|
498
|
+
std::error_code& ec)
|
|
499
|
+
{
|
|
500
|
+
std::array<T,N> v;
|
|
501
|
+
cursor.array_expected(ec);
|
|
502
|
+
if (ec)
|
|
503
|
+
{
|
|
504
|
+
v.fill(T());
|
|
505
|
+
return v;
|
|
506
|
+
}
|
|
507
|
+
v.fill(T{});
|
|
508
|
+
if (cursor.current().event_type() != staj_event_type::begin_array)
|
|
509
|
+
{
|
|
510
|
+
ec = conv_errc::not_vector;
|
|
511
|
+
return v;
|
|
512
|
+
}
|
|
513
|
+
cursor.next(ec);
|
|
514
|
+
for (std::size_t i = 0; i < N && cursor.current().event_type() != staj_event_type::end_array && !ec; ++i)
|
|
515
|
+
{
|
|
516
|
+
v[i] = decode_traits<value_type,CharT>::decode(cursor, decoder, ec);
|
|
517
|
+
if (ec) {return v;}
|
|
518
|
+
cursor.next(ec);
|
|
519
|
+
if (ec) {return v;}
|
|
520
|
+
}
|
|
521
|
+
return v;
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
// map like
|
|
526
|
+
|
|
527
|
+
template <class T, class CharT>
|
|
528
|
+
struct decode_traits<T,CharT,
|
|
529
|
+
typename std::enable_if<!is_json_type_traits_declared<T>::value &&
|
|
530
|
+
traits_extension::is_map_like<T>::value &&
|
|
531
|
+
traits_extension::is_constructible_from_const_pointer_and_size<typename T::key_type>::value
|
|
532
|
+
>::type>
|
|
533
|
+
{
|
|
534
|
+
using mapped_type = typename T::mapped_type;
|
|
535
|
+
using value_type = typename T::value_type;
|
|
536
|
+
using key_type = typename T::key_type;
|
|
537
|
+
|
|
538
|
+
template <class Json,class TempAllocator>
|
|
539
|
+
static T decode(basic_staj_cursor<CharT>& cursor,
|
|
540
|
+
json_decoder<Json,TempAllocator>& decoder,
|
|
541
|
+
std::error_code& ec)
|
|
542
|
+
{
|
|
543
|
+
T val;
|
|
544
|
+
if (cursor.current().event_type() != staj_event_type::begin_object)
|
|
545
|
+
{
|
|
546
|
+
ec = conv_errc::not_map;
|
|
547
|
+
return val;
|
|
548
|
+
}
|
|
549
|
+
if (cursor.current().size() > 0)
|
|
550
|
+
{
|
|
551
|
+
reserve_storage(typename std::integral_constant<bool, traits_extension::has_reserve<T>::value>::type(), val, cursor.current().size());
|
|
552
|
+
}
|
|
553
|
+
cursor.next(ec);
|
|
554
|
+
|
|
555
|
+
while (cursor.current().event_type() != staj_event_type::end_object && !ec)
|
|
556
|
+
{
|
|
557
|
+
if (cursor.current().event_type() != staj_event_type::key)
|
|
558
|
+
{
|
|
559
|
+
ec = json_errc::expected_key;
|
|
560
|
+
return val;
|
|
561
|
+
}
|
|
562
|
+
auto key = cursor.current().template get<key_type>(ec);
|
|
563
|
+
if (ec) return val;
|
|
564
|
+
cursor.next(ec);
|
|
565
|
+
if (ec) return val;
|
|
566
|
+
val.emplace(std::move(key),decode_traits<mapped_type,CharT>::decode(cursor, decoder, ec));
|
|
567
|
+
if (ec) {return val;}
|
|
568
|
+
cursor.next(ec);
|
|
569
|
+
if (ec) {return val;}
|
|
570
|
+
}
|
|
571
|
+
return val;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
static void reserve_storage(std::true_type, T& v, std::size_t new_cap)
|
|
575
|
+
{
|
|
576
|
+
v.reserve(new_cap);
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
static void reserve_storage(std::false_type, T&, std::size_t)
|
|
580
|
+
{
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
template <class T, class CharT>
|
|
585
|
+
struct decode_traits<T,CharT,
|
|
586
|
+
typename std::enable_if<!is_json_type_traits_declared<T>::value &&
|
|
587
|
+
traits_extension::is_map_like<T>::value &&
|
|
588
|
+
std::is_integral<typename T::key_type>::value
|
|
589
|
+
>::type>
|
|
590
|
+
{
|
|
591
|
+
using mapped_type = typename T::mapped_type;
|
|
592
|
+
using value_type = typename T::value_type;
|
|
593
|
+
using key_type = typename T::key_type;
|
|
594
|
+
|
|
595
|
+
template <class Json,class TempAllocator>
|
|
596
|
+
static T decode(basic_staj_cursor<CharT>& cursor,
|
|
597
|
+
json_decoder<Json,TempAllocator>& decoder,
|
|
598
|
+
std::error_code& ec)
|
|
599
|
+
{
|
|
600
|
+
T val;
|
|
601
|
+
if (cursor.current().event_type() != staj_event_type::begin_object)
|
|
602
|
+
{
|
|
603
|
+
ec = conv_errc::not_map;
|
|
604
|
+
return val;
|
|
605
|
+
}
|
|
606
|
+
if (cursor.current().size() > 0)
|
|
607
|
+
{
|
|
608
|
+
reserve_storage(typename std::integral_constant<bool, traits_extension::has_reserve<T>::value>::type(), val, cursor.current().size());
|
|
609
|
+
}
|
|
610
|
+
cursor.next(ec);
|
|
611
|
+
|
|
612
|
+
while (cursor.current().event_type() != staj_event_type::end_object && !ec)
|
|
613
|
+
{
|
|
614
|
+
if (cursor.current().event_type() != staj_event_type::key)
|
|
615
|
+
{
|
|
616
|
+
ec = json_errc::expected_key;
|
|
617
|
+
return val;
|
|
618
|
+
}
|
|
619
|
+
auto s = cursor.current().template get<jsoncons::basic_string_view<typename Json::char_type>>(ec);
|
|
620
|
+
if (ec) return val;
|
|
621
|
+
key_type n{0};
|
|
622
|
+
auto r = jsoncons::detail::to_integer(s.data(), s.size(), n);
|
|
623
|
+
if (r.ec != jsoncons::detail::to_integer_errc())
|
|
624
|
+
{
|
|
625
|
+
ec = json_errc::invalid_number;
|
|
626
|
+
return val;
|
|
627
|
+
}
|
|
628
|
+
cursor.next(ec);
|
|
629
|
+
if (ec) return val;
|
|
630
|
+
val.emplace(n, decode_traits<mapped_type,CharT>::decode(cursor, decoder, ec));
|
|
631
|
+
if (ec) {return val;}
|
|
632
|
+
cursor.next(ec);
|
|
633
|
+
if (ec) {return val;}
|
|
634
|
+
}
|
|
635
|
+
return val;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
static void reserve_storage(std::true_type, T& v, std::size_t new_cap)
|
|
639
|
+
{
|
|
640
|
+
v.reserve(new_cap);
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
static void reserve_storage(std::false_type, T&, std::size_t)
|
|
644
|
+
{
|
|
645
|
+
}
|
|
646
|
+
};
|
|
647
|
+
|
|
648
|
+
} // jsoncons
|
|
649
|
+
|
|
650
|
+
#endif
|
|
651
|
+
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Copyright 2020 Daniel Parker
|
|
2
|
+
// Distributed under the Boost license, Version 1.0.
|
|
3
|
+
// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
4
|
+
|
|
5
|
+
// See https://github.com/danielaparker/jsoncons for latest version
|
|
6
|
+
|
|
7
|
+
#ifndef JSONCONS_DETAIL_ENDIAN_HPP
|
|
8
|
+
#define JSONCONS_DETAIL_ENDIAN_HPP
|
|
9
|
+
|
|
10
|
+
#if defined(__sun)
|
|
11
|
+
# include <sys/byteorder.h>
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
namespace jsoncons {
|
|
15
|
+
namespace detail {
|
|
16
|
+
|
|
17
|
+
enum class endian
|
|
18
|
+
{
|
|
19
|
+
#if defined(_MSC_VER)
|
|
20
|
+
// MSVC, which implies Windows, which implies little-endian
|
|
21
|
+
little = 0,
|
|
22
|
+
big = 1,
|
|
23
|
+
native = little
|
|
24
|
+
#elif defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__) && defined(__BYTE_ORDER__)
|
|
25
|
+
little = __ORDER_LITTLE_ENDIAN__,
|
|
26
|
+
big = __ORDER_BIG_ENDIAN__,
|
|
27
|
+
native = __BYTE_ORDER__
|
|
28
|
+
#elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
|
|
29
|
+
little = 0,
|
|
30
|
+
big = 1,
|
|
31
|
+
native = big
|
|
32
|
+
#elif !defined(_BIG_ENDIAN) && defined(_LITTLE_ENDIAN)
|
|
33
|
+
little = 0,
|
|
34
|
+
big = 1,
|
|
35
|
+
native = little
|
|
36
|
+
#else
|
|
37
|
+
#error "Unable to determine byte order!"
|
|
38
|
+
#endif
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
} // namespace detail
|
|
42
|
+
} // namespace jsoncons
|
|
43
|
+
|
|
44
|
+
#endif
|