Ruby: prism/util/pm_buffer.h File Reference

Ruby 3.3.6p108 (2024-11-05 revision 75015d4c1f6965b5e85e96fb309f1f2129f933c0)

Data Structures | Functions
pm_buffer.h File Reference

A wrapper around a contiguous block of allocated memory. More...

`#include "prism/defines.h"`
`#include <assert.h>`
`#include <stdbool.h>`
`#include <stdint.h>`
`#include <stdlib.h>`
`#include <string.h>`

Go to the source code of this file.

## Data Structures
struct | pm_buffer_t
| A pm_buffer_t is a simple memory buffer that stores data in a contiguous block of memory. More...

## Functions
PRISM_EXPORTED_FUNCTION size_t | pm_buffer_sizeof (void)
| Return the size of the pm_buffer_t struct.
bool | pm_buffer_init_capacity (pm_buffer_t *buffer, size_t capacity)
| Initialize a pm_buffer_t with the given capacity.
PRISM_EXPORTED_FUNCTION bool | pm_buffer_init (pm_buffer_t *buffer)
| Initialize a pm_buffer_t with its default values.
PRISM_EXPORTED_FUNCTION char * | pm_buffer_value (pm_buffer_t *buffer)
| Return the value of the buffer.
PRISM_EXPORTED_FUNCTION size_t | pm_buffer_length (pm_buffer_t *buffer)
| Return the length of the buffer.
void | pm_buffer_append_zeroes (pm_buffer_t *buffer, size_t length)
| Append the given amount of space as zeroes to the buffer.
void | pm_buffer_append_format (pm_buffer_t *buffer, const char *format,...) PRISM_ATTRIBUTE_FORMAT(2
| Append a formatted string to the buffer.
void void | pm_buffer_append_string (pm_buffer_t *buffer, const char *value, size_t length)
| Append a string to the buffer.
void | pm_buffer_append_bytes (pm_buffer_t *buffer, const uint8_t *value, size_t length)
| Append a list of bytes to the buffer.
void | pm_buffer_append_byte (pm_buffer_t *buffer, uint8_t value)
| Append a single byte to the buffer.
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.
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.
void | pm_buffer_concat (pm_buffer_t *destination, const pm_buffer_t *source)
| Concatenate one buffer onto another.
PRISM_EXPORTED_FUNCTION void | pm_buffer_free (pm_buffer_t *buffer)
| Free the memory associated with the buffer.

## Detailed Description

A wrapper around a contiguous block of allocated memory.

Definition in file pm_buffer.h.

## Function Documentation

## ◆ pm_buffer_append_byte()

void pm_buffer_append_byte | ( | pm_buffer_t * | buffer,
|  | uint8_t | value )

Append a single byte to the buffer.

Parameters

  buffer | The buffer to append to.
  value | The byte to append.

Definition at line 132 of file pm_buffer.c.

## ◆ 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.

Parameters

  buffer | The buffer to append to.
  value | The bytes to append.
  length | The length of the bytes to append.

Definition at line 124 of file pm_buffer.c.

## ◆ pm_buffer_append_format()

void pm_buffer_append_format | ( | pm_buffer_t * | buffer,
|  | const char * | format,
|  |  | ... )

Append a formatted string to the buffer.

Parameters

  buffer | The buffer to append to.
  format | The format string to append.
  ... | The arguments to the format string.

## ◆ 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.

Parameters

  buffer | The buffer to append to.
  value | The string to append.
  length | The length of the string to append.

Definition at line 116 of file pm_buffer.c.

## ◆ 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.

Parameters

  buffer | The buffer to append to.
  value | The integer to append.

Definition at line 158 of file pm_buffer.c.

## ◆ 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.

Parameters

  buffer | The buffer to append to.
  value | The integer to append.

Definition at line 141 of file pm_buffer.c.

## ◆ 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.

Parameters

  buffer | The buffer to append to.
  length | The amount of space to append and zero.

Definition at line 83 of file pm_buffer.c.

## ◆ pm_buffer_concat()

void pm_buffer_concat | ( | pm_buffer_t * | destination,
|  | const pm_buffer_t * | source )

Concatenate one buffer onto another.

Parameters

  destination | The buffer to concatenate onto.
  source | The buffer to concatenate.

Definition at line 167 of file pm_buffer.c.

## ◆ pm_buffer_free()

PRISM_EXPORTED_FUNCTION void pm_buffer_free | ( | pm_buffer_t * | buffer | ) |

Free the memory associated with the buffer.

Parameters

  buffer | The buffer to free.

Definition at line 177 of file pm_buffer.c.

## ◆ pm_buffer_init()

PRISM_EXPORTED_FUNCTION bool pm_buffer_init | ( | pm_buffer_t * | buffer | ) |

Initialize a pm_buffer_t with its default values.

Parameters

  buffer | The buffer to initialize.

Returns
  True if the buffer was initialized successfully, false otherwise.

Definition at line 27 of file pm_buffer.c.

## ◆ 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.

Parameters

  buffer | The buffer to initialize.
  capacity | The capacity of the buffer.

Returns
  True if the buffer was initialized successfully, false otherwise.

Definition at line 15 of file pm_buffer.c.

## ◆ pm_buffer_length()

PRISM_EXPORTED_FUNCTION size_t pm_buffer_length | ( | pm_buffer_t * | buffer | ) |

Return the length of the buffer.

Parameters

  buffer | The buffer to get the length of.

Returns
  The length of the buffer.

Definition at line 43 of file pm_buffer.c.

## ◆ pm_buffer_sizeof()

PRISM_EXPORTED_FUNCTION size_t pm_buffer_sizeof | ( | void |  | ) |

Return the size of the pm_buffer_t struct.

Returns
  The size of the pm_buffer_t struct.

Definition at line 7 of file pm_buffer.c.

## ◆ pm_buffer_value()

PRISM_EXPORTED_FUNCTION char * pm_buffer_value | ( | pm_buffer_t * | buffer | ) |

Return the value of the buffer.

Parameters

  buffer | The buffer to get the value of.

Returns
  The value of the buffer.

Definition at line 35 of file pm_buffer.c.