Ruby: prism/pack.h File Reference

Ruby 3.4.9p82 (2026-03-11 revision 76cca827ab52ab1d346a728f068d5b8da3e2952b)

Typedefs | Enumerations | Functions
pack.h File Reference

A pack template string parser. More...

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

Go to the source code of this file.

## Typedefs
typedef enum pm_pack_version | pm_pack_version
| The version of the pack template language that we are parsing.
typedef enum pm_pack_variant | pm_pack_variant
| The type of pack template we are parsing.
typedef enum pm_pack_type | pm_pack_type
| A directive within the pack template.
typedef enum pm_pack_signed | pm_pack_signed
| The signness of a pack directive.
typedef enum pm_pack_endian | pm_pack_endian
| The endianness of a pack directive.
typedef enum pm_pack_size | pm_pack_size
| The size of an integer pack directive.
typedef enum pm_pack_length_type | pm_pack_length_type
| The type of length of a pack directive.
typedef enum pm_pack_encoding | pm_pack_encoding
| The type of encoding for a pack template string.
typedef enum pm_pack_result | pm_pack_result
| The result of parsing a pack template.

## Enumerations
enum | pm_pack_version { PM_PACK_VERSION_3_2_0 }
| The version of the pack template language that we are parsing. More...
enum | pm_pack_variant { PM_PACK_VARIANT_PACK , PM_PACK_VARIANT_UNPACK }
| The type of pack template we are parsing. More...
enum | pm_pack_type { PM_PACK_SPACE , PM_PACK_COMMENT , PM_PACK_INTEGER , PM_PACK_UTF8 , PM_PACK_BER , PM_PACK_FLOAT , PM_PACK_STRING_SPACE_PADDED , PM_PACK_STRING_NULL_PADDED , PM_PACK_STRING_NULL_TERMINATED , PM_PACK_STRING_MSB , PM_PACK_STRING_LSB , PM_PACK_STRING_HEX_HIGH , PM_PACK_STRING_HEX_LOW , PM_PACK_STRING_UU , PM_PACK_STRING_MIME , PM_PACK_STRING_BASE64 , PM_PACK_STRING_FIXED , PM_PACK_STRING_POINTER , PM_PACK_MOVE , PM_PACK_BACK , PM_PACK_NULL , PM_PACK_END }
| A directive within the pack template. More...
enum | pm_pack_signed { PM_PACK_UNSIGNED , PM_PACK_SIGNED , PM_PACK_SIGNED_NA }
| The signness of a pack directive. More...
enum | pm_pack_endian { PM_PACK_AGNOSTIC_ENDIAN , PM_PACK_LITTLE_ENDIAN , PM_PACK_BIG_ENDIAN , PM_PACK_NATIVE_ENDIAN , PM_PACK_ENDIAN_NA }
| The endianness of a pack directive. More...
enum | pm_pack_size { PM_PACK_SIZE_SHORT , PM_PACK_SIZE_INT , PM_PACK_SIZE_LONG , PM_PACK_SIZE_LONG_LONG , PM_PACK_SIZE_8 , PM_PACK_SIZE_16 , PM_PACK_SIZE_32 , PM_PACK_SIZE_64 , PM_PACK_SIZE_P , PM_PACK_SIZE_NA }
| The size of an integer pack directive. More...
enum | pm_pack_length_type { PM_PACK_LENGTH_FIXED , PM_PACK_LENGTH_MAX , PM_PACK_LENGTH_RELATIVE , PM_PACK_LENGTH_NA }
| The type of length of a pack directive. More...
enum | pm_pack_encoding { PM_PACK_ENCODING_START , PM_PACK_ENCODING_ASCII_8BIT , PM_PACK_ENCODING_US_ASCII , PM_PACK_ENCODING_UTF_8 }
| The type of encoding for a pack template string. More...
enum | pm_pack_result { PM_PACK_OK , PM_PACK_ERROR_UNSUPPORTED_DIRECTIVE , PM_PACK_ERROR_UNKNOWN_DIRECTIVE , PM_PACK_ERROR_LENGTH_TOO_BIG , PM_PACK_ERROR_BANG_NOT_ALLOWED , PM_PACK_ERROR_DOUBLE_ENDIAN }
| The result of parsing a pack template. More...

## Functions
PRISM_EXPORTED_FUNCTION pm_pack_result | pm_pack_parse (pm_pack_variant variant, const char **format, const char *format_end, pm_pack_type *type, pm_pack_signed *signed_type, pm_pack_endian *endian, pm_pack_size *size, pm_pack_length_type *length_type, uint64_t *length, pm_pack_encoding *encoding)
| Parse a single directive from a pack or unpack format string.
PRISM_EXPORTED_FUNCTION size_t | pm_size_to_native (pm_pack_size size)
| Prism abstracts sizes away from the native system - this converts an abstract size to a native size.

## Detailed Description

A pack template string parser.

Definition in file pack.h.

## Typedef Documentation

## ◆ pm_pack_encoding

typedef enum pm_pack_encoding pm_pack_encoding

The type of encoding for a pack template string.

## ◆ pm_pack_endian

typedef enum pm_pack_endian pm_pack_endian

The endianness of a pack directive.

## ◆ pm_pack_length_type

typedef enum pm_pack_length_type pm_pack_length_type

The type of length of a pack directive.

## ◆ pm_pack_result

typedef enum pm_pack_result pm_pack_result

The result of parsing a pack template.

## ◆ pm_pack_signed

typedef enum pm_pack_signed pm_pack_signed

The signness of a pack directive.

## ◆ pm_pack_size

typedef enum pm_pack_size pm_pack_size

The size of an integer pack directive.

## ◆ pm_pack_type

typedef enum pm_pack_type pm_pack_type

A directive within the pack template.

## ◆ pm_pack_variant

typedef enum pm_pack_variant pm_pack_variant

The type of pack template we are parsing.

## ◆ pm_pack_version

typedef enum pm_pack_version pm_pack_version

The version of the pack template language that we are parsing.

## Enumeration Type Documentation

## ◆ pm_pack_encoding

enum pm_pack_encoding

The type of encoding for a pack template string.

Definition at line 99 of file pack.h.

## ◆ pm_pack_endian

enum pm_pack_endian

The endianness of a pack directive.

Definition at line 68 of file pack.h.

## ◆ pm_pack_length_type

enum pm_pack_length_type

The type of length of a pack directive.

Definition at line 91 of file pack.h.

## ◆ pm_pack_result

enum pm_pack_result

The result of parsing a pack template.

Definition at line 107 of file pack.h.

## ◆ pm_pack_signed

enum pm_pack_signed

The signness of a pack directive.

Definition at line 61 of file pack.h.

## ◆ pm_pack_size

enum pm_pack_size

The size of an integer pack directive.

Definition at line 77 of file pack.h.

## ◆ pm_pack_type

enum pm_pack_type

A directive within the pack template.

Definition at line 35 of file pack.h.

## ◆ pm_pack_variant

enum pm_pack_variant

The type of pack template we are parsing.

Definition at line 29 of file pack.h.

## ◆ pm_pack_version

enum pm_pack_version

The version of the pack template language that we are parsing.

Definition at line 24 of file pack.h.

## Function Documentation

## ◆ pm_pack_parse()

PRISM_EXPORTED_FUNCTION pm_pack_result pm_pack_parse | ( | pm_pack_variant | variant,
|  | const char ** | format,
|  | const char * | format_end,
|  | pm_pack_type * | type,
|  | pm_pack_signed * | signed_type,
|  | pm_pack_endian * | endian,
|  | pm_pack_size * | size,
|  | pm_pack_length_type * | length_type,
|  | uint64_t * | length,
|  | pm_pack_encoding * | encoding )

Parse a single directive from a pack or unpack format string.

Parameters

  variant | (in) pack or unpack
  format | (in, out) the start of the next directive to parse on calling, and advanced beyond the parsed directive on return, or as much of it as was consumed until an error was encountered
  format_end | (in) the end of the format string
  type | (out) the type of the directive
  signed_type | (out) whether the value is signed
  endian | (out) the endianness of the value
  size | (out) the size of the value
  length_type | (out) what kind of length is specified
  length | (out) the length of the directive
  encoding | (in, out) takes the current encoding of the string which would result from parsing the whole format string, and returns a possibly changed directive - the encoding should be PM_PACK_ENCODING_START when pm_pack_parse is called for the first directive in a format string

Returns
  PM_PACK_OK on success or PM_PACK_ERROR_* on error

Note
  Consult Ruby documentation for the meaning of directives.

Definition at line 29 of file pack.c.

## ◆ pm_size_to_native()

PRISM_EXPORTED_FUNCTION size_t pm_size_to_native | ( | pm_pack_size | size | ) |

Prism abstracts sizes away from the native system - this converts an abstract size to a native size.

Parameters

  size | The abstract size to convert.

Returns
  The native size.

Definition at line 484 of file pack.c.