Skip to content

Add ByteBuffer struct (pointer + length + capacity) #31

@davidgaspardev

Description

@davidgaspardev

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions