libdragon
Loading...
Searching...
No Matches
Data Structures | Functions
ringbuf_internal.h File Reference

Go to the source code of this file.

Data Structures

struct  decompress_ringbuf_t
 A ring buffer used for streaming decompression. More...
 

Functions

void __ringbuf_init (decompress_ringbuf_t *ringbuf, uint8_t *buf, int winsize)
 Initialize a ring buffer for streaming decompression.
 
void __ringbuf_write (decompress_ringbuf_t *ringbuf, uint8_t *src, int count)
 Write an array of bytes into the ring buffer.
 
void __ringbuf_copy (decompress_ringbuf_t *ringbuf, int copy_offset, uint8_t *dst, int count)
 Extract data from the ring buffer, updating it at the same time.
 

Detailed Description

Author
Giovanni Bajo giova.nosp@m.nnib.nosp@m.ajo@g.nosp@m.mail.nosp@m..com

Data Structure Documentation

◆ decompress_ringbuf_t

struct decompress_ringbuf_t

A ring buffer used for streaming decompression.

Data Fields
uint8_t * ringbuf The ring buffer itself.
unsigned int ringbuf_size Size of the ring buffer (power of two)
unsigned int ringbuf_pos Current write position in the ring buffer.

Function Documentation

◆ __ringbuf_init()

void __ringbuf_init ( decompress_ringbuf_t ringbuf,
uint8_t *  buf,
int  winsize 
)

Initialize a ring buffer for streaming decompression.

Parameters
ringbufPointer to the ring buffer structure to initialize.
bufBuffer to use as the ring buffer storage.
winsizeWindow size (must be a power of 2).

◆ __ringbuf_write()

void __ringbuf_write ( decompress_ringbuf_t ringbuf,
uint8_t *  src,
int  count 
)

Write an array of bytes into the ring buffer.

Parameters
ringbufThe ring buffer to write to.
srcThe source array to write from.
countThe number of bytes to write.

◆ __ringbuf_copy()

void __ringbuf_copy ( decompress_ringbuf_t ringbuf,
int  copy_offset,
uint8_t *  dst,
int  count 
)

Extract data from the ring buffer, updating it at the same time.

This function is used to implement a typical match-copy of LZ algorithms. Given the ring buffer and the position to copy from, it will copy the specified number of bytes into the destination buffer, while also updating the ring buffer with the copied data.

It correctly handles overlaps, so if copy_offset is 1 and count is 100, the last character in the ring buffer will be copied 100 times to the output (and to the ring buffer itself).

Parameters
ringbufThe ring buffer
copy_offsetOffset to copy from, relative to the current position.
dstDestination buffer
countNumber of bytes to copy