1#ifndef ZSERIO_BIT_BUFFER_H_INC
2#define ZSERIO_BIT_BUFFER_H_INC
34template <
typename ALLOC = std::allocator<u
int8_t>>
38 static_assert(std::is_same<uint8_t, typename ALLOC::value_type>::value,
39 "Allocator with uint8_t value_type is required!");
50 return m_buffer.get_allocator();
154 return !(*
this ==
other);
176 return other < *
this;
188 return !(
other < *
this);
200 return !(*
this <
other);
245 const std::vector<uint8_t, ALLOC>&
getBytes()
const;
262 uint8_t getMaskedLastByte()
const;
264 std::vector<uint8_t, ALLOC> m_buffer;
268template <
typename ALLOC>
274template <
typename ALLOC>
280template <
typename ALLOC>
286template <
typename ALLOC>
288 m_buffer(buffer.begin(), buffer.end(),
allocator),
289 m_bitSize(8 * buffer.size())
292template <
typename ALLOC>
294 m_buffer(buffer.begin(), buffer.end(),
allocator),
301 <<
bitSize <<
" out of range for given span byte size " << buffer.size() <<
"!";
305template <
typename ALLOC>
307 m_buffer(
std::move(buffer)),
308 m_bitSize(8 * m_buffer.size())
311template <
typename ALLOC>
313 m_buffer(
std::move(buffer)),
320 <<
bitSize <<
" out of range for given vector byte size " << m_buffer.size() <<
"!";
324template <
typename ALLOC>
327 m_bitSize(
other.m_bitSize)
330template <
typename ALLOC>
333 m_bitSize(
other.m_bitSize)
336template <
typename ALLOC>
341 if (m_bitSize !=
other.m_bitSize)
346 const size_t byteSize = getByteSize();
351 if (std::memcmp(getBuffer(),
other.getBuffer(),
byteSize - 1) != 0)
357 if (getMaskedLastByte() !=
other.getMaskedLastByte())
367template <
typename ALLOC>
382 using DifferenceType =
typename std::vector<uint8_t, ALLOC>::iterator::difference_type;
384 auto first1 = m_buffer.begin();
411 return m_bitSize <
other.m_bitSize;
414template <
typename ALLOC>
418 const size_t byteSize = getByteSize();
435template <
typename ALLOC>
438 return m_buffer.data();
441template <
typename ALLOC>
444 return m_buffer.data();
447template <
typename ALLOC>
453template <
typename ALLOC>
456 return (m_bitSize + 7) / 8;
459template <
typename ALLOC>
465template <
typename ALLOC>
471template <
typename ALLOC>
477template <
typename ALLOC>
492template <
typename ALLOC>
498template <
typename ALLOC>
507template <
typename ALLOC>
510 return lhs.get() ==
rhs.get();
513template <
typename ALLOC>
516 return lhs.get() !=
rhs.get();
519template <
typename ALLOC>
522 return lhs.get() <
rhs.get();
525template <
typename ALLOC>
528 return lhs.get() >
rhs.get();
531template <
typename ALLOC>
534 return lhs.get() <=
rhs.get();
537template <
typename ALLOC>
540 return lhs.get() >=
rhs.get();
553template <
typename ALLOC>
556 return exception <<
"BitBuffer([...], " <<
bitBuffer.getBitSize() <<
")";
567template <
typename ALLOC>
576template <
typename ALLOC>
577void validate(
const BasicBitBufferView<ALLOC>&, std::string_view)
582template <
typename ALLOC>
583BitSize bitSizeOf(
const BasicBitBufferView<ALLOC>& bitBufferView,
BitSize = 0)
585 const BasicBitBuffer<ALLOC>& bitBuffer = bitBufferView.get();
589 return bitSizeOf(bitBufferSize) + bitBufferSize;
592template <
typename ALLOC>
593BitSize initializeOffsets(
const BasicBitBufferView<ALLOC>& bitBufferView,
BitSize bitPosition)
595 return bitSizeof(bitBufferView, bitPosition);
608template <
typename ALLOC>
609struct hash<
zserio::BasicBitBuffer<ALLOC>>
613 return static_cast<size_t>(bitBuffer.hashCode());
620template <
typename ALLOC>
621struct hash<
zserio::BasicBitBufferView<ALLOC>>
625 return static_cast<size_t>(bitBuffer.get().hashCode());
size_t getByteSize() const
BasicBitBuffer(const BasicBitBuffer &other, const ALLOC &allocator)
ALLOC get_allocator() const
bool operator<=(const BasicBitBuffer &other) const
BasicBitBuffer(std::vector< uint8_t, ALLOC > &&buffer)
BasicBitBuffer(Span< const uint8_t > buffer, const ALLOC &allocator={})
bool operator>(const BasicBitBuffer &other) const
BasicBitBuffer & operator=(const BasicBitBuffer &)=default
BasicBitBuffer(BasicBitBuffer &&)=default
BasicBitBuffer(const BasicBitBuffer &)=default
Span< const uint8_t > getData() const
size_t getBitSize() const
uint32_t hashCode() const
BasicBitBuffer(size_t bitSize, const ALLOC &allocator={})
BasicBitBuffer(std::vector< uint8_t, ALLOC > &&buffer, size_t bitSize)
bool operator>=(const BasicBitBuffer &other) const
bool operator==(const BasicBitBuffer &other) const
bool operator<(const BasicBitBuffer &other) const
BasicBitBuffer & operator=(BasicBitBuffer &&)=default
~BasicBitBuffer()=default
const std::vector< uint8_t, ALLOC > & getBytes() const
Span< uint8_t > getData()
const uint8_t * getBuffer() const
BasicBitBuffer(const ALLOC &allocator)
BasicBitBuffer(Span< const uint8_t > buffer, size_t bitSize, const ALLOC &allocator={})
bool operator!=(const BasicBitBuffer &other) const
BasicBitBuffer(BasicBitBuffer &&other, const ALLOC &allocator)
bool operator>(const BasicBitBufferView< ALLOC > &lhs, const BasicBitBufferView< ALLOC > &rhs)
bool operator==(const BasicBitBufferView< ALLOC > &lhs, const BasicBitBufferView< ALLOC > &rhs)
CppRuntimeException & operator<<(CppRuntimeException &exception, const BasicBitBuffer< ALLOC > &bitBuffer)
std::reference_wrapper< const BitBuffer > BitBufferView
bool operator<(const BasicBitBufferView< ALLOC > &lhs, const BasicBitBufferView< ALLOC > &rhs)
uint32_t calcHashCode(uint32_t seedValue, const ArrayView< T, ARRAY_TRAITS > &array)
uint32_t convertSizeToUInt32(size_t value)
bool operator<=(const BasicBitBufferView< ALLOC > &lhs, const BasicBitBufferView< ALLOC > &rhs)
bool operator>=(const BasicBitBufferView< ALLOC > &lhs, const BasicBitBufferView< ALLOC > &rhs)
std::reference_wrapper< const BasicBitBuffer< ALLOC > > BasicBitBufferView
bool operator!=(const BasicBitBufferView< ALLOC > &lhs, const BasicBitBufferView< ALLOC > &rhs)
detail::VarIntWrapper< uint32_t, detail::VarIntType::VARSIZE > VarSize
size_t operator()(const zserio::BasicBitBufferView< ALLOC > &bitBuffer) const
size_t operator()(const zserio::BasicBitBuffer< ALLOC > &bitBuffer) const