| 1575 | |
| 1576 | template <typename T,typename Alloc, typename TempAlloc> |
| 1577 | typename std::enable_if<ext_traits::is_basic_byte_string<T>::value,conversion_result<T>>::type |
| 1578 | try_as_byte_string(const allocator_set<Alloc,TempAlloc>& aset) const |
| 1579 | { |
| 1580 | using value_type = T; |
| 1581 | using result_type = conversion_result<value_type>; |
| 1582 | |
| 1583 | switch (storage_kind()) |
| 1584 | { |
| 1585 | case json_storage_kind::short_str: |
| 1586 | { |
| 1587 | value_type bytes = jsoncons::make_obj_using_allocator<value_type>(aset.get_allocator()); |
| 1588 | const auto& stor = cast<short_string_storage>(); |
| 1589 | auto res = string_to_bytes(stor.data(), stor.data()+stor.length(), tag(), bytes); |
| 1590 | if (JSONCONS_UNLIKELY(res.ec != conv_errc{})) |
| 1591 | { |
| 1592 | return result_type(jsoncons::unexpect, conv_errc::not_byte_string); |
| 1593 | } |
| 1594 | return result_type(std::move(bytes)); |
| 1595 | } |
| 1596 | case json_storage_kind::long_str: |
| 1597 | { |
| 1598 | value_type bytes = jsoncons::make_obj_using_allocator<value_type>(aset.get_allocator()); |
| 1599 | const auto& stor = cast<long_string_storage>(); |
| 1600 | auto res = string_to_bytes(stor.data(), stor.data()+stor.length(), tag(), bytes); |
| 1601 | if (JSONCONS_UNLIKELY(res.ec != conv_errc{})) |
| 1602 | { |
| 1603 | return result_type(jsoncons::unexpect, conv_errc::not_byte_string); |
| 1604 | } |
| 1605 | return result_type(std::move(bytes)); |
| 1606 | } |
| 1607 | case json_storage_kind::byte_str: |
| 1608 | { |
| 1609 | auto& bs = cast<byte_string_storage>(); |
| 1610 | auto val = jsoncons::make_obj_using_allocator<value_type>(aset.get_allocator(), |
| 1611 | bs.data(), bs.length()); |
| 1612 | return result_type(std::move(val)); |
| 1613 | } |
| 1614 | case json_storage_kind::const_json_ref: |
| 1615 | return cast<const_json_ref_storage>().value().template try_as_byte_string<T>(aset); |
| 1616 | case json_storage_kind::json_ref: |
| 1617 | return cast<json_ref_storage>().value().template try_as_byte_string<T>(aset); |
| 1618 | default: |
| 1619 | return result_type(jsoncons::unexpect, conv_errc::not_byte_string); |
| 1620 | } |
| 1621 | } |
| 1622 | |
| 1623 | template <typename BytesAlloc=std::allocator<uint8_t>> |
| 1624 | basic_byte_string<BytesAlloc> as_byte_string() const |
nothing calls this directly
no test coverage detected