Skip to content

Commit

Permalink
cbor add raw_tag accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Jan 24, 2025
1 parent 96e06a5 commit 673cdfa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
5 changes: 5 additions & 0 deletions include/jsoncons_ext/cbor/cbor_cursor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ class basic_cbor_cursor : public basic_staj_cursor<char>, private virtual ser_co
{
return parser_.done();
}

bool raw_tag() const
{
return parser_.raw_tag();
}

bool is_typed_array() const
{
Expand Down
45 changes: 25 additions & 20 deletions include/jsoncons_ext/cbor/cbor_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class basic_cbor_parser : public ser_context
bool done_{false};
string_type text_buffer_;
byte_string_type bytes_buffer_;
uint64_t item_tag_;
uint64_t raw_tag_;
std::vector<parse_state,parse_state_allocator_type> state_stack_;
byte_string_type typed_array_;
std::vector<std::size_t> shape_;
Expand Down Expand Up @@ -187,7 +187,7 @@ class basic_cbor_parser : public ser_context
options_(options),
text_buffer_(alloc),
bytes_buffer_(alloc),
item_tag_(0),
raw_tag_(0),
state_stack_(alloc),
typed_array_(alloc),
index_(0),
Expand Down Expand Up @@ -215,7 +215,7 @@ class basic_cbor_parser : public ser_context
done_ = false;
text_buffer_.clear();
bytes_buffer_.clear();
item_tag_ = 0;
raw_tag_ = 0;
state_stack_.clear();
state_stack_.emplace_back(parse_mode::root,0);
typed_array_.clear();
Expand Down Expand Up @@ -249,6 +249,11 @@ class basic_cbor_parser : public ser_context
{
return source_.position();
}

uint64_t raw_tag() const
{
return raw_tag_;
}

void parse(item_event_visitor& visitor, std::error_code& ec)
{
Expand Down Expand Up @@ -442,7 +447,7 @@ class basic_cbor_parser : public ser_context
semantic_tag tag = semantic_tag::none;
if (other_tags_[item_tag])
{
if (item_tag_ == 1)
if (raw_tag_ == 1)
{
tag = semantic_tag::epoch_second;
}
Expand All @@ -462,7 +467,7 @@ class basic_cbor_parser : public ser_context
semantic_tag tag = semantic_tag::none;
if (other_tags_[item_tag])
{
if (item_tag_ == 1)
if (raw_tag_ == 1)
{
tag = semantic_tag::epoch_second;
}
Expand Down Expand Up @@ -550,7 +555,7 @@ class basic_cbor_parser : public ser_context
semantic_tag tag = semantic_tag::none;
if (other_tags_[item_tag])
{
if (item_tag_ == 1)
if (raw_tag_ == 1)
{
tag = semantic_tag::epoch_second;
}
Expand All @@ -572,7 +577,7 @@ class basic_cbor_parser : public ser_context
{
if (other_tags_[item_tag])
{
switch (item_tag_)
switch (raw_tag_)
{
case 0x04:
text_buffer_.clear();
Expand Down Expand Up @@ -1461,7 +1466,7 @@ class basic_cbor_parser : public ser_context
break;
default:
other_tags_[item_tag] = true;
item_tag_ = val;
raw_tag_ = val;
break;
}
c = source_.peek();
Expand All @@ -1480,7 +1485,7 @@ class basic_cbor_parser : public ser_context
semantic_tag tag = semantic_tag::none;
if (other_tags_[item_tag])
{
switch (item_tag_)
switch (raw_tag_)
{
case 0:
tag = semantic_tag::datetime;
Expand Down Expand Up @@ -1520,7 +1525,7 @@ class basic_cbor_parser : public ser_context
{
if (other_tags_[item_tag])
{
switch (item_tag_)
switch (raw_tag_)
{
case 0x2:
{
Expand Down Expand Up @@ -1624,7 +1629,7 @@ class basic_cbor_parser : public ser_context
more_ = false;
return;
}
const uint8_t tag = (uint8_t)item_tag_;
const uint8_t tag = (uint8_t)raw_tag_;
jsoncons::endian e = get_typed_array_endianness(tag);
const size_t bytes_per_elem = get_typed_array_bytes_per_element(tag);

Expand All @@ -1651,7 +1656,7 @@ class basic_cbor_parser : public ser_context
more_ = false;
return;
}
const uint8_t tag = (uint8_t)item_tag_;
const uint8_t tag = (uint8_t)raw_tag_;
jsoncons::endian e = get_typed_array_endianness(tag);
const size_t bytes_per_elem = get_typed_array_bytes_per_element(tag);

Expand All @@ -1677,7 +1682,7 @@ class basic_cbor_parser : public ser_context
more_ = false;
return;
}
const uint8_t tag = (uint8_t)item_tag_;
const uint8_t tag = (uint8_t)raw_tag_;
jsoncons::endian e = get_typed_array_endianness(tag);
const size_t bytes_per_elem = get_typed_array_bytes_per_element(tag);

Expand Down Expand Up @@ -1717,7 +1722,7 @@ class basic_cbor_parser : public ser_context
more_ = false;
return;
}
const uint8_t tag = (uint8_t)item_tag_;
const uint8_t tag = (uint8_t)raw_tag_;
jsoncons::endian e = get_typed_array_endianness(tag);
const size_t bytes_per_elem = get_typed_array_bytes_per_element(tag);

Expand All @@ -1743,7 +1748,7 @@ class basic_cbor_parser : public ser_context
more_ = false;
return;
}
const uint8_t tag = (uint8_t)item_tag_;
const uint8_t tag = (uint8_t)raw_tag_;
jsoncons::endian e = get_typed_array_endianness(tag);
const size_t bytes_per_elem = get_typed_array_bytes_per_element(tag);

Expand All @@ -1769,7 +1774,7 @@ class basic_cbor_parser : public ser_context
more_ = false;
return;
}
const uint8_t tag = (uint8_t)item_tag_;
const uint8_t tag = (uint8_t)raw_tag_;
jsoncons::endian e = get_typed_array_endianness(tag);
const size_t bytes_per_elem = get_typed_array_bytes_per_element(tag);

Expand All @@ -1795,7 +1800,7 @@ class basic_cbor_parser : public ser_context
more_ = false;
return;
}
const uint8_t tag = (uint8_t)item_tag_;
const uint8_t tag = (uint8_t)raw_tag_;
jsoncons::endian e = get_typed_array_endianness(tag);
const size_t bytes_per_elem = get_typed_array_bytes_per_element(tag);

Expand All @@ -1821,7 +1826,7 @@ class basic_cbor_parser : public ser_context
more_ = false;
return;
}
const uint8_t tag = (uint8_t)item_tag_;
const uint8_t tag = (uint8_t)raw_tag_;
jsoncons::endian e = get_typed_array_endianness(tag);
const size_t bytes_per_elem = get_typed_array_bytes_per_element(tag);

Expand All @@ -1847,7 +1852,7 @@ class basic_cbor_parser : public ser_context
more_ = false;
return;
}
const uint8_t tag = (uint8_t)item_tag_;
const uint8_t tag = (uint8_t)raw_tag_;
jsoncons::endian e = get_typed_array_endianness(tag);
const size_t bytes_per_elem = get_typed_array_bytes_per_element(tag);

Expand All @@ -1872,7 +1877,7 @@ class basic_cbor_parser : public ser_context
more_ = false;
return;
}
more_ = visitor.byte_string_value(bytes_buffer_, item_tag_, *this, ec);
more_ = visitor.byte_string_value(bytes_buffer_, raw_tag_, *this, ec);
break;
}
}
Expand Down

0 comments on commit 673cdfa

Please sign in to comment.