• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

libbitcoin / libbitcoin-network / 42941732917

11 Nov 2026 01:49AM UTC coverage: 93.688% (-0.006%) from 93.694%
42941732917

push

github

web-flow
Merge pull request #1022 from evoskuil/master

Generate vs props files and build config from master xml.

14798 of 15795 relevant lines covered (93.69%)

2253.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.59
/src/messages/http/flat_buffer.cpp
1
/**
2
 * Copyright (c) 2011-2026 libbitcoin developers
3
 *
4
 * This file is part of libbitcoin.
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Affero General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU Affero General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Affero General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
#include <bitcoin/network/messages/http/flat_buffer.hpp>
20

21
#include <stdexcept>
22
#include <bitcoin/network/define.hpp>
23

24
namespace libbitcoin {
25
namespace network {
26
namespace http {
27

28
using namespace system;
29

30
BC_PUSH_WARNING(NO_POINTER_ARITHMETIC)
31
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
32

33
flat_buffer::flat_buffer() NOEXCEPT
725 ✔
34
  : flat_buffer(max_size_t)
725 ✔
35
{
36
}
725 ✔
37

38
flat_buffer::flat_buffer(size_t limit) NOEXCEPT
1,963 ✔
39
  : limit_(limit)
1,963 ✔
40
{
41
}
1,963 ✔
42

43
flat_buffer::const_buffers_type flat_buffer::data() const NOEXCEPT
50 ✔
44
{
45
    return { std::next(buffer_.data(), begin_), size() };
50 ✔
46
}
47

48
flat_buffer::const_buffers_type flat_buffer::cdata() const NOEXCEPT
2 ✔
49
{
50
    return data();
2 ✔
51
}
52

53
flat_buffer::mutable_buffers_type flat_buffer::data() NOEXCEPT
632 ✔
54
{
55
    return { std::next(buffer_.data(), begin_), size() };
632 ✔
56
}
57

58
size_t flat_buffer::size() const NOEXCEPT
3,736 ✔
59
{
60
    return end_ - begin_;
3,736 ✔
61
}
62

63
size_t flat_buffer::max_size() const NOEXCEPT
691 ✔
64
{
65
    return limit_;
691 ✔
66
}
67

68
size_t flat_buffer::capacity() const NOEXCEPT
651 ✔
69
{
70
    return buffer_.size();
651 ✔
71
}
72

73
flat_buffer::mutable_buffers_type flat_buffer::prepare(size_t size) THROWS
1,097 ✔
74
{
75
    if (size > limit_ - this->size())
1,097 ✔
76
        throw std::length_error{ "flat_buffer overflow" };
2 ✔
77

78
    // Move readable bytes to the front when that makes sufficient room.
79
    if (buffer_.size() - end_ < size && !is_zero(begin_))
1,095 ✔
80
    {
81
        std::copy(std::next(buffer_.begin(), begin_),
48 ✔
82
            std::next(buffer_.begin(), end_), buffer_.begin());
16 ✔
83
        end_ -= begin_;
16 ✔
84
        begin_ = zero;
16 ✔
85
    }
86

87
    if (buffer_.size() - end_ < size)
1,095 ✔
88
        buffer_.resize(end_ + size);
545 ✔
89

90
    return { std::next(buffer_.data(), end_), size };
1,095 ✔
91
}
92

93
void flat_buffer::commit(size_t size) NOEXCEPT
513 ✔
94
{
95
    end_ += std::min(size, buffer_.size() - end_);
513 ✔
96
}
513 ✔
97

98
void flat_buffer::consume(size_t size) NOEXCEPT
925 ✔
99
{
100
    if (size >= this->size())
925 ✔
101
    {
102
        clear();
832 ✔
103
        return;
832 ✔
104
    }
105

106
    begin_ += size;
93 ✔
107
}
108

109
void flat_buffer::clear() NOEXCEPT
1,206 ✔
110
{
111
    begin_ = zero;
1,206 ✔
112
    end_ = zero;
1,206 ✔
113
}
1,206 ✔
114

115
void flat_buffer::reserve(size_t size) NOEXCEPT
37 ✔
116
{
117
    if (buffer_.size() < size)
37 ✔
118
        buffer_.resize(size);
18 ✔
119
}
37 ✔
120

121
void flat_buffer::shrink_to_fit() NOEXCEPT
37 ✔
122
{
123
    if (!is_zero(begin_))
37 ✔
124
    {
125
        std::copy(std::next(buffer_.begin(), begin_),
×
126
            std::next(buffer_.begin(), end_), buffer_.begin());
×
127
        end_ -= begin_;
×
128
        begin_ = zero;
×
129
    }
130

131
    buffer_.resize(end_);
37 ✔
132
    buffer_.shrink_to_fit();
37 ✔
133
}
37 ✔
134

135
BC_POP_WARNING()
136
BC_POP_WARNING()
137

138
} // namespace http
139
} // namespace network
140
} // namespace libbitcoin
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc