bytebuffer.h 814 Bytes
Newer Older
1 2
#ifndef _BYTEBUFFER_H_
#define _BYTEBUFFER_H_
3 4 5 6 7

#include <stdlib.h>
#include <stdint.h>


8 9
#define BUFFER_INITIAL_CAPACITY 512

10 11 12 13 14 15 16 17 18 19 20
typedef struct {
	uint8_t * restrict bytes;
	size_t position;
	size_t capacity;
} buffer_t;

//

void buffer_init (buffer_t * restrict buffer, const size_t capacity);
void buffer_destroy (buffer_t * restrict buffer);

21
uint8_t * buffer_claim (buffer_t * restrict buffer, const size_t size);
22 23 24 25 26 27 28

inline size_t
buffer_position (const buffer_t * restrict buffer) {
	return buffer->position;
}

inline size_t
29 30
buffer_length (const buffer_t * restrict buffer) {
	return buffer->position;
31 32 33 34 35 36 37
}

inline void
buffer_clear (buffer_t * restrict buffer) {
	buffer->position = 0;
}

38
uint8_t * buffer_ptr_block (
39 40 41
	const buffer_t * restrict buffer, size_t position, size_t size
);

42
#endif /* _BYTEBUFFER_H_ */