17#ifndef __CWIST_CORE_SEQ_SEQ_H__
18#define __CWIST_CORE_SEQ_SEQ_H__
29#define CWIST_SEQ_HEADER_SIZE 8
32#define CWIST_SEQ_DEFAULT_CHUNK_PAYLOAD 1024
36#define CWIST_SEQ_MAX_CHUNKS 8192
37#define CWIST_SEQ_MAX_REASSEMBLED_SIZE (64U * 1024U * 1024U)
89 uint16_t payload_len, uint16_t chunk_size);
101bool cwist_seq_split(
const uint8_t *data,
size_t len, uint16_t chunk_payload_size,
cwist_seq_assembler_t * cwist_seq_assembler_create_limited(size_t max_data_len)
Create an assembler with a maximum possible reassembled size.
bool cwist_seq_assembler_is_complete(const cwist_seq_assembler_t *a)
Return true when every expected chunk has been received.
struct cwist_seq_message cwist_seq_message_t
Split a message into sequenced chunks.
bool cwist_seq_chunk_parse(const uint8_t *data, size_t len, cwist_seq_chunk_t *out)
Parse a sequence chunk from raw bytes.
struct cwist_seq_chunk cwist_seq_chunk_t
Parsed view of one sequenced chunk.
void cwist_seq_assembler_reset(cwist_seq_assembler_t *a)
Reset an assembler so it can receive a new message.
cwist_seq_assembler_t * cwist_seq_assembler_create(void)
Create an empty assembler.
void cwist_seq_assembler_destroy(cwist_seq_assembler_t *a)
Destroy an assembler and its internal buffer.
size_t cwist_seq_assembler_recovery_targets(const cwist_seq_assembler_t *a, uint16_t *out, size_t out_cap)
Return the sequence numbers still required to complete a message.
void cwist_seq_message_free(cwist_seq_message_t *msg)
Free all buffers allocated by cwist_seq_split().
bool cwist_seq_assembler_get_data(cwist_seq_assembler_t *a, const uint8_t **out_data, size_t *out_len)
Borrow the assembled message when complete.
bool cwist_seq_assembler_feed(cwist_seq_assembler_t *a, const cwist_seq_chunk_t *chunk)
Feed one parsed chunk into the assembler.
struct cwist_seq_assembler cwist_seq_assembler_t
Opaque stateful assembler that reorders chunks and detects duplicates.
void cwist_seq_chunk_build_header(uint8_t out[CWIST_SEQ_HEADER_SIZE], uint16_t seq, uint16_t total, uint16_t payload_len, uint16_t chunk_size)
Write an 8-byte sequence header.
#define CWIST_SEQ_HEADER_SIZE
bool cwist_seq_split(const uint8_t *data, size_t len, uint16_t chunk_payload_size, cwist_seq_message_t *out)
Split data into sequenced chunks.
Parsed view of one sequenced chunk.
uint16_t payload_len
Payload length in this chunk.
uint16_t total
Total chunks in the message.
uint16_t chunk_size
Payload length of a full chunk.
const uint8_t * payload
Pointer to payload bytes.
uint16_t seq
1-based sequence number.
Split a message into sequenced chunks.
size_t count
Number of chunks.
size_t * chunk_lens
Length of each chunk buffer.
uint8_t ** chunks
Array of chunk buffers.