Ruby  3.4.0dev (2024-11-23 revision b4d13fac3dd5420475aa1e14fdad8137da7e3ee0)
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 // We optionally support parsing String#pack templates. For systems that don't
12 // want or need this functionality, it can be turned off with the
13 // PRISM_EXCLUDE_PACK define.
14 #ifdef PRISM_EXCLUDE_PACK
15 
16 void pm_pack_parse(void);
17 
18 #else
19 
20 #include <stdint.h>
21 #include <stdlib.h>
22 
24 typedef enum pm_pack_version {
25  PM_PACK_VERSION_3_2_0
27 
29 typedef enum pm_pack_variant {
30  PM_PACK_VARIANT_PACK,
31  PM_PACK_VARIANT_UNPACK
33 
35 typedef enum pm_pack_type {
36  PM_PACK_SPACE,
37  PM_PACK_COMMENT,
38  PM_PACK_INTEGER,
39  PM_PACK_UTF8,
40  PM_PACK_BER,
41  PM_PACK_FLOAT,
42  PM_PACK_STRING_SPACE_PADDED,
43  PM_PACK_STRING_NULL_PADDED,
44  PM_PACK_STRING_NULL_TERMINATED,
45  PM_PACK_STRING_MSB,
46  PM_PACK_STRING_LSB,
47  PM_PACK_STRING_HEX_HIGH,
48  PM_PACK_STRING_HEX_LOW,
49  PM_PACK_STRING_UU,
50  PM_PACK_STRING_MIME,
51  PM_PACK_STRING_BASE64,
52  PM_PACK_STRING_FIXED,
53  PM_PACK_STRING_POINTER,
54  PM_PACK_MOVE,
55  PM_PACK_BACK,
56  PM_PACK_NULL,
57  PM_PACK_END
59 
61 typedef enum pm_pack_signed {
62  PM_PACK_UNSIGNED,
63  PM_PACK_SIGNED,
64  PM_PACK_SIGNED_NA
66 
68 typedef enum pm_pack_endian {
69  PM_PACK_AGNOSTIC_ENDIAN,
70  PM_PACK_LITTLE_ENDIAN, // aka 'VAX', or 'V'
71  PM_PACK_BIG_ENDIAN, // aka 'network', or 'N'
72  PM_PACK_NATIVE_ENDIAN,
73  PM_PACK_ENDIAN_NA
75 
77 typedef enum pm_pack_size {
78  PM_PACK_SIZE_SHORT,
79  PM_PACK_SIZE_INT,
80  PM_PACK_SIZE_LONG,
81  PM_PACK_SIZE_LONG_LONG,
82  PM_PACK_SIZE_8,
83  PM_PACK_SIZE_16,
84  PM_PACK_SIZE_32,
85  PM_PACK_SIZE_64,
86  PM_PACK_SIZE_P,
87  PM_PACK_SIZE_NA
89 
91 typedef enum pm_pack_length_type {
92  PM_PACK_LENGTH_FIXED,
93  PM_PACK_LENGTH_MAX,
94  PM_PACK_LENGTH_RELATIVE, // special case for unpack @*
95  PM_PACK_LENGTH_NA
97 
99 typedef enum pm_pack_encoding {
100  PM_PACK_ENCODING_START,
101  PM_PACK_ENCODING_ASCII_8BIT,
102  PM_PACK_ENCODING_US_ASCII,
103  PM_PACK_ENCODING_UTF_8
105 
107 typedef enum pm_pack_result {
108  PM_PACK_OK,
109  PM_PACK_ERROR_UNSUPPORTED_DIRECTIVE,
110  PM_PACK_ERROR_UNKNOWN_DIRECTIVE,
111  PM_PACK_ERROR_LENGTH_TOO_BIG,
112  PM_PACK_ERROR_BANG_NOT_ALLOWED,
113  PM_PACK_ERROR_DOUBLE_ENDIAN
115 
140  pm_pack_variant variant,
141  const char **format,
142  const char *format_end,
144  pm_pack_signed *signed_type,
145  pm_pack_endian *endian,
146  pm_pack_size *size,
147  pm_pack_length_type *length_type,
148  uint64_t *length,
149  pm_pack_encoding *encoding
150 );
151 
160 
161 #endif
162 
163 #endif
VALUE type(ANYARGS)
ANYARGS-ed function type.
Definition: cxxanyargs.hpp:56
pm_pack_encoding
The type of encoding for a pack template string.
Definition: pack.h:99
pm_pack_result
The result of parsing a pack template.
Definition: pack.h:107
pm_pack_variant
The type of pack template we are parsing.
Definition: pack.h:29
pm_pack_endian
The endianness of a pack directive.
Definition: pack.h:68
pm_pack_signed
The signness of a pack directive.
Definition: pack.h:61
pm_pack_size
The size of an integer pack directive.
Definition: pack.h:77
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:484
pm_pack_length_type
The type of length of a pack directive.
Definition: pack.h:91
pm_pack_version
The version of the pack template language that we are parsing.
Definition: pack.h:24
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:29
pm_pack_type
A directive within the pack template.
Definition: pack.h:35
Macro definitions used throughout the prism library.
#define PRISM_EXPORTED_FUNCTION
By default, we compile with -fvisibility=hidden.
Definition: defines.h:50