Buffer abstraction (headers)
More...
#include <stdint.h>
#include <glib.h>
Go to the source code of this file.
|
typedef struct imquic_buffer_chunk | imquic_buffer_chunk |
| Buffer chunk.
|
|
typedef struct imquic_buffer | imquic_buffer |
| Buffer made of multiple chunks (possibly with gaps)
|
|
Buffer abstraction (headers)
- Author
- Lorenzo Miniero loren.nosp@m.zo@m.nosp@m.eetec.nosp@m.ho.c.nosp@m.om
- Copyright
- MIT License
Abstraction of a chunked buffer, to be used either during CRYPTO exchanges in the Initial/Handshake phase, or with STREAM after a connection has been established. It provides a high level interface to adding chunks to the queue (in a gap-aware way), and to retrieving data in an ordered way (waiting in case gaps are encountered).
◆ imquic_buffer
typedef struct imquic_buffer imquic_buffer |
Buffer made of multiple chunks (possibly with gaps)
◆ imquic_buffer_chunk
typedef struct imquic_buffer_chunk imquic_buffer_chunk |
◆ imquic_buffer_append()
int imquic_buffer_append |
( |
imquic_buffer * | buf, |
|
|
uint8_t * | data, |
|
|
uint64_t | length ) |
Helper method to add new data at the end of the buffer, as a new chunk.
- Parameters
-
buf | The imquic_buffer instance to add data to |
data | The data to add to the buffer |
length | Length of this new data |
- Returns
- 0 in case of success, a negative integer otherwise
◆ imquic_buffer_chunk_free()
Helper to quickly free a buffer chunk.
- Parameters
-
chunk | The buffer chunk to free |
◆ imquic_buffer_create()
Helper method to create a new buffer.
- Parameters
-
stream_id | Stream ID this buffer belongs to (ignored when used with CRYPTO frames) |
- Returns
- A pointer to a new imquic_buffer instance, if successful, or NULL otherwise
◆ imquic_buffer_destroy()
Helper method to destroy an existing buffer.
- Parameters
-
◆ imquic_buffer_get()
Helper method to get a chunk of data from the buffer.
- Note
- If there's data in the buffer, but the current offset points at a gap of data that hasn't been added yet, this function will not return anything, since this buffer API is conceived to read data in an ordered way. If data is found, the base offset is modified to point at the end of the returned chunk, which means a new imquic_buffer_peek or imquic_buffer_get call will point at the next chunk in the buffer.
- Parameters
-
- Returns
- A buffer chunk, if successful, or NULL otherwise
◆ imquic_buffer_peek()
Helper method to peek at a buffer and check if there's data to read.
- Note
- If there's data in the buffer, but the current offset points at a gap of data that hasn't been added yet, this function will not return anything, since this buffer API is conceived to read data in an ordered way. If data is found, the base offset is not modified, which means a new imquic_buffer_peek call will return the same chunk until imquic_buffer_get is called.
- Parameters
-
- Returns
- A buffer chunk, if successful, or NULL otherwise
◆ imquic_buffer_print()
Helper method to print the contents of a buffer.
- Parameters
-
level | Log level at which this should be printed |
buf | The imquic_buffer instance whose content should be printed |
◆ imquic_buffer_put()
int imquic_buffer_put |
( |
imquic_buffer * | buf, |
|
|
uint8_t * | data, |
|
|
uint64_t | offset, |
|
|
uint64_t | length ) |
Helper method to add new data to the buffer at a specific offset, as a new chunk.
- Note
- In case the new data overlaps data already in the buffer, the new data is truncated accordingly to fit
- Parameters
-
buf | The imquic_buffer instance to add data to |
data | The data to add to the buffer |
offset | Offset in the overall buffer where this new data should be placed |
length | Length of this new data |
- Returns
- 0 in case of success, a negative integer otherwise