Coverage Report

Created: 2025-12-20 06:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/jsoncons/include/jsoncons_ext/ubjson/ubjson_reader.hpp
Line
Count
Source
1
// Copyright 2013-2025 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_EXT_UBJSON_UBJSON_READER_HPP
8
#define JSONCONS_EXT_UBJSON_UBJSON_READER_HPP
9
10
#include <cstddef>
11
#include <memory>
12
#include <system_error>
13
#include <utility> // std::move
14
15
#include <jsoncons/config/compiler_support.hpp>
16
#include <jsoncons/config/jsoncons_config.hpp>
17
#include <jsoncons/json_visitor.hpp>
18
#include <jsoncons/source.hpp>
19
#include <jsoncons_ext/ubjson/ubjson_error.hpp>
20
#include <jsoncons_ext/ubjson/ubjson_parser.hpp>
21
#include <jsoncons_ext/ubjson/ubjson_type.hpp>
22
23
namespace jsoncons { 
24
namespace ubjson {
25
26
template <typename Source,typename Allocator=std::allocator<char>>
27
class basic_ubjson_reader
28
{
29
    basic_ubjson_parser<Source,Allocator> parser_;
30
    json_visitor& visitor_;
31
public:
32
    template <typename Sourceable>
33
    basic_ubjson_reader(Sourceable&& source, 
34
                      json_visitor& visitor, 
35
                      const Allocator& alloc)
36
       : basic_ubjson_reader(std::forward<Sourceable>(source),
37
                           visitor,
38
                           ubjson_decode_options(),
39
                           alloc)
40
    {
41
    }
42
43
    template <typename Sourceable>
44
    basic_ubjson_reader(Sourceable&& source, 
45
                      json_visitor& visitor, 
46
                      const ubjson_decode_options& options = ubjson_decode_options(),
47
                      const Allocator& alloc=Allocator())
48
743
       : parser_(std::forward<Sourceable>(source), options, alloc),
49
743
         visitor_(visitor)
50
743
    {
51
743
    }
jsoncons::ubjson::basic_ubjson_reader<jsoncons::stream_source<unsigned char, std::__1::allocator<unsigned char> >, std::__1::allocator<char> >::basic_ubjson_reader<std::__1::basic_istringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >&>(std::__1::basic_istringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, jsoncons::basic_json_visitor<char>&, jsoncons::ubjson::ubjson_decode_options const&, std::__1::allocator<char> const&)
Line
Count
Source
48
281
       : parser_(std::forward<Sourceable>(source), options, alloc),
49
281
         visitor_(visitor)
50
281
    {
51
281
    }
jsoncons::ubjson::basic_ubjson_reader<jsoncons::stream_source<unsigned char, std::__1::allocator<unsigned char> >, std::__1::allocator<char> >::basic_ubjson_reader<std::__1::basic_istream<char, std::__1::char_traits<char> >&>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, jsoncons::basic_json_visitor<char>&, jsoncons::ubjson::ubjson_decode_options const&, std::__1::allocator<char> const&)
Line
Count
Source
48
462
       : parser_(std::forward<Sourceable>(source), options, alloc),
49
462
         visitor_(visitor)
50
462
    {
51
462
    }
52
53
    void read()
54
    {
55
        std::error_code ec;
56
        read(ec);
57
        if (JSONCONS_UNLIKELY(ec))
58
        {
59
            JSONCONS_THROW(ser_error(ec,line(),column()));
60
        }
61
    }
62
63
    void read(std::error_code& ec)
64
743
    {
65
743
        parser_.reset();
66
743
        parser_.parse(visitor_, ec);
67
743
        if (JSONCONS_UNLIKELY(ec))
68
601
        {
69
601
            return;
70
601
        }
71
743
    }
72
73
    std::size_t line() const 
74
337
    {
75
337
        return parser_.line();
76
337
    }
77
78
    std::size_t column() const
79
337
    {
80
337
        return parser_.column();
81
337
    }
82
};
83
84
using ubjson_stream_reader = basic_ubjson_reader<jsoncons::binary_stream_source>;
85
86
using ubjson_bytes_reader = basic_ubjson_reader<jsoncons::bytes_source>;
87
88
} // namespace ubjson
89
} // namespace jsoncons
90
91
#endif // JSONCONS_EXT_UBJSON_UBJSON_READER_HPP