26 static constexpr size_t RequiredAlignment = 8;
31 size_t Read(
void* buffer,
size_t maxBytes);
34 template<
typename ValueType>
35 std::enable_if_t<
sizeof(
ValueType) <= RequiredAlignment,
bool>
38 constexpr size_t valueSize =
sizeof(
ValueType);
39 const size_t availableBytes = mCurrentBytes - mCurrentIndex;
42 if (availableBytes < valueSize)
43 return valueSize == Read(&value, valueSize);
46 if constexpr (valueSize == 1)
47 value = mBufferStart[mCurrentIndex];
49 value = UncheckedRead<ValueType>();
51 mCurrentIndex += valueSize;
64 virtual bool HasMoreData()
const = 0;
66 virtual size_t ReadData(
void* buffer,
size_t maxBytes) = 0;
70 bool HandleUnderflow();
76 T UncheckedRead() noexcept
83 if ((mCurrentIndex %
sizeof(T)) == 0)
86 const void* ptr = mBufferStart + mCurrentIndex;
87 result = *
static_cast<const T*
>(ptr);
92 const uint8_t*
begin = mBufferStart + mCurrentIndex;
93 const uint8_t*
end =
begin +
sizeof(T);
110 size_t mCurrentIndex { 0 };
111 size_t mCurrentBytes { 0 };
A facade-like class, that implements buffered reading from the underlying data stream.
std::enable_if_t< sizeof(ValueType)<=RequiredAlignment, bool > ReadValue(ValueType &value) { constexpr size_t valueSize=sizeof(ValueType);const size_t availableBytes=mCurrentBytes - mCurrentIndex;if(availableBytes< valueSize) return valueSize==Read(&value, valueSize);if constexpr(valueSize==1) value=mBufferStart[mCurrentIndex];else value=UncheckedRead< ValueType >();mCurrentIndex+=valueSize;return true;} bool Eof() const ;int GetC();protected:virtual bool HasMoreData() const=0;virtual size_t ReadData(void *buffer, size_t maxBytes)=0;private:bool HandleUnderflow();template< typename T > T UncheckedRead() noexcept { T result;if((mCurrentIndex % sizeof(T))==0) { const void *ptr=mBufferStart+mCurrentIndex;result=*static_cast< const T * >(ptr);} else { const uint8_t *begin=mBufferStart+mCurrentIndex;const uint8_t *end=begin+sizeof(T);void *out=&result;std::copy(begin, end, static_cast< uint8_t * >(out));} return result;} std::vector< uint8_t > mBufferData
Read a single value of ValueType, where sizeof(ValueType) <= 8 and value is aligned to the size bound...
const char * end(const char *str) noexcept
const char * begin(const char *str) noexcept
void copy(const T *src, T *dst, int32_t n)