Ruby: prism/pack.h Source File

Ruby 3.3.4p94 (2024-07-09 revision be1089c8ec5ba40e09b1553e36b3174bf4014d9d)

pack.h
Go to the documentation of this file.
1
6#ifndef PRISM_PACK_H
7#define PRISM_PACK_H
8
9#include "prism/defines.h"
10
11#include <stdint.h>
12#include <stdlib.h>
13
15 typedef enum pm_pack_version {
16 PM_PACK_VERSION_3_2_0
17} pm_pack_version;
18
20 typedef enum pm_pack_variant {
21 PM_PACK_VARIANT_PACK,
22 PM_PACK_VARIANT_UNPACK
23} pm_pack_variant;
24
26 typedef enum pm_pack_type {
27 PM_PACK_SPACE,
28 PM_PACK_COMMENT,
29 PM_PACK_INTEGER,
30 PM_PACK_UTF8,
31 PM_PACK_BER,
32 PM_PACK_FLOAT,
33 PM_PACK_STRING_SPACE_PADDED,
34 PM_PACK_STRING_NULL_PADDED,
35 PM_PACK_STRING_NULL_TERMINATED,
36 PM_PACK_STRING_MSB,
37 PM_PACK_STRING_LSB,
38 PM_PACK_STRING_HEX_HIGH,
39 PM_PACK_STRING_HEX_LOW,
40 PM_PACK_STRING_UU,
41 PM_PACK_STRING_MIME,
42 PM_PACK_STRING_BASE64,
43 PM_PACK_STRING_FIXED,
44 PM_PACK_STRING_POINTER,
45 PM_PACK_MOVE,
46 PM_PACK_BACK,
47 PM_PACK_NULL,
48 PM_PACK_END
49} pm_pack_type;
50
52 typedef enum pm_pack_signed {
53 PM_PACK_UNSIGNED,
54 PM_PACK_SIGNED,
55 PM_PACK_SIGNED_NA
56} pm_pack_signed;
57
59 typedef enum pm_pack_endian {
60 PM_PACK_AGNOSTIC_ENDIAN,
61 PM_PACK_LITTLE_ENDIAN, // aka 'VAX', or 'V'
62 PM_PACK_BIG_ENDIAN, // aka 'network', or 'N'
63 PM_PACK_NATIVE_ENDIAN,
64 PM_PACK_ENDIAN_NA
65} pm_pack_endian;
66
68 typedef enum pm_pack_size {
69 PM_PACK_SIZE_SHORT,
70 PM_PACK_SIZE_INT,
71 PM_PACK_SIZE_LONG,
72 PM_PACK_SIZE_LONG_LONG,
73 PM_PACK_SIZE_8,
74 PM_PACK_SIZE_16,
75 PM_PACK_SIZE_32,
76 PM_PACK_SIZE_64,
77 PM_PACK_SIZE_P,
78 PM_PACK_SIZE_NA
79} pm_pack_size;
80
82 typedef enum pm_pack_length_type {
83 PM_PACK_LENGTH_FIXED,
84 PM_PACK_LENGTH_MAX,
85 PM_PACK_LENGTH_RELATIVE, // special case for unpack @*
86 PM_PACK_LENGTH_NA
87} pm_pack_length_type;
88
90 typedef enum pm_pack_encoding {
91 PM_PACK_ENCODING_START,
92 PM_PACK_ENCODING_ASCII_8BIT,
93 PM_PACK_ENCODING_US_ASCII,
94 PM_PACK_ENCODING_UTF_8
95} pm_pack_encoding;
96
98 typedef enum pm_pack_result {
99 PM_PACK_OK,
100 PM_PACK_ERROR_UNSUPPORTED_DIRECTIVE,
101 PM_PACK_ERROR_UNKNOWN_DIRECTIVE,
102 PM_PACK_ERROR_LENGTH_TOO_BIG,
103 PM_PACK_ERROR_BANG_NOT_ALLOWED,
104 PM_PACK_ERROR_DOUBLE_ENDIAN
105} pm_pack_result;
106
129 PRISM_EXPORTED_FUNCTION pm_pack_result
130 pm_pack_parse(
131 pm_pack_variant variant,
132 const char **format,
133 const char *format_end,
134 pm_pack_type *type,
135 pm_pack_signed *signed_type,
136 pm_pack_endian *endian,
137 pm_pack_size *size,
138 pm_pack_length_type *length_type,
139 uint64_t *length,
140 pm_pack_encoding *encoding
141);
142
150 PRISM_EXPORTED_FUNCTION size_t pm_size_to_native(pm_pack_size size);
151
152#endif
pm_pack_encoding
pm_pack_encoding
The type of encoding for a pack template string.
Definition pack.h:90
pm_pack_result
pm_pack_result
The result of parsing a pack template.
Definition pack.h:98
pm_pack_variant
pm_pack_variant
The type of pack template we are parsing.
Definition pack.h:20
pm_pack_endian
pm_pack_endian
The endianness of a pack directive.
Definition pack.h:59
pm_pack_signed
pm_pack_signed
The signness of a pack directive.
Definition pack.h:52
pm_pack_size
pm_pack_size
The size of an integer pack directive.
Definition pack.h:68
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.
Definition pack.c:457
pm_pack_length_type
pm_pack_length_type
The type of length of a pack directive.
Definition pack.h:82
pm_pack_version
pm_pack_version
The version of the pack template language that we are parsing.
Definition pack.h:15
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.
Definition pack.c:10
pm_pack_type
pm_pack_type
A directive within the pack template.
Definition pack.h:26
defines.h
Macro definitions used throughout the prism library.
PRISM_EXPORTED_FUNCTION
#define PRISM_EXPORTED_FUNCTION
By default, we compile with -fvisibility=hidden.
Definition defines.h:32