Skip to content

Commit 6f82084

Browse files
committed
xxx_encoder options
1 parent 98d4396 commit 6f82084

File tree

10 files changed

+74
-57
lines changed

10 files changed

+74
-57
lines changed

doc/ref/deprecated.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,16 @@ Category/class|Old name|Replacement
2727
 |`csv::basic_csv_cursor` constructor overloads that take an `err_handler` argument|
2828
`csv::result_options`| | 
2929
 |**csv::result_options::value**|Use `csv::result_options{}` instead
30+
`json_type`| | 
31+
 |**json_type::null_value**|Use `json_type::null` instead
32+
 |**json_type::bool_value**|Use `json_type::boolean` instead
33+
 |**json_type::int64_value**|Use `json_type::int64` instead
34+
 |**json_type::uint64_value**|Use `json_type::uint64` instead
35+
 |**json_type::half_value**|Use `json_type::float16` instead
36+
 |**json_type::double_value**|Use `json_type::float64` instead
37+
 |**json_type::string_value**|Use `json_type::string` instead
38+
 |**json_type::byte_string_value**|Use `json_type::byte_string` instead
39+
 |**json_type::array_value**|Use `json_type::array` instead
40+
 |**json_type::object_value**|Use `json_type::object` instead
3041

3142

include/jsoncons_ext/bson/bson_encoder.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class basic_bson_encoder final : public basic_json_visitor<char>
9292
};
9393

9494
sink_type sink_;
95-
const bson_encode_options options_;
95+
int max_nesting_depth_;
9696
allocator_type alloc_;
9797

9898
std::vector<stack_item> stack_;
@@ -116,7 +116,7 @@ class basic_bson_encoder final : public basic_json_visitor<char>
116116
const bson_encode_options& options,
117117
const Allocator& alloc = Allocator())
118118
: sink_(std::forward<Sink>(sink)),
119-
options_(options),
119+
max_nesting_depth_(options.max_nesting_depth()),
120120
alloc_(alloc)
121121
{
122122
}
@@ -152,7 +152,7 @@ class basic_bson_encoder final : public basic_json_visitor<char>
152152

153153
JSONCONS_VISITOR_RETURN_TYPE visit_begin_object(semantic_tag, const ser_context&, std::error_code& ec) override
154154
{
155-
if (JSONCONS_UNLIKELY(++nesting_depth_ > options_.max_nesting_depth()))
155+
if (JSONCONS_UNLIKELY(++nesting_depth_ > max_nesting_depth_))
156156
{
157157
ec = bson_errc::max_nesting_depth_exceeded;
158158
JSONCONS_VISITOR_RETURN;
@@ -196,7 +196,7 @@ class basic_bson_encoder final : public basic_json_visitor<char>
196196

197197
JSONCONS_VISITOR_RETURN_TYPE visit_begin_array(semantic_tag, const ser_context&, std::error_code& ec) override
198198
{
199-
if (JSONCONS_UNLIKELY(++nesting_depth_ > options_.max_nesting_depth()))
199+
if (JSONCONS_UNLIKELY(++nesting_depth_ > max_nesting_depth_))
200200
{
201201
ec = bson_errc::max_nesting_depth_exceeded;
202202
JSONCONS_VISITOR_RETURN;

include/jsoncons_ext/bson/bson_parser.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class basic_bson_parser : public ser_context
7272
int mark_level_{0};
7373

7474
Source source_;
75-
bson_decode_options options_;
75+
int max_nesting_depth_;
7676
std::vector<uint8_t,byte_allocator_type> bytes_buffer_;
7777
string_type name_buffer_;
7878
string_type text_buffer_;
@@ -83,7 +83,7 @@ class basic_bson_parser : public ser_context
8383
const bson_decode_options& options = bson_decode_options(),
8484
const TempAlloc& temp_alloc = TempAlloc())
8585
: source_(std::forward<Sourceable>(source)),
86-
options_(options),
86+
max_nesting_depth_(options.max_nesting_depth()),
8787
bytes_buffer_(temp_alloc),
8888
name_buffer_(temp_alloc),
8989
text_buffer_(temp_alloc),
@@ -248,7 +248,7 @@ class basic_bson_parser : public ser_context
248248

249249
void begin_document(json_visitor& visitor, std::error_code& ec)
250250
{
251-
if (JSONCONS_UNLIKELY(static_cast<int>(state_stack_.size()) > options_.max_nesting_depth()))
251+
if (JSONCONS_UNLIKELY(static_cast<int>(state_stack_.size()) > max_nesting_depth_))
252252
{
253253
ec = bson_errc::max_nesting_depth_exceeded;
254254
more_ = false;
@@ -294,7 +294,7 @@ class basic_bson_parser : public ser_context
294294

295295
void begin_array(json_visitor& visitor, std::error_code& ec)
296296
{
297-
if (JSONCONS_UNLIKELY(static_cast<int>(state_stack_.size()) > options_.max_nesting_depth()))
297+
if (JSONCONS_UNLIKELY(static_cast<int>(state_stack_.size()) > max_nesting_depth_))
298298
{
299299
ec = bson_errc::max_nesting_depth_exceeded;
300300
more_ = false;

include/jsoncons_ext/cbor/cbor_encoder.hpp

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ class basic_cbor_encoder final : public basic_json_visitor<char>
103103
using stack_item_allocator_type = typename std::allocator_traits<allocator_type>:: template rebind_alloc<stack_item>;
104104

105105
Sink sink_;
106-
const cbor_encode_options options_;
106+
int max_nesting_depth_;
107+
bool pack_strings_;
108+
bool use_typed_arrays_;
107109
allocator_type alloc_;
108110

109111
std::vector<stack_item,stack_item_allocator_type> stack_;
@@ -126,7 +128,9 @@ class basic_cbor_encoder final : public basic_json_visitor<char>
126128
const cbor_encode_options& options,
127129
const Allocator& alloc = Allocator())
128130
: sink_(std::forward<Sink>(sink)),
129-
options_(options),
131+
max_nesting_depth_(options.max_nesting_depth()),
132+
pack_strings_(options.pack_strings()),
133+
use_typed_arrays_(options.use_typed_arrays()),
130134
alloc_(alloc),
131135
stack_(alloc),
132136
stringref_map_(alloc),
@@ -259,7 +263,7 @@ class basic_cbor_encoder final : public basic_json_visitor<char>
259263

260264
JSONCONS_VISITOR_RETURN_TYPE visit_begin_object(semantic_tag, const ser_context&, std::error_code& ec) override
261265
{
262-
if (JSONCONS_UNLIKELY(++nesting_depth_ > options_.max_nesting_depth()))
266+
if (JSONCONS_UNLIKELY(++nesting_depth_ > max_nesting_depth_))
263267
{
264268
ec = cbor_errc::max_nesting_depth_exceeded;
265269
JSONCONS_VISITOR_RETURN;
@@ -272,7 +276,7 @@ class basic_cbor_encoder final : public basic_json_visitor<char>
272276

273277
JSONCONS_VISITOR_RETURN_TYPE visit_begin_object(std::size_t length, semantic_tag, const ser_context&, std::error_code& ec) override
274278
{
275-
if (JSONCONS_UNLIKELY(++nesting_depth_ > options_.max_nesting_depth()))
279+
if (JSONCONS_UNLIKELY(++nesting_depth_ > max_nesting_depth_))
276280
{
277281
ec = cbor_errc::max_nesting_depth_exceeded;
278282
JSONCONS_VISITOR_RETURN;
@@ -347,7 +351,7 @@ class basic_cbor_encoder final : public basic_json_visitor<char>
347351

348352
JSONCONS_VISITOR_RETURN_TYPE visit_begin_array(semantic_tag, const ser_context&, std::error_code& ec) override
349353
{
350-
if (JSONCONS_UNLIKELY(++nesting_depth_ > options_.max_nesting_depth()))
354+
if (JSONCONS_UNLIKELY(++nesting_depth_ > max_nesting_depth_))
351355
{
352356
ec = cbor_errc::max_nesting_depth_exceeded;
353357
JSONCONS_VISITOR_RETURN;
@@ -359,7 +363,7 @@ class basic_cbor_encoder final : public basic_json_visitor<char>
359363

360364
JSONCONS_VISITOR_RETURN_TYPE visit_begin_array(std::size_t length, semantic_tag, const ser_context&, std::error_code& ec) override
361365
{
362-
if (JSONCONS_UNLIKELY(++nesting_depth_ > options_.max_nesting_depth()))
366+
if (JSONCONS_UNLIKELY(++nesting_depth_ > max_nesting_depth_))
363367
{
364368
ec = cbor_errc::max_nesting_depth_exceeded;
365369
JSONCONS_VISITOR_RETURN;
@@ -459,7 +463,7 @@ class basic_cbor_encoder final : public basic_json_visitor<char>
459463
JSONCONS_THROW(ser_error(cbor_errc::invalid_utf8_text_string));
460464
}
461465

462-
if (options_.pack_strings() && sv.size() >= jsoncons::cbor::detail::min_length_for_stringref(next_stringref_))
466+
if (pack_strings_ && sv.size() >= jsoncons::cbor::detail::min_length_for_stringref(next_stringref_))
463467
{
464468
string_type s(sv.data(), sv.size(), alloc_);
465469
auto it = stringref_map_.find(s);
@@ -998,7 +1002,7 @@ class basic_cbor_encoder final : public basic_json_visitor<char>
9981002
default:
9991003
break;
10001004
}
1001-
if (options_.pack_strings() && b.size() >= jsoncons::cbor::detail::min_length_for_stringref(next_stringref_))
1005+
if (pack_strings_ && b.size() >= jsoncons::cbor::detail::min_length_for_stringref(next_stringref_))
10021006
{
10031007
byte_string_type bs(b.data(), b.size(), alloc_);
10041008
auto it = bytestringref_map_.find(bs);
@@ -1027,7 +1031,7 @@ class basic_cbor_encoder final : public basic_json_visitor<char>
10271031
const ser_context&,
10281032
std::error_code&) override
10291033
{
1030-
if (options_.pack_strings() && b.size() >= jsoncons::cbor::detail::min_length_for_stringref(next_stringref_))
1034+
if (pack_strings_ && b.size() >= jsoncons::cbor::detail::min_length_for_stringref(next_stringref_))
10311035
{
10321036
byte_string_type bs(b.data(), b.size(), alloc_);
10331037
auto it = bytestringref_map_.find(bs);
@@ -1347,7 +1351,7 @@ class basic_cbor_encoder final : public basic_json_visitor<char>
13471351
const ser_context& context,
13481352
std::error_code& ec) override
13491353
{
1350-
if (options_.use_typed_arrays())
1354+
if (use_typed_arrays_)
13511355
{
13521356
switch (tag)
13531357
{
@@ -1380,7 +1384,7 @@ class basic_cbor_encoder final : public basic_json_visitor<char>
13801384
const ser_context& context,
13811385
std::error_code& ec) override
13821386
{
1383-
if (options_.use_typed_arrays())
1387+
if (use_typed_arrays_)
13841388
{
13851389
write_typed_array_tag(std::integral_constant<bool, jsoncons::endian::native == jsoncons::endian::big>(),
13861390
uint16_t(),
@@ -1409,7 +1413,7 @@ class basic_cbor_encoder final : public basic_json_visitor<char>
14091413
const ser_context& context,
14101414
std::error_code& ec) override
14111415
{
1412-
if (options_.use_typed_arrays())
1416+
if (use_typed_arrays_)
14131417
{
14141418
write_typed_array_tag(std::integral_constant<bool, jsoncons::endian::native == jsoncons::endian::big>(),
14151419
uint32_t(),
@@ -1438,7 +1442,7 @@ class basic_cbor_encoder final : public basic_json_visitor<char>
14381442
const ser_context& context,
14391443
std::error_code& ec) override
14401444
{
1441-
if (options_.use_typed_arrays())
1445+
if (use_typed_arrays_)
14421446
{
14431447
write_typed_array_tag(std::integral_constant<bool, jsoncons::endian::native == jsoncons::endian::big>(),
14441448
uint64_t(),
@@ -1467,7 +1471,7 @@ class basic_cbor_encoder final : public basic_json_visitor<char>
14671471
const ser_context& context,
14681472
std::error_code& ec) override
14691473
{
1470-
if (options_.use_typed_arrays())
1474+
if (use_typed_arrays_)
14711475
{
14721476
write_tag(0x48);
14731477
std::vector<uint8_t> v(data.size()*sizeof(int8_t));
@@ -1494,7 +1498,7 @@ class basic_cbor_encoder final : public basic_json_visitor<char>
14941498
const ser_context& context,
14951499
std::error_code& ec) override
14961500
{
1497-
if (options_.use_typed_arrays())
1501+
if (use_typed_arrays_)
14981502
{
14991503
write_typed_array_tag(std::integral_constant<bool, jsoncons::endian::native == jsoncons::endian::big>(),
15001504
int16_t(),
@@ -1523,7 +1527,7 @@ class basic_cbor_encoder final : public basic_json_visitor<char>
15231527
const ser_context& context,
15241528
std::error_code& ec) override
15251529
{
1526-
if (options_.use_typed_arrays())
1530+
if (use_typed_arrays_)
15271531
{
15281532
write_typed_array_tag(std::integral_constant<bool, jsoncons::endian::native == jsoncons::endian::big>(),
15291533
int32_t(),
@@ -1552,7 +1556,7 @@ class basic_cbor_encoder final : public basic_json_visitor<char>
15521556
const ser_context& context,
15531557
std::error_code& ec) override
15541558
{
1555-
if (options_.use_typed_arrays())
1559+
if (use_typed_arrays_)
15561560
{
15571561
write_typed_array_tag(std::integral_constant<bool, jsoncons::endian::native == jsoncons::endian::big>(),
15581562
int64_t(),
@@ -1582,7 +1586,7 @@ class basic_cbor_encoder final : public basic_json_visitor<char>
15821586
const ser_context& context,
15831587
std::error_code& ec) override
15841588
{
1585-
if (options_.use_typed_arrays())
1589+
if (use_typed_arrays_)
15861590
{
15871591
write_typed_array_tag(std::integral_constant<bool, jsoncons::endian::native == jsoncons::endian::big>(),
15881592
half_arg,
@@ -1611,7 +1615,7 @@ class basic_cbor_encoder final : public basic_json_visitor<char>
16111615
const ser_context& context,
16121616
std::error_code& ec) override
16131617
{
1614-
if (options_.use_typed_arrays())
1618+
if (use_typed_arrays_)
16151619
{
16161620
write_typed_array_tag(std::integral_constant<bool, jsoncons::endian::native == jsoncons::endian::big>(),
16171621
float(),
@@ -1640,7 +1644,7 @@ class basic_cbor_encoder final : public basic_json_visitor<char>
16401644
const ser_context& context,
16411645
std::error_code& ec) override
16421646
{
1643-
if (options_.use_typed_arrays())
1647+
if (use_typed_arrays_)
16441648
{
16451649
write_typed_array_tag(std::integral_constant<bool, jsoncons::endian::native == jsoncons::endian::big>(),
16461650
double(),

include/jsoncons_ext/cbor/cbor_parser.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class basic_cbor_parser : public ser_context
136136
std::bitset<num_of_tags> other_tags_;
137137
allocator_type alloc_;
138138
Source source_;
139-
cbor_decode_options options_;
139+
int max_nesting_depth_;
140140
string_type text_buffer_;
141141
byte_string_type bytes_buffer_;
142142
std::vector<parse_state,parse_state_allocator_type> state_stack_;
@@ -186,7 +186,7 @@ class basic_cbor_parser : public ser_context
186186
const Allocator& alloc = Allocator())
187187
: alloc_(alloc),
188188
source_(std::forward<Sourceable>(source)),
189-
options_(options),
189+
max_nesting_depth_(options.max_nesting_depth()),
190190
text_buffer_(alloc),
191191
bytes_buffer_(alloc),
192192
state_stack_(alloc),
@@ -657,7 +657,7 @@ class basic_cbor_parser : public ser_context
657657

658658
void begin_array(item_event_visitor& visitor, uint8_t info, std::error_code& ec)
659659
{
660-
if (JSONCONS_UNLIKELY(++nesting_depth_ > options_.max_nesting_depth()))
660+
if (JSONCONS_UNLIKELY(++nesting_depth_ > max_nesting_depth_))
661661
{
662662
ec = cbor_errc::max_nesting_depth_exceeded;
663663
more_ = false;
@@ -715,7 +715,7 @@ class basic_cbor_parser : public ser_context
715715

716716
void begin_object(item_event_visitor& visitor, uint8_t info, std::error_code& ec)
717717
{
718-
if (JSONCONS_UNLIKELY(++nesting_depth_ > options_.max_nesting_depth()))
718+
if (JSONCONS_UNLIKELY(++nesting_depth_ > max_nesting_depth_))
719719
{
720720
ec = cbor_errc::max_nesting_depth_exceeded;
721721
more_ = false;

include/jsoncons_ext/msgpack/msgpack_encoder.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ namespace msgpack {
8282
};
8383

8484
Sink sink_;
85-
const msgpack_encode_options options_;
85+
int max_nesting_depth_;
8686
allocator_type alloc_;
8787

8888
std::vector<stack_item> stack_;
@@ -102,7 +102,7 @@ namespace msgpack {
102102
const msgpack_encode_options& options,
103103
const Allocator& alloc = Allocator())
104104
: sink_(std::forward<Sink>(sink)),
105-
options_(options),
105+
max_nesting_depth_(options.max_nesting_depth()),
106106
alloc_(alloc)
107107
{
108108
}
@@ -143,7 +143,7 @@ namespace msgpack {
143143

144144
JSONCONS_VISITOR_RETURN_TYPE visit_begin_object(std::size_t length, semantic_tag, const ser_context&, std::error_code& ec) final
145145
{
146-
if (JSONCONS_UNLIKELY(++nesting_depth_ > options_.max_nesting_depth()))
146+
if (JSONCONS_UNLIKELY(++nesting_depth_ > max_nesting_depth_))
147147
{
148148
ec = msgpack_errc::max_nesting_depth_exceeded;
149149
JSONCONS_VISITOR_RETURN;
@@ -202,7 +202,7 @@ namespace msgpack {
202202

203203
JSONCONS_VISITOR_RETURN_TYPE visit_begin_array(std::size_t length, semantic_tag, const ser_context&, std::error_code& ec) final
204204
{
205-
if (JSONCONS_UNLIKELY(++nesting_depth_ > options_.max_nesting_depth()))
205+
if (JSONCONS_UNLIKELY(++nesting_depth_ > max_nesting_depth_))
206206
{
207207
ec = msgpack_errc::max_nesting_depth_exceeded;
208208
JSONCONS_VISITOR_RETURN;

include/jsoncons_ext/msgpack/msgpack_parser.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class basic_msgpack_parser : public ser_context
7373
int mark_level_{0};
7474

7575
Source source_;
76-
msgpack_decode_options options_;
76+
int max_nesting_depth_;
7777
std::basic_string<char,std::char_traits<char>,char_allocator_type> text_buffer_;
7878
std::vector<uint8_t,byte_allocator_type> bytes_buffer_;
7979
std::vector<parse_state,parse_state_allocator_type> state_stack_;
@@ -84,7 +84,7 @@ class basic_msgpack_parser : public ser_context
8484
const msgpack_decode_options& options = msgpack_decode_options(),
8585
const Allocator& alloc = Allocator())
8686
: source_(std::forward<Sourceable>(source)),
87-
options_(options),
87+
max_nesting_depth_(options.max_nesting_depth()),
8888
text_buffer_(alloc),
8989
bytes_buffer_(alloc),
9090
state_stack_(alloc)
@@ -671,7 +671,7 @@ class basic_msgpack_parser : public ser_context
671671

672672
void begin_array(item_event_visitor& visitor, uint8_t type, std::error_code& ec)
673673
{
674-
if (JSONCONS_UNLIKELY(++nesting_depth_ > options_.max_nesting_depth()))
674+
if (JSONCONS_UNLIKELY(++nesting_depth_ > max_nesting_depth_))
675675
{
676676
ec = msgpack_errc::max_nesting_depth_exceeded;
677677
more_ = false;
@@ -698,7 +698,7 @@ class basic_msgpack_parser : public ser_context
698698

699699
void begin_object(item_event_visitor& visitor, uint8_t type, std::error_code& ec)
700700
{
701-
if (JSONCONS_UNLIKELY(++nesting_depth_ > options_.max_nesting_depth()))
701+
if (JSONCONS_UNLIKELY(++nesting_depth_ > max_nesting_depth_))
702702
{
703703
ec = msgpack_errc::max_nesting_depth_exceeded;
704704
more_ = false;

0 commit comments

Comments
 (0)