/// Advances the stream by `len` bytes, and returns a pointer to the chunk that
/// was skipped. The stream must be byte aligned.
-static inline const u8 *IO_read_bytes(istream_t *const in, size_t len);
+static inline const u8 *IO_get_read_ptr(istream_t *const in, size_t len);
/// Advances the stream by `len` bytes, and returns a pointer to the chunk that
/// was skipped so it can be written to.
-static inline u8 *IO_write_bytes(ostream_t *const out, size_t len);
+static inline u8 *IO_get_write_ptr(ostream_t *const out, size_t len);
/// Advance the inner state by `len` bytes. The stream must be byte aligned.
static inline void IO_advance_input(istream_t *const in, size_t len);
case 0: {
// "Raw_Block - this is an uncompressed block. Block_Size is the
// number of bytes to read and copy."
- const u8 *const read_ptr = IO_read_bytes(in, block_len);
- u8 *const write_ptr = IO_write_bytes(out, block_len);
+ const u8 *const read_ptr = IO_get_read_ptr(in, block_len);
+ u8 *const write_ptr = IO_get_write_ptr(out, block_len);
// Copy the raw data into the output
memcpy(write_ptr, read_ptr, block_len);
// "RLE_Block - this is a single byte, repeated N times. In which
// case, Block_Size is the size to regenerate, while the
// "compressed" block is just 1 byte (the byte to repeat)."
- const u8 *const read_ptr = IO_read_bytes(in, 1);
- u8 *const write_ptr = IO_write_bytes(out, block_len);
+ const u8 *const read_ptr = IO_get_read_ptr(in, 1);
+ u8 *const write_ptr = IO_get_write_ptr(out, block_len);
// Copy `block_len` copies of `read_ptr[0]` to the output
memset(write_ptr, read_ptr[0], block_len);
switch (block_type) {
case 0: {
// "Raw_Literals_Block - Literals are stored uncompressed."
- const u8 *const read_ptr = IO_read_bytes(in, size);
+ const u8 *const read_ptr = IO_get_read_ptr(in, size);
memcpy(*literals, read_ptr, size);
break;
}
case 1: {
// "RLE_Literals_Block - Literals consist of a single byte value repeated N times."
- const u8 *const read_ptr = IO_read_bytes(in, 1);
+ const u8 *const read_ptr = IO_get_read_ptr(in, 1);
memset(*literals, read_ptr[0], size);
break;
}
num_symbs = header - 127;
const size_t bytes = (num_symbs + 1) / 2;
- const u8 *const weight_src = IO_read_bytes(in, bytes);
+ const u8 *const weight_src = IO_get_read_ptr(in, bytes);
for (int i = 0; i < num_symbs; i++) {
// "They are encoded forward, 2
}
const size_t len = IO_istream_len(in);
- const u8 *const src = IO_read_bytes(in, len);
+ const u8 *const src = IO_get_read_ptr(in, len);
// "After writing the last bit containing information, the compressor writes
// a single 1-bit and then fills the byte with 0-7 0 bits of padding."
}
case seq_rle: {
// "RLE_Mode : it's a single code, repeated Number_of_Sequences times."
- const u8 symb = IO_read_bytes(in, 1)[0];
+ const u8 symb = IO_get_read_ptr(in, 1)[0];
FSE_init_dtable_rle(table, symb);
break;
}
// Copy any leftover literals
{
size_t len = IO_istream_len(&litstream);
- u8 *const write_ptr = IO_write_bytes(out, len);
- const u8 *const read_ptr = IO_read_bytes(&litstream, len);
+ u8 *const write_ptr = IO_get_write_ptr(out, len);
+ const u8 *const read_ptr = IO_get_read_ptr(&litstream, len);
memcpy(write_ptr, read_ptr, len);
total_output += len;
CORRUPTION();
}
- u8 *const write_ptr = IO_write_bytes(out, seq.literal_length);
+ u8 *const write_ptr = IO_get_write_ptr(out, seq.literal_length);
const u8 *const read_ptr =
- IO_read_bytes(litstream, seq.literal_length);
+ IO_get_read_ptr(litstream, seq.literal_length);
// Copy literals to output
memcpy(write_ptr, read_ptr, seq.literal_length);
static void execute_match_copy(frame_context_t *const ctx, size_t offset,
size_t match_length, size_t total_output,
ostream_t *const out) {
- u8 *write_ptr = IO_write_bytes(out, match_length);
+ u8 *write_ptr = IO_get_write_ptr(out, match_length);
if (total_output <= ctx->header.window_size) {
// In this case offset might go back into the dictionary
if (offset > total_output + ctx->dict_content_len) {
BAD_ALLOC();
}
- const u8 *const content = IO_read_bytes(in, dict->content_size);
+ const u8 *const content = IO_get_read_ptr(in, dict->content_size);
memcpy(dict->content, content, dict->content_size);
}
/// Returns a pointer where `len` bytes can be read, and advances the internal
/// state. The stream must be byte aligned.
-static inline const u8 *IO_read_bytes(istream_t *const in, size_t len) {
+static inline const u8 *IO_get_read_ptr(istream_t *const in, size_t len) {
if (len > in->len) {
INP_SIZE();
}
return ptr;
}
/// Returns a pointer to write `len` bytes to, and advances the internal state
-static inline u8 *IO_write_bytes(ostream_t *const out, size_t len) {
+static inline u8 *IO_get_write_ptr(ostream_t *const out, size_t len) {
if (len > out->len) {
OUT_SIZE();
}
/// `in` must be byte aligned
static inline istream_t IO_make_sub_istream(istream_t *const in, size_t len) {
// Consume `len` bytes of the parent stream
- const u8 *const ptr = IO_read_bytes(in, len);
+ const u8 *const ptr = IO_get_read_ptr(in, len);
// Make a substream using the pointer to those `len` bytes
return IO_make_istream(ptr, len);
if (len == 0) {
INP_SIZE();
}
- const u8 *const src = IO_read_bytes(in, len);
+ const u8 *const src = IO_get_read_ptr(in, len);
// "Each bitstream must be read backward, that is starting from the end down
// to the beginning. Therefore it's necessary to know the size of each
if (len == 0) {
INP_SIZE();
}
- const u8 *const src = IO_read_bytes(in, len);
+ const u8 *const src = IO_get_read_ptr(in, len);
// "Each bitstream must be read backward, that is starting from the end down
// to the beginning. Therefore it's necessary to know the size of each