diff --git a/include/ki/util/BitStream.h b/include/ki/util/BitStream.h index 7baf141..3b26a94 100644 --- a/include/ki/util/BitStream.h +++ b/include/ki/util/BitStream.h @@ -21,6 +21,7 @@ namespace ki explicit stream_pos(intmax_t byte = 0, int bit = 0); stream_pos(const stream_pos &cp); + intmax_t as_bits() const; intmax_t get_byte() const; uint8_t get_bit() const; @@ -148,6 +149,20 @@ namespace ki } } + /** + * Copy memory from an external buffer into the bitstream's buffer from the current position. + * @param src The buffer to copy data from. + * @param bitsize The number of bits to copy from the src buffer. + */ + void write_copy(uint8_t *src, std::size_t bitsize); + + /** + * Copy memory from the bitstream's buffer into an external buffer. + * @param dst The destination buffer to copy data to. + * @param bitsize The number of bits to copy into the dst buffer. + */ + void read_copy(uint8_t *dst, std::size_t bitsize); + private: uint8_t *m_buffer; std::size_t m_buffer_size; diff --git a/include/ki/util/BitTypes.h b/include/ki/util/BitTypes.h index 048a86d..379600a 100644 --- a/include/ki/util/BitTypes.h +++ b/include/ki/util/BitTypes.h @@ -37,9 +37,9 @@ namespace ki >::type; /** - * The integer type that can most efficiently store N bits - * without signedness. - */ + * The integer type that can most efficiently store N bits + * without signedness. + */ using uint_type = typename std::conditional< N <= 8, uint8_t, @@ -162,27 +162,27 @@ namespace ki }; /** - * Represents a signed integer of N bits. - */ + * Represents a signed integer of N bits. + */ template using bi = BitInteger; /** - * Represents an unsigned integer of N bits. - */ + * Represents an unsigned integer of N bits. + */ template using bui = BitInteger; /** - * A utility to calculate the bitsize of a type. - */ + * A utility to calculate the bitsize of a type. + */ template struct bitsizeof { /** - * The number of bits a type will occupy if written to a BitStream. - * This does not reflect the size of the type in memory. - */ + * The number of bits a type will occupy if written to a BitStream. + * This does not reflect the size of the type in memory. + */ static constexpr std::size_t value = sizeof(T) * 8; }; @@ -206,4 +206,4 @@ namespace ki template struct is_integral> : std::true_type {}; -} \ No newline at end of file +}