1 #ifndef ZSERIO_BIT_STREAM_READER_H_INC
2 #define ZSERIO_BIT_STREAM_READER_H_INC
102 template <
typename ALLOC>
246 template <
typename ALLOC = std::allocator<u
int8_t>>
249 const size_t len =
static_cast<size_t>(
readVarSize());
251 if ((beginBitPosition & 0x07U) != 0)
256 for (
size_t i = 0; i < len; ++i)
258 value.push_back(readByte());
278 template <
typename ALLOC = std::allocator<
char>>
281 const size_t len =
static_cast<size_t>(
readVarSize());
283 if ((beginBitPosition & 0x07U) != 0)
288 for (
size_t i = 0; i < len; ++i)
290 const char readCharacter = std::char_traits<char>::to_char_type(
291 static_cast<std::char_traits<char>::int_type
>(readByte()));
292 value.push_back(readCharacter);
312 template <
typename ALLOC = std::allocator<u
int8_t>>
315 const size_t bitSize =
static_cast<size_t>(
readVarSize());
316 const size_t numBytesToRead = bitSize / 8;
317 const uint8_t numRestBits =
static_cast<uint8_t
>(bitSize - numBytesToRead * 8);
322 if ((beginBitPosition & 0x07U) != 0)
335 (void)std::copy(sourceIt, sourceIt + numBytesToRead, buffer.
begin());
368 void alignTo(
size_t alignment);
383 ReaderContext m_context;
389 inline void read(BitStreamReader& reader,
Bool& value)
391 value = reader.readBool();
394 template <BitSize BIT_SIZE,
bool IS_SIGNED>
395 void read(BitStreamReader& reader, FixedIntWrapper<BIT_SIZE, IS_SIGNED>& value)
397 using ValueType =
typename FixedIntWrapper<BIT_SIZE, IS_SIGNED>::ValueType;
399 if constexpr (
sizeof(ValueType) <= 4)
401 if constexpr (std::is_signed_v<ValueType>)
403 value =
static_cast<ValueType
>(reader.readSignedBits32(BIT_SIZE));
407 value =
static_cast<ValueType
>(reader.readUnsignedBits32(BIT_SIZE));
412 if constexpr (std::is_signed_v<ValueType>)
414 value =
static_cast<ValueType
>(reader.readSignedBits64(BIT_SIZE));
418 value =
static_cast<ValueType
>(reader.readUnsignedBits64(BIT_SIZE));
423 template <
typename T>
424 void read(BitStreamReader& reader, DynIntWrapper<T>& value, uint8_t
numBits)
426 if constexpr (
sizeof(T) <= 4)
428 if constexpr (std::is_signed_v<T>)
430 value =
static_cast<T
>(reader.readSignedBits32(
numBits));
434 value =
static_cast<T
>(reader.readUnsignedBits32(
numBits));
439 if constexpr (std::is_signed_v<T>)
441 value =
static_cast<T
>(reader.readSignedBits64(
numBits));
445 value =
static_cast<T
>(reader.readUnsignedBits64(
numBits));
450 inline void read(BitStreamReader& reader,
VarInt16& value)
452 value = reader.readVarInt16();
455 inline void read(BitStreamReader& reader,
VarInt32& value)
457 value = reader.readVarInt32();
460 inline void read(BitStreamReader& reader,
VarInt64& value)
462 value = reader.readVarInt64();
465 inline void read(BitStreamReader& reader,
VarInt& value)
467 value = reader.readVarInt();
470 inline void read(BitStreamReader& reader,
VarUInt16& value)
472 value = reader.readVarUInt16();
475 inline void read(BitStreamReader& reader,
VarUInt32& value)
477 value = reader.readVarUInt32();
480 inline void read(BitStreamReader& reader,
VarUInt64& value)
482 value = reader.readVarUInt64();
485 inline void read(BitStreamReader& reader,
VarUInt& value)
487 value = reader.readVarUInt();
490 inline void read(BitStreamReader& reader,
VarSize& value)
492 value = reader.readVarSize();
495 inline void read(BitStreamReader& reader,
Float16& value)
497 value = reader.readFloat16();
500 inline void read(BitStreamReader& reader,
Float32& value)
502 value = reader.readFloat32();
505 inline void read(BitStreamReader& reader,
Float64& value)
507 value = reader.readFloat64();
510 template <
typename ALLOC>
511 inline void read(BitStreamReader& reader, BasicBytes<ALLOC>& value)
513 value = reader.readBytes(value.get_allocator());
516 template <
typename ALLOC>
519 value = reader.readString(value.get_allocator());
522 template <
typename ALLOC>
523 inline void read(BitStreamReader& reader, BasicBitBuffer<ALLOC>& value)
525 value = reader.readBitBuffer(value.get_allocator());
Span< const uint8_t > getData() const
void setBitPosition(BitPosType position)
void alignTo(size_t alignment)
BitStreamReader(const uint8_t *buffer, size_t bufferByteSize)
uint32_t readUnsignedBits32(uint8_t numBits=32)
BitStreamReader(const BasicBitBuffer< ALLOC > &bitBuffer)
BasicBitBuffer< RebindAlloc< ALLOC, uint8_t > > readBitBuffer(const ALLOC &allocator=ALLOC())
VarUInt16 readVarUInt16()
uint64_t readUnsignedBits64(uint8_t numBits=64)
VarUInt32 readVarUInt32()
VarUInt64 readVarUInt64()
size_t getBufferBitSize() const
int64_t readSignedBits64(uint8_t numBits=64)
int32_t readSignedBits32(uint8_t numBits=32)
~BitStreamReader()=default
BasicString< ALLOC > readString(const ALLOC &alloc=ALLOC())
BasicBytes< ALLOC > readBytes(const ALLOC &alloc=ALLOC())
BitPosType getBitPosition() const
constexpr iterator begin() const noexcept
uint8_t numBits(uint64_t numValues)
detail::VarIntWrapper< uint64_t, detail::VarIntType::VAR > VarUInt
std::basic_string< char, std::char_traits< char >, ALLOC > BasicString
detail::FloatWrapper< float, detail::FloatType::FLOAT16 > Float16
std::vector< T, ALLOC > Vector
std::vector< uint8_t, ALLOC > BasicBytes
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
ReaderContext(Span< const uint8_t > readBuffer, size_t readBufferBitSize)
Span< const uint8_t > buffer
ReaderContext & operator=(const ReaderContext &&)=delete
const BitPosType bufferBitSize
ReaderContext(const ReaderContext &&)=delete
ReaderContext & operator=(const ReaderContext &)=delete
ReaderContext(const ReaderContext &)=delete