jaulib v1.4.0-2-g788cf73
Jau Support Library (C++, Java, ..)
|
Versatile Bitstream implementation supporting: More...
#include <bit_stream.hpp>
Public Types | |
using | size_type = jau::io::ByteStream::size_type |
uint64_t size data type, bit position and count | |
Public Member Functions | |
Bitstream (std::unique_ptr< ByteStream > &&stream, ioaccess_t access) | |
data_type | bitCache () |
Returns the 64-bit MaxBitCacheSize cache buffer value. | |
constexpr jau::nsize_t | bitCacheSizeRead () const noexcept |
Returns filled read bit-cache-size, i.e. | |
constexpr_cxx23 lb_endian_t | byteOrder () const noexcept |
Returns endian byte-order of stream storage. | |
ByteStream & | byteStream () |
Returns the used underlying ByteStream. | |
constexpr jau::nsize_t | cachedBitCount () const noexcept |
Returns number of cached bits. | |
constexpr jau::nsize_t | cachedBitPos () const noexcept |
Return the next cached bit position. | |
constexpr bool | canWrite () const noexcept |
Returns true in case stream is in write mode, false if in read mode. | |
void | close () noexcept |
Closing the underlying stream, implies flush() . | |
size_type | flush () noexcept |
Synchronizes underlying ByteStream output stream operations in writeMode(), or does nothing. | |
constexpr ioaccess_t | ioaccess () const noexcept |
Returns ioaccess_t stream mode. | |
size_type | mark () const noexcept |
Returns the markpos set via setMark() or ByteStream::npos if unset. | |
uint64_t | markReadLimit () const noexcept |
Returns the readLimit set via setMark(). | |
constexpr_cxx23 iomode_t | mode () const noexcept |
size_type | position () const noexcept |
Returns the bit position in the stream. | |
int | readBit () noexcept |
Read incoming bit in least-significant-bit (LSB) first order. | |
jau::nsize_t | readBits64 (jau::nsize_t n, data_type &r) noexcept |
Read incoming bits in least-significant-bit (LSB) first order. | |
bool | readSInt16 (int16_t &bits) noexcept |
Read int16_t . | |
bool | readU32 (uint32_t &bits) noexcept |
Read uint32_t . | |
bool | readUInt16 (uint16_t &bits) noexcept |
Read uint16_t . | |
bool | readUInt8 (uint8_t &bits) noexcept |
Read incoming uint8_t via readBits32(). | |
size_type | seek (size_type newPos) noexcept |
Sets this stream's bit position. | |
bool | seekMark () noexcept |
Seeks stream bit-position to markpos as set via setMark(). | |
bool | setAccess (ioaccess_t access) noexcept |
Changes the access-mode to write or read and resets position and cache to zero. | |
bool | setImmutable () noexcept |
Changes the write-mode to read, sets the underlying ByteStream to read-only and resets position and cache to zero. | |
bool | setMark (size_type readLimit) noexcept |
Set markpos to current bit-position, allowing the stream to be seekMark(). | |
size_type | skip (size_type n) noexcept |
Skip given number of bits. | |
std::string | toString () const |
std::string | toStringImpl () const |
bool | writeBit (uint8_t bit) noexcept |
Write given bit in least-significant-bit (LSB) first order. | |
jau::nsize_t | writeBits64 (jau::nsize_t n, data_type bits) noexcept |
Write given bits in least-significant-bit (LSB) first order. | |
bool | writeU32 (uint32_t bits) noexcept |
Write uint32_t . | |
bool | writeUInt16 (uint16_t bits) noexcept |
Write uint16_t | |
bool | writeUInt8 (uint8_t bits) noexcept |
Write the given 8 bits via writeBits31(int, int) . | |
Static Public Member Functions | |
static std::string | toHexBinaryString (uint64_t v, unsigned bitCount=MaxBitCacheSize) |
Static Public Attributes | |
static constexpr jau::nsize_t | MaxBitCacheSize = sizeof(data_type)*CHAR_BIT |
Maximum read bitCacheSizeRead() and fixed 64-bit write cache size. | |
static constexpr size_type | npos = jau::io::ByteStream::npos |
Invalid position constant, denoting unset mark() or invalid position. | |
Versatile Bitstream implementation supporting:
Definition at line 64 of file bit_stream.hpp.
uint64_t size data type, bit position and count
Definition at line 71 of file bit_stream.hpp.
|
inline |
stream | input and/or output stream |
access | ioaccess_t::read for read-access and ioaccess_t::write for read-access |
IllegalArgumentError | if requested writeMode doesn't match stream's ByteStream::canRead() and ByteStream::canWrite(). |
Definition at line 105 of file bit_stream.hpp.
|
inline |
Returns the used underlying ByteStream.
Definition at line 169 of file bit_stream.hpp.
|
inlinenoexcept |
Definition at line 171 of file bit_stream.hpp.
|
inlinenodiscardnoexcept |
Changes the access-mode to write or read and resets position and cache to zero.
If the previous stream was in ioaccess_t::write mode, flush() is being called.
Certain ByteStream implementations may not allow random rewinding of the stream,
writeMode | new access-mode |
access
doesn't match stream's ByteStream::canRead() and ByteStream::canWrite() - or flush() failed, otherwise true Definition at line 184 of file bit_stream.hpp.
|
inlinenodiscardnoexcept |
Changes the write-mode to read, sets the underlying ByteStream to read-only and resets position and cache to zero.
If the previous stream was in ioaccess_t::write mode, flush() is being called.
Certain ByteStream implementations may not allow random rewinding of the stream,
Definition at line 208 of file bit_stream.hpp.
|
inlinenoexcept |
Returns endian byte-order of stream storage.
Only affects multi-byte r/w operations, e.g. readU16(), writeU16(), etc.
Definition at line 231 of file bit_stream.hpp.
|
inlineconstexprnoexcept |
Returns true in case stream is in write mode, false if in read mode.
Definition at line 234 of file bit_stream.hpp.
|
inlineconstexprnoexcept |
Returns ioaccess_t stream mode.
Definition at line 236 of file bit_stream.hpp.
|
inlinenoexcept |
Closing the underlying stream, implies flush()
.
Implementation will null
the stream references, hence setStream(Object)
must be called before re-using instance.
If the closed stream was in output mode
, flush()
is being called.
IOException |
Definition at line 251 of file bit_stream.hpp.
|
inlinenoexcept |
Synchronizes underlying ByteStream output stream operations in writeMode(), or does nothing.
Method also flushes incomplete bytes to the underlying ByteStream and hence skips to the next byte position.
Definition at line 265 of file bit_stream.hpp.
|
inlinenodiscardnoexcept |
Set markpos
to current bit-position, allowing the stream to be seekMark().
seek() will clear markpos
if > newPos.
For implementations where seek() doesn't allow random rewinding of the stream, setMark() will allow rewinding back to markpos
if not exceeding readLimit
.
readlimit | maximum number of bytes able to read before invalidating the markpos . |
Definition at line 291 of file bit_stream.hpp.
|
inlinenoexcept |
Returns the markpos
set via setMark() or ByteStream::npos if unset.
Definition at line 301 of file bit_stream.hpp.
|
inlinenoexcept |
Returns the readLimit
set via setMark().
If unset either 0 or implicit limit.
Definition at line 304 of file bit_stream.hpp.
|
inlinenodiscardnoexcept |
Seeks stream bit-position to markpos
as set via setMark().
markpos
is kept, hence seekMark() can be called multiple times.
Definition at line 314 of file bit_stream.hpp.
|
inlineconstexprnoexcept |
Returns filled read bit-cache-size, i.e.
up to 64-bit MaxBitCacheSize reading.
Definition at line 329 of file bit_stream.hpp.
|
inlineconstexprnoexcept |
Returns number of cached bits.
Definition at line 351 of file bit_stream.hpp.
|
inlineconstexprnoexcept |
Return the next cached bit position.
Definition at line 359 of file bit_stream.hpp.
|
inline |
Returns the 64-bit MaxBitCacheSize cache buffer value.
Definition at line 374 of file bit_stream.hpp.
|
inlinenoexcept |
Returns the bit position in the stream.
Definition at line 382 of file bit_stream.hpp.
Sets this stream's bit position.
A set mark is cleared.
Known supporting implementation is ByteBufferStream
and ByteArrayStream
.
newPos | desired absolute bit-position |
Definition at line 404 of file bit_stream.hpp.
Skip given number of bits.
n | number of bits to skip |
Definition at line 431 of file bit_stream.hpp.
|
inlinenodiscardnoexcept |
Read incoming bit in least-significant-bit (LSB) first order.
-1
if end-of-stream is reached. Definition at line 487 of file bit_stream.hpp.
|
inlinenodiscardnoexcept |
Write given bit in least-significant-bit (LSB) first order.
bit |
Definition at line 511 of file bit_stream.hpp.
|
inlinenodiscardnoexcept |
Read incoming bits in least-significant-bit (LSB) first order.
n | number of bits, maximum 64 bits |
Definition at line 530 of file bit_stream.hpp.
|
inlinenodiscardnoexcept |
Write given bits in least-significant-bit (LSB) first order.
n | number of bits, maximum 64 bits |
bits | the bits to write |
Definition at line 580 of file bit_stream.hpp.
|
inlinenodiscardnoexcept |
Read incoming uint8_t
via readBits32().
In case of a int8_t
2-complement signed value, simply cast the result.
bits | reference to result |
Definition at line 638 of file bit_stream.hpp.
|
inlinenodiscardnoexcept |
Write the given 8 bits via writeBits31(int, int)
.
Definition at line 654 of file bit_stream.hpp.
|
inlinenodiscardnoexcept |
Read uint16_t
.
If stream byteOrder() != lb_endian_t::native, result is bytes swapped via jau::bswap().
bits | reference to result |
Definition at line 669 of file bit_stream.hpp.
|
inlinenodiscardnoexcept |
Read int16_t
.
If stream byteOrder() != lb_endian_t::native, result is bytes swapped via jau::bswap().
bits | reference to result |
Definition at line 690 of file bit_stream.hpp.
|
inlinenodiscardnoexcept |
Write uint16_t
If stream byteOrder() != lb_endian_t::native, result is bytes swapped via jau::bswap().
bits | data to write |
Definition at line 699 of file bit_stream.hpp.
|
inlinenodiscardnoexcept |
Read uint32_t
.
If stream byteOrder() != lb_endian_t::native, result is bytes swapped via jau::bswap().
bits | reference to result |
Definition at line 721 of file bit_stream.hpp.
|
inlinenodiscardnoexcept |
Write uint32_t
.
If stream byteOrder() != lb_endian_t::native, result is bytes swapped via jau::bswap().
bits | data to write |
Definition at line 747 of file bit_stream.hpp.
|
inline |
|
inline |
|
inlinestatic |
|
staticconstexpr |
Invalid position constant, denoting unset mark() or invalid position.
Value: std::numeric_limits<size_type>::max()
Definition at line 74 of file bit_stream.hpp.
|
staticconstexpr |
Maximum read bitCacheSizeRead() and fixed 64-bit write cache size.
Definition at line 77 of file bit_stream.hpp.