Description
Implement a ByteBuffer struct that holds a data pointer alongside its length and allocated capacity, enabling safe handling of binary data (buffers that may contain \0 bytes in the middle).
typedef struct {
bytes_t data;
unsigned int len;
unsigned int cap;
} ByteBuffer;
Motivation
Current functions rely on null-terminated strings, which breaks for binary data. A ByteBuffer makes the length explicit and decouples it from the content.
References
- Dynamic array / buffer pattern — used in C++
std::vector, Rust Vec<u8>, Go []byte
- Wikipedia: Dynamic array
- Author of pattern: popularized by Brian Kernighan & Dennis Ritchie in The C Programming Language (1978) through manual buffer management idioms
Description
Implement a
ByteBufferstruct that holds a data pointer alongside its length and allocated capacity, enabling safe handling of binary data (buffers that may contain\0bytes in the middle).Motivation
Current functions rely on null-terminated strings, which breaks for binary data. A
ByteBuffermakes the length explicit and decouples it from the content.References
std::vector, RustVec<u8>, Go[]byte