1#ifndef ZSERIO_BIT_STREAM_READER_H_INC
2#define ZSERIO_BIT_STREAM_READER_H_INC
127 explicit BitStreamReader(
128 Span<const uint8_t> buffer,
size_t bufferBitSize, ArrayPreallocation maxArrayPrealloc = {});
138 const uint8_t* buffer,
size_t bufferBitSize, BitsTag, ArrayPreallocation maxArrayPrealloc = {});
146 template <
typename ALLOC>
290 template <
typename ALLOC = std::allocator<u
int8_t>>
304 for (
size_t i = 0;
i <
len; ++
i)
306 value.push_back(readByte());
326 template <
typename ALLOC = std::allocator<
char>>
340 for (
size_t i = 0;
i <
len; ++
i)
342 const char readCharacter = std::char_traits<char>::to_char_type(
343 static_cast<std::char_traits<char>::int_type
>(readByte()));
364 template <
typename ALLOC = std::allocator<u
int8_t>>
424 void alignTo(
size_t alignment);
449 ReaderContext m_context;
455inline void read(BitStreamReader& reader,
Bool& value)
457 value = reader.readBool();
460template <BitSize BIT_SIZE,
bool IS_SIGNED>
461void read(BitStreamReader& reader, FixedIntWrapper<BIT_SIZE, IS_SIGNED>& value)
463 using ValueType =
typename FixedIntWrapper<BIT_SIZE, IS_SIGNED>::ValueType;
465 if constexpr (
sizeof(ValueType) <= 4)
467 if constexpr (std::is_signed_v<ValueType>)
469 value =
static_cast<ValueType
>(reader.readSignedBits32(BIT_SIZE));
473 value =
static_cast<ValueType
>(reader.readUnsignedBits32(BIT_SIZE));
478 if constexpr (std::is_signed_v<ValueType>)
480 value =
static_cast<ValueType
>(reader.readSignedBits64(BIT_SIZE));
484 value =
static_cast<ValueType
>(reader.readUnsignedBits64(BIT_SIZE));
490void read(BitStreamReader& reader, DynIntWrapper<T>& value, uint8_t numBits)
492 if constexpr (
sizeof(T) <= 4)
494 if constexpr (std::is_signed_v<T>)
496 value =
static_cast<T
>(reader.readSignedBits32(numBits));
500 value =
static_cast<T
>(reader.readUnsignedBits32(numBits));
505 if constexpr (std::is_signed_v<T>)
507 value =
static_cast<T
>(reader.readSignedBits64(numBits));
511 value =
static_cast<T
>(reader.readUnsignedBits64(numBits));
516inline void read(BitStreamReader& reader,
VarInt16& value)
518 value = reader.readVarInt16();
521inline void read(BitStreamReader& reader,
VarInt32& value)
523 value = reader.readVarInt32();
526inline void read(BitStreamReader& reader,
VarInt64& value)
528 value = reader.readVarInt64();
531inline void read(BitStreamReader& reader,
VarInt& value)
533 value = reader.readVarInt();
536inline void read(BitStreamReader& reader,
VarUInt16& value)
538 value = reader.readVarUInt16();
541inline void read(BitStreamReader& reader,
VarUInt32& value)
543 value = reader.readVarUInt32();
546inline void read(BitStreamReader& reader,
VarUInt64& value)
548 value = reader.readVarUInt64();
551inline void read(BitStreamReader& reader,
VarUInt& value)
553 value = reader.readVarUInt();
556inline void read(BitStreamReader& reader,
VarSize& value)
558 value = reader.readVarSize();
561inline void read(BitStreamReader& reader,
Float16& value)
563 value = reader.readFloat16();
566inline void read(BitStreamReader& reader,
Float32& value)
568 value = reader.readFloat32();
571inline void read(BitStreamReader& reader,
Float64& value)
573 value = reader.readFloat64();
576template <
typename ALLOC>
577inline void read(BitStreamReader& reader, BasicBytes<ALLOC>& value)
579 value = reader.readBytes(value.get_allocator());
582template <
typename ALLOC>
585 value = reader.readString(value.get_allocator());
588template <
typename ALLOC>
589inline void read(BitStreamReader& reader, BasicBitBuffer<ALLOC>& value)
591 value = reader.readBitBuffer(value.get_allocator());
static constexpr size_t MAX_INITIAL_ARRAY_ALLOCATION
ArrayPreallocation(size_t alloc)
void setBitPosition(BitPosType position)
void alignTo(size_t alignment)
uint32_t readUnsignedBits32(uint8_t numBits=32)
size_t getMaxArrayPreallocation() const
BasicBytes< ALLOC > readBytes(const ALLOC &alloc=ALLOC())
VarUInt16 readVarUInt16()
uint64_t readUnsignedBits64(uint8_t numBits=64)
BasicString< ALLOC > readString(const ALLOC &alloc=ALLOC())
VarUInt32 readVarUInt32()
BitStreamReader(const BasicBitBuffer< ALLOC > &bitBuffer, ArrayPreallocation maxArrayPrealloc={})
VarUInt64 readVarUInt64()
size_t getBufferBitSize() const
BasicBitBuffer< RebindAlloc< ALLOC, uint8_t > > readBitBuffer(const ALLOC &allocator=ALLOC())
int64_t readSignedBits64(uint8_t numBits=64)
int32_t readSignedBits32(uint8_t numBits=32)
BitStreamReader(const uint8_t *buffer, size_t bufferByteSize, ArrayPreallocation maxArrayPrealloc={})
~BitStreamReader()=default
BitPosType getBitPosition() const
const_pointer const_iterator
constexpr iterator begin() const noexcept
detail::VarIntWrapper< uint64_t, detail::VarIntType::VAR > VarUInt
detail::FloatWrapper< float, detail::FloatType::FLOAT16 > Float16
detail::FloatWrapper< float, detail::FloatType::FLOAT32 > Float32
detail::VarIntWrapper< int32_t, detail::VarIntType::VAR32 > VarInt32
detail::VarIntWrapper< uint16_t, detail::VarIntType::VAR16 > VarUInt16
detail::VarIntWrapper< uint64_t, detail::VarIntType::VAR64 > VarUInt64
detail::VarIntWrapper< int16_t, detail::VarIntType::VAR16 > VarInt16
detail::FloatWrapper< double, detail::FloatType::FLOAT64 > Float64
detail::VarIntWrapper< uint32_t, detail::VarIntType::VAR32 > VarUInt32
detail::VarIntWrapper< int64_t, detail::VarIntType::VAR > VarInt
detail::VarIntWrapper< int64_t, detail::VarIntType::VAR64 > VarInt64
detail::VarIntWrapper< uint32_t, detail::VarIntType::VARSIZE > VarSize
Span< const uint8_t > buffer
const BitPosType bufferBitSize
ReaderContext(const ReaderContext &&)=delete
ReaderContext & operator=(const ReaderContext &&)=delete
ReaderContext(const ReaderContext &)=delete
const size_t maxArrayPreallocation
ReaderContext & operator=(const ReaderContext &)=delete