@@ -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 (),
0 commit comments