Ruby: prism/util/pm_buffer.h Source File

Ruby 3.3.5p100 (2024-09-03 revision ef084cc8f4958c1b6e4ead99136631bef6d8ddba)

pm_buffer.h
Go to the documentation of this file.
1
6#ifndef PRISM_BUFFER_H
7#define PRISM_BUFFER_H
8
9#include "prism/defines.h"
10
11#include <assert.h>
12#include <stdbool.h>
13#include <stdint.h>
14#include <stdlib.h>
15#include <string.h>
16
21 typedef struct {
23 size_t length;
24
26 size_t capacity;
27
29 char *value;
30} pm_buffer_t;
31
37 PRISM_EXPORTED_FUNCTION size_t pm_buffer_sizeof(void);
38
46bool pm_buffer_init_capacity(pm_buffer_t *buffer, size_t capacity);
47
54 PRISM_EXPORTED_FUNCTION bool pm_buffer_init(pm_buffer_t *buffer);
55
62 PRISM_EXPORTED_FUNCTION char * pm_buffer_value(pm_buffer_t *buffer);
63
70 PRISM_EXPORTED_FUNCTION size_t pm_buffer_length(pm_buffer_t *buffer);
71
78void pm_buffer_append_zeroes(pm_buffer_t *buffer, size_t length);
79
87 void pm_buffer_append_format(pm_buffer_t *buffer, const char *format, ...) PRISM_ATTRIBUTE_FORMAT(2, 3);
88
96void pm_buffer_append_string(pm_buffer_t *buffer, const char *value, size_t length);
97
105void pm_buffer_append_bytes(pm_buffer_t *buffer, const uint8_t *value, size_t length);
106
113void pm_buffer_append_byte(pm_buffer_t *buffer, uint8_t value);
114
121void pm_buffer_append_varuint(pm_buffer_t *buffer, uint32_t value);
122
129void pm_buffer_append_varsint(pm_buffer_t *buffer, int32_t value);
130
137void pm_buffer_concat(pm_buffer_t *destination, const pm_buffer_t *source);
138
144 PRISM_EXPORTED_FUNCTION void pm_buffer_free(pm_buffer_t *buffer);
145
146#endif
assert.h
pm_buffer_init_capacity
bool pm_buffer_init_capacity(pm_buffer_t *buffer, size_t capacity)
Initialize a pm_buffer_t with the given capacity.
Definition pm_buffer.c:15
pm_buffer_sizeof
PRISM_EXPORTED_FUNCTION size_t pm_buffer_sizeof(void)
Return the size of the pm_buffer_t struct.
Definition pm_buffer.c:7
pm_buffer_value
PRISM_EXPORTED_FUNCTION char * pm_buffer_value(pm_buffer_t *buffer)
Return the value of the buffer.
Definition pm_buffer.c:35
pm_buffer_append_format
void pm_buffer_append_format(pm_buffer_t *buffer, const char *format,...) PRISM_ATTRIBUTE_FORMAT(2
Append a formatted string to the buffer.
pm_buffer_append_string
void void pm_buffer_append_string(pm_buffer_t *buffer, const char *value, size_t length)
Append a string to the buffer.
Definition pm_buffer.c:116
pm_buffer_append_zeroes
void pm_buffer_append_zeroes(pm_buffer_t *buffer, size_t length)
Append the given amount of space as zeroes to the buffer.
Definition pm_buffer.c:83
pm_buffer_append_varuint
void pm_buffer_append_varuint(pm_buffer_t *buffer, uint32_t value)
Append a 32-bit unsigned integer to the buffer as a variable-length integer.
Definition pm_buffer.c:141
pm_buffer_append_byte
void pm_buffer_append_byte(pm_buffer_t *buffer, uint8_t value)
Append a single byte to the buffer.
Definition pm_buffer.c:132
pm_buffer_init
PRISM_EXPORTED_FUNCTION bool pm_buffer_init(pm_buffer_t *buffer)
Initialize a pm_buffer_t with its default values.
Definition pm_buffer.c:27
pm_buffer_append_varsint
void pm_buffer_append_varsint(pm_buffer_t *buffer, int32_t value)
Append a 32-bit signed integer to the buffer as a variable-length integer.
Definition pm_buffer.c:158
pm_buffer_free
PRISM_EXPORTED_FUNCTION void pm_buffer_free(pm_buffer_t *buffer)
Free the memory associated with the buffer.
Definition pm_buffer.c:177
pm_buffer_length
PRISM_EXPORTED_FUNCTION size_t pm_buffer_length(pm_buffer_t *buffer)
Return the length of the buffer.
Definition pm_buffer.c:43
pm_buffer_append_bytes
void pm_buffer_append_bytes(pm_buffer_t *buffer, const uint8_t *value, size_t length)
Append a list of bytes to the buffer.
Definition pm_buffer.c:124
pm_buffer_concat
void pm_buffer_concat(pm_buffer_t *destination, const pm_buffer_t *source)
Concatenate one buffer onto another.
Definition pm_buffer.c:167
defines.h
Macro definitions used throughout the prism library.
PRISM_ATTRIBUTE_FORMAT
#define PRISM_ATTRIBUTE_FORMAT(string_index, argument_index)
Certain compilers support specifying that a function accepts variadic parameters that look like print...
Definition defines.h:43
PRISM_EXPORTED_FUNCTION
#define PRISM_EXPORTED_FUNCTION
By default, we compile with -fvisibility=hidden.
Definition defines.h:32
stdbool.h
C99 shim for <stdbool.h>
pm_buffer_t
A pm_buffer_t is a simple memory buffer that stores data in a contiguous block of memory.
Definition pm_buffer.h:21
pm_buffer_t::capacity
size_t capacity
The capacity of the buffer in bytes that has been allocated.
Definition pm_buffer.h:26
pm_buffer_t::length
size_t length
The length of the buffer in bytes.
Definition pm_buffer.h:23
pm_buffer_t::value
char * value
A pointer to the start of the buffer.
Definition pm_buffer.h:29