24 #include <boost/endian/conversion.hpp>
29 namespace endian = boost::endian;
32 : m_buffer(make_shared<
Buffer>(totalReserve))
34 m_begin = m_end = m_buffer->end() - (reserveFromBack < totalReserve ? reserveFromBack : 0);
38 : m_buffer(const_pointer_cast<
Buffer>(block.getBuffer()))
39 , m_begin(m_buffer->begin() + (block.begin() - m_buffer->begin()))
40 , m_end(m_buffer->begin() + (block.end() - m_buffer->begin()))
47 if (m_end +
size > m_buffer->end())
54 if (m_buffer->begin() +
size > m_begin)
61 return Block(m_buffer, m_begin, m_end, verifyLength);
67 if (size < m_buffer->
size()) {
68 size = m_buffer->size();
72 size_t diffEnd = m_buffer->end() - m_end;
73 size_t diffBegin = m_buffer->end() - m_begin;
76 std::copy_backward(m_buffer->begin(), m_buffer->end(),
buf->end());
80 m_end = m_buffer->end() - diffEnd;
81 m_begin = m_buffer->end() - diffBegin;
84 size_t diffEnd = m_end - m_buffer->begin();
85 size_t diffBegin = m_begin - m_buffer->begin();
88 std::copy(m_buffer->begin(), m_buffer->end(),
buf->begin());
92 m_end = m_buffer->begin() + diffEnd;
93 m_begin = m_buffer->begin() + diffBegin;
123 std::copy(array, array + length, m_begin);
132 std::copy(array, array + length, m_end);
140 if (varNumber < 253) {
144 else if (varNumber <= std::numeric_limits<uint16_t>::max()) {
145 uint16_t value = endian::native_to_big(
static_cast<uint16_t
>(varNumber));
150 else if (varNumber <= std::numeric_limits<uint32_t>::max()) {
151 uint32_t value = endian::native_to_big(
static_cast<uint32_t
>(varNumber));
157 uint64_t value = endian::native_to_big(varNumber);
167 if (varNumber < 253) {
171 else if (varNumber <= std::numeric_limits<uint16_t>::max()) {
173 uint16_t value = endian::native_to_big(
static_cast<uint16_t
>(varNumber));
177 else if (varNumber <= std::numeric_limits<uint32_t>::max()) {
179 uint32_t value = endian::native_to_big(
static_cast<uint32_t
>(varNumber));
185 uint64_t value = endian::native_to_big(varNumber);
194 if (varNumber <= std::numeric_limits<uint8_t>::max()) {
195 return prependByte(
static_cast<uint8_t
>(varNumber));
197 else if (varNumber <= std::numeric_limits<uint16_t>::max()) {
198 uint16_t value = endian::native_to_big(
static_cast<uint16_t
>(varNumber));
201 else if (varNumber <= std::numeric_limits<uint32_t>::max()) {
202 uint32_t value = endian::native_to_big(
static_cast<uint32_t
>(varNumber));
206 uint64_t value = endian::native_to_big(varNumber);
214 if (varNumber <= std::numeric_limits<uint8_t>::max()) {
215 return appendByte(
static_cast<uint8_t
>(varNumber));
217 else if (varNumber <= std::numeric_limits<uint16_t>::max()) {
218 uint16_t value = endian::native_to_big(
static_cast<uint16_t
>(varNumber));
221 else if (varNumber <= std::numeric_limits<uint32_t>::max()) {
222 uint32_t value = endian::native_to_big(
static_cast<uint32_t
>(varNumber));
226 uint64_t value = endian::native_to_big(varNumber);