Debian Codegraph @

include/prism/pack.h

raw symbols SCIP
1 /**
2 * @file pack.h
3 *
4 * A pack template string parser.
5 */
6 #ifndef PRISM_PACK_H
7 #define PRISM_PACK_Hcxx . . $ `include/prism/pack.h:7:9`!
8
9 #include "prism/defines.h"cxx . . $ `<file>/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
23 /** The version of the pack template language that we are parsing. */
24 typedef enum pm_pack_versioncxx . . $ pm_pack_version# {
25 PM_PACK_VERSION_3_2_0cxx . . $ PM_PACK_VERSION_3_2_0.
26 } pm_pack_versioncxx . . $ pm_pack_version#;
27
28 /** The type of pack template we are parsing. */
29 typedef enum pm_pack_variantcxx . . $ pm_pack_variant# {
30 PM_PACK_VARIANT_PACKcxx . . $ PM_PACK_VARIANT_PACK.,
31 PM_PACK_VARIANT_UNPACKcxx . . $ PM_PACK_VARIANT_UNPACK.
32 } pm_pack_variantcxx . . $ pm_pack_variant#;
33
34 /** A directive within the pack template. */
35 typedef enum pm_pack_typecxx . . $ pm_pack_type# {
36 PM_PACK_SPACEcxx . . $ PM_PACK_SPACE.,
37 PM_PACK_COMMENTcxx . . $ PM_PACK_COMMENT.,
38 PM_PACK_INTEGERcxx . . $ PM_PACK_INTEGER.,
39 PM_PACK_UTF8cxx . . $ PM_PACK_UTF8.,
40 PM_PACK_BERcxx . . $ PM_PACK_BER.,
41 PM_PACK_FLOATcxx . . $ PM_PACK_FLOAT.,
42 PM_PACK_STRING_SPACE_PADDEDcxx . . $ PM_PACK_STRING_SPACE_PADDED.,
43 PM_PACK_STRING_NULL_PADDEDcxx . . $ PM_PACK_STRING_NULL_PADDED.,
44 PM_PACK_STRING_NULL_TERMINATEDcxx . . $ PM_PACK_STRING_NULL_TERMINATED.,
45 PM_PACK_STRING_MSBcxx . . $ PM_PACK_STRING_MSB.,
46 PM_PACK_STRING_LSBcxx . . $ PM_PACK_STRING_LSB.,
47 PM_PACK_STRING_HEX_HIGHcxx . . $ PM_PACK_STRING_HEX_HIGH.,
48 PM_PACK_STRING_HEX_LOWcxx . . $ PM_PACK_STRING_HEX_LOW.,
49 PM_PACK_STRING_UUcxx . . $ PM_PACK_STRING_UU.,
50 PM_PACK_STRING_MIMEcxx . . $ PM_PACK_STRING_MIME.,
51 PM_PACK_STRING_BASE64cxx . . $ PM_PACK_STRING_BASE64.,
52 PM_PACK_STRING_FIXEDcxx . . $ PM_PACK_STRING_FIXED.,
53 PM_PACK_STRING_POINTERcxx . . $ PM_PACK_STRING_POINTER.,
54 PM_PACK_MOVEcxx . . $ PM_PACK_MOVE.,
55 PM_PACK_BACKcxx . . $ PM_PACK_BACK.,
56 PM_PACK_NULLcxx . . $ PM_PACK_NULL.,
57 PM_PACK_ENDcxx . . $ PM_PACK_END.
58 } pm_pack_typecxx . . $ pm_pack_type#;
59
60 /** The signness of a pack directive. */
61 typedef enum pm_pack_signedcxx . . $ pm_pack_signed# {
62 PM_PACK_UNSIGNEDcxx . . $ PM_PACK_UNSIGNED.,
63 PM_PACK_SIGNEDcxx . . $ PM_PACK_SIGNED.,
64 PM_PACK_SIGNED_NAcxx . . $ PM_PACK_SIGNED_NA.
65 } pm_pack_signedcxx . . $ pm_pack_signed#;
66
67 /** The endianness of a pack directive. */
68 typedef enum pm_pack_endiancxx . . $ pm_pack_endian# {
69 PM_PACK_AGNOSTIC_ENDIANcxx . . $ PM_PACK_AGNOSTIC_ENDIAN.,
70 PM_PACK_LITTLE_ENDIANcxx . . $ PM_PACK_LITTLE_ENDIAN., // aka 'VAX', or 'V'
71 PM_PACK_BIG_ENDIANcxx . . $ PM_PACK_BIG_ENDIAN., // aka 'network', or 'N'
72 PM_PACK_NATIVE_ENDIANcxx . . $ PM_PACK_NATIVE_ENDIAN.,
73 PM_PACK_ENDIAN_NAcxx . . $ PM_PACK_ENDIAN_NA.
74 } pm_pack_endiancxx . . $ pm_pack_endian#;
75
76 /** The size of an integer pack directive. */
77 typedef enum pm_pack_sizecxx . . $ pm_pack_size# {
78 PM_PACK_SIZE_SHORTcxx . . $ PM_PACK_SIZE_SHORT.,
79 PM_PACK_SIZE_INTcxx . . $ PM_PACK_SIZE_INT.,
80 PM_PACK_SIZE_LONGcxx . . $ PM_PACK_SIZE_LONG.,
81 PM_PACK_SIZE_LONG_LONGcxx . . $ PM_PACK_SIZE_LONG_LONG.,
82 PM_PACK_SIZE_8cxx . . $ PM_PACK_SIZE_8.,
83 PM_PACK_SIZE_16cxx . . $ PM_PACK_SIZE_16.,
84 PM_PACK_SIZE_32cxx . . $ PM_PACK_SIZE_32.,
85 PM_PACK_SIZE_64cxx . . $ PM_PACK_SIZE_64.,
86 PM_PACK_SIZE_Pcxx . . $ PM_PACK_SIZE_P.,
87 PM_PACK_SIZE_NAcxx . . $ PM_PACK_SIZE_NA.
88 } pm_pack_sizecxx . . $ pm_pack_size#;
89
90 /** The type of length of a pack directive. */
91 typedef enum pm_pack_length_typecxx . . $ pm_pack_length_type# {
92 PM_PACK_LENGTH_FIXEDcxx . . $ PM_PACK_LENGTH_FIXED.,
93 PM_PACK_LENGTH_MAXcxx . . $ PM_PACK_LENGTH_MAX.,
94 PM_PACK_LENGTH_RELATIVEcxx . . $ PM_PACK_LENGTH_RELATIVE., // special case for unpack @*
95 PM_PACK_LENGTH_NAcxx . . $ PM_PACK_LENGTH_NA.
96 } pm_pack_length_typecxx . . $ pm_pack_length_type#;
97
98 /** The type of encoding for a pack template string. */
99 typedef enum pm_pack_encodingcxx . . $ pm_pack_encoding# {
100 PM_PACK_ENCODING_STARTcxx . . $ PM_PACK_ENCODING_START.,
101 PM_PACK_ENCODING_ASCII_8BITcxx . . $ PM_PACK_ENCODING_ASCII_8BIT.,
102 PM_PACK_ENCODING_US_ASCIIcxx . . $ PM_PACK_ENCODING_US_ASCII.,
103 PM_PACK_ENCODING_UTF_8cxx . . $ PM_PACK_ENCODING_UTF_8.
104 } pm_pack_encodingcxx . . $ pm_pack_encoding#;
105
106 /** The result of parsing a pack template. */
107 typedef enum pm_pack_resultcxx . . $ pm_pack_result# {
108 PM_PACK_OKcxx . . $ PM_PACK_OK.,
109 PM_PACK_ERROR_UNSUPPORTED_DIRECTIVEcxx . . $ PM_PACK_ERROR_UNSUPPORTED_DIRECTIVE.,
110 PM_PACK_ERROR_UNKNOWN_DIRECTIVEcxx . . $ PM_PACK_ERROR_UNKNOWN_DIRECTIVE.,
111 PM_PACK_ERROR_LENGTH_TOO_BIGcxx . . $ PM_PACK_ERROR_LENGTH_TOO_BIG.,
112 PM_PACK_ERROR_BANG_NOT_ALLOWEDcxx . . $ PM_PACK_ERROR_BANG_NOT_ALLOWED.,
113 PM_PACK_ERROR_DOUBLE_ENDIANcxx . . $ PM_PACK_ERROR_DOUBLE_ENDIAN.
114 } pm_pack_resultcxx . . $ pm_pack_result#;
115
116 /**
117 * Parse a single directive from a pack or unpack format string.
118 *
119 * @param variant (in) pack or unpack
120 * @param format (in, out) the start of the next directive to parse on calling,
121 * and advanced beyond the parsed directive on return, or as much of it as
122 * was consumed until an error was encountered
123 * @param format_end (in) the end of the format string
124 * @param type (out) the type of the directive
125 * @param signed_type (out) whether the value is signed
126 * @param endian (out) the endianness of the value
127 * @param size (out) the size of the value
128 * @param length_type (out) what kind of length is specified
129 * @param length (out) the length of the directive
130 * @param encoding (in, out) takes the current encoding of the string which
131 * would result from parsing the whole format string, and returns a possibly
132 * changed directive - the encoding should be `PM_PACK_ENCODING_START` when
133 * pm_pack_parse is called for the first directive in a format string
134 *
135 * @return `PM_PACK_OK` on success or `PM_PACK_ERROR_*` on error
136 * @note Consult Ruby documentation for the meaning of directives.
137 */
138 PRISM_EXPORTED_FUNCTIONcxx . . $ `include/prism/defines.h:50:19`! pm_pack_resultcxx . . $ pm_pack_result#
139 pm_pack_parsecxx . . $ pm_pack_parse(3da3df61e6ef7ac1).(
140 pm_pack_variantcxx . . $ pm_pack_variant# variant,
141 const char **format,
142 const char *format_end,
143 pm_pack_typecxx . . $ pm_pack_type# *type,
144 pm_pack_signedcxx . . $ pm_pack_signed# *signed_type,
145 pm_pack_endiancxx . . $ pm_pack_endian# *endian,
146 pm_pack_sizecxx . . $ pm_pack_size# *size,
147 pm_pack_length_typecxx . . $ pm_pack_length_type# *length_type,
148 uint64_tcxx . . $ uint64_t# *length,
149 pm_pack_encodingcxx . . $ pm_pack_encoding# *encoding
150 );
151
152 /**
153 * Prism abstracts sizes away from the native system - this converts an abstract
154 * size to a native size.
155 *
156 * @param size The abstract size to convert.
157 * @return The native size.
158 */
159 PRISM_EXPORTED_FUNCTIONcxx . . $ `include/prism/defines.h:50:19`! size_t pm_size_to_nativecxx . . $ pm_size_to_native(84ed60057d071c1b).(pm_pack_sizecxx . . $ pm_pack_size# size);
160
161 #endif
162
163 #endif