4 * A wrapper around a contiguous block of allocated memory.
9 #include "prism/defines.h"
10 #include "prism/util/pm_char.h"
19 * A pm_buffer_t is a simple memory buffer that stores data in a contiguous
23 /** The length of the buffer in bytes. */
26 /** The capacity of the buffer in bytes that has been allocated. */
29 /** A pointer to the start of the buffer. */
34 * Return the size of the pm_buffer_t struct.
36 * @returns The size of the pm_buffer_t struct.
38 PRISM_EXPORTED_FUNCTION
size_t pm_buffer_sizeof(void);
41 * Initialize a pm_buffer_t with the given capacity.
43 * @param buffer The buffer to initialize.
44 * @param capacity The capacity of the buffer.
45 * @returns True if the buffer was initialized successfully, false otherwise.
47 bool pm_buffer_init_capacity(pm_buffer_t
*buffer
, size_t capacity
);
50 * Initialize a pm_buffer_t with its default values.
52 * @param buffer The buffer to initialize.
53 * @returns True if the buffer was initialized successfully, false otherwise.
55 PRISM_EXPORTED_FUNCTION
bool pm_buffer_init(pm_buffer_t
*buffer
);
58 * Return the value of the buffer.
60 * @param buffer The buffer to get the value of.
61 * @returns The value of the buffer.
63 PRISM_EXPORTED_FUNCTION
char * pm_buffer_value(const pm_buffer_t
*buffer
);
66 * Return the length of the buffer.
68 * @param buffer The buffer to get the length of.
69 * @returns The length of the buffer.
71 PRISM_EXPORTED_FUNCTION
size_t pm_buffer_length(const pm_buffer_t
*buffer
);
74 * Append the given amount of space as zeroes to the buffer.
76 * @param buffer The buffer to append to.
77 * @param length The amount of space to append and zero.
79 void pm_buffer_append_zeroes(pm_buffer_t
*buffer
, size_t length
);
82 * Append a formatted string to the buffer.
84 * @param buffer The buffer to append to.
85 * @param format The format string to append.
86 * @param ... The arguments to the format string.
88 void pm_buffer_append_format(pm_buffer_t
*buffer
, const char *format
, ...) PRISM_ATTRIBUTE_FORMAT(2, 3);
91 * Append a string to the buffer.
93 * @param buffer The buffer to append to.
94 * @param value The string to append.
95 * @param length The length of the string to append.
97 void pm_buffer_append_string(pm_buffer_t
*buffer
, const char *value
, size_t length
);
100 * Append a list of bytes to the buffer.
102 * @param buffer The buffer to append to.
103 * @param value The bytes to append.
104 * @param length The length of the bytes to append.
106 void pm_buffer_append_bytes(pm_buffer_t
*buffer
, const uint8_t *value
, size_t length
);
109 * Append a single byte to the buffer.
111 * @param buffer The buffer to append to.
112 * @param value The byte to append.
114 void pm_buffer_append_byte(pm_buffer_t
*buffer
, uint8_t value
);
117 * Append a 32-bit unsigned integer to the buffer as a variable-length integer.