RPNXCortado
C++23 JVM class-file, bytecode, validation, and JAR toolkit
Loading...
Searching...
No Matches
types.hpp
Go to the documentation of this file.
1// AI Generated 2026 Ryan P. Nicholl <rnicholl@protonmail.com>
2// SPDX-License-Identifier: Apache-2.0
3
10
11#ifndef RPNX_CORTADO_TYPES_HPP
12#define RPNX_CORTADO_TYPES_HPP
13
14#include <cstddef>
15#include <cstdint>
16#include <rpnx/macros.hpp>
17#include <string>
18#include <variant>
19#include <vector>
20
24namespace rpnx::cortado
25{
27 inline constexpr std::uint32_t class_file_magic = 0xCAFEBABEU;
28
30 enum class constant_pool_tag : std::uint8_t { utf8 = 1, integer = 3, floating_point = 4, long_integer = 5, double_precision = 6, class_reference = 7, string = 8, field_reference = 9, method_reference = 10, interface_method_reference = 11, name_and_type = 12, method_handle = 15, method_type = 16, dynamic = 17, invoke_dynamic = 18, module = 19, package = 20 };
31
34 {
35 std::uint16_t value{};
36 RPNX_MEMBER_METADATA(constant_pool_index, value);
37 };
38
41 {
42 std::uint16_t value{};
43 RPNX_MEMBER_METADATA(bootstrap_method_index, value);
44 };
45
48 {
49 std::uint16_t minor{};
50 std::uint16_t major{};
51 RPNX_MEMBER_METADATA(class_file_version, minor, major);
52 };
53
55 enum class method_handle_reference_kind : std::uint8_t { get_field = 1, get_static = 2, put_field = 3, put_static = 4, invoke_virtual = 5, invoke_static = 6, invoke_special = 7, new_invoke_special = 8, invoke_interface = 9 };
56
58 enum class class_access_flags : std::uint16_t { none = 0, is_public = 0x0001, is_final = 0x0010, invokes_special_super = 0x0020, is_interface = 0x0200, is_abstract = 0x0400, is_synthetic = 0x1000, is_annotation = 0x2000, is_enum = 0x4000, is_module = 0x8000 };
59
61 [[nodiscard]] constexpr class_access_flags operator|(class_access_flags left, class_access_flags right) noexcept
62 {
63 return static_cast< class_access_flags >(static_cast< std::uint16_t >(left) | static_cast< std::uint16_t >(right));
64 }
65
67 enum class field_access_flags : std::uint16_t { none = 0, is_public = 0x0001, is_private = 0x0002, is_protected = 0x0004, is_static = 0x0008, is_final = 0x0010, is_volatile = 0x0040, is_transient = 0x0080, is_synthetic = 0x1000, is_enum = 0x4000 };
68
70 [[nodiscard]] constexpr field_access_flags operator|(field_access_flags left, field_access_flags right) noexcept
71 {
72 return static_cast< field_access_flags >(static_cast< std::uint16_t >(left) | static_cast< std::uint16_t >(right));
73 }
74
76 enum class method_access_flags : std::uint16_t { none = 0, is_public = 0x0001, is_private = 0x0002, is_protected = 0x0004, is_static = 0x0008, is_final = 0x0010, is_synchronized = 0x0020, is_bridge = 0x0040, has_variable_arguments = 0x0080, is_native = 0x0100, is_abstract = 0x0400, is_strict = 0x0800, is_synthetic = 0x1000 };
77
79 [[nodiscard]] constexpr method_access_flags operator|(method_access_flags left, method_access_flags right) noexcept
80 {
81 return static_cast< method_access_flags >(static_cast< std::uint16_t >(left) | static_cast< std::uint16_t >(right));
82 }
83
86 {
87 static constexpr constant_pool_tag tag = constant_pool_tag::utf8;
88 static constexpr std::size_t slot_count = 1;
89 std::string bytes;
90 RPNX_MEMBER_METADATA(utf8_constant, bytes);
91 };
92
95 {
96 static constexpr constant_pool_tag tag = constant_pool_tag::integer;
97 static constexpr std::size_t slot_count = 1;
98 std::uint32_t bits{};
99 RPNX_MEMBER_METADATA(integer_constant, bits);
100 };
101
104 {
105 static constexpr constant_pool_tag tag = constant_pool_tag::floating_point;
106 static constexpr std::size_t slot_count = 1;
107 std::uint32_t bits{};
108 RPNX_MEMBER_METADATA(float_constant, bits);
109 };
110
113 {
114 static constexpr constant_pool_tag tag = constant_pool_tag::long_integer;
115 static constexpr std::size_t slot_count = 2;
116 std::uint64_t bits{};
117 RPNX_MEMBER_METADATA(long_constant, bits);
118 };
119
122 {
123 static constexpr constant_pool_tag tag = constant_pool_tag::double_precision;
124 static constexpr std::size_t slot_count = 2;
125 std::uint64_t bits{};
126 RPNX_MEMBER_METADATA(double_constant, bits);
127 };
128
131 {
132 static constexpr constant_pool_tag tag = constant_pool_tag::class_reference;
133 static constexpr std::size_t slot_count = 1;
135 RPNX_MEMBER_METADATA(class_constant, name_index);
136 };
137
140 {
141 static constexpr constant_pool_tag tag = constant_pool_tag::string;
142 static constexpr std::size_t slot_count = 1;
144 RPNX_MEMBER_METADATA(string_constant, string_index);
145 };
146
149 {
150 static constexpr constant_pool_tag tag = constant_pool_tag::field_reference;
151 static constexpr std::size_t slot_count = 1;
154 RPNX_MEMBER_METADATA(fieldref_constant, class_index, name_and_type_index);
155 };
156
159 {
160 static constexpr constant_pool_tag tag = constant_pool_tag::method_reference;
161 static constexpr std::size_t slot_count = 1;
164 RPNX_MEMBER_METADATA(methodref_constant, class_index, name_and_type_index);
165 };
166
169 {
170 static constexpr constant_pool_tag tag = constant_pool_tag::interface_method_reference;
171 static constexpr std::size_t slot_count = 1;
175 };
176
179 {
180 static constexpr constant_pool_tag tag = constant_pool_tag::name_and_type;
181 static constexpr std::size_t slot_count = 1;
184 RPNX_MEMBER_METADATA(name_and_type_constant, name_index, descriptor_index);
185 };
186
189 {
190 static constexpr constant_pool_tag tag = constant_pool_tag::method_handle;
191 static constexpr std::size_t slot_count = 1;
192 method_handle_reference_kind reference_kind{method_handle_reference_kind::get_field};
195 };
196
199 {
200 static constexpr constant_pool_tag tag = constant_pool_tag::method_type;
201 static constexpr std::size_t slot_count = 1;
203 RPNX_MEMBER_METADATA(method_type_constant, descriptor_index);
204 };
205
208 {
209 static constexpr constant_pool_tag tag = constant_pool_tag::dynamic;
210 static constexpr std::size_t slot_count = 1;
214 };
215
218 {
219 static constexpr constant_pool_tag tag = constant_pool_tag::invoke_dynamic;
220 static constexpr std::size_t slot_count = 1;
224 };
225
228 {
229 static constexpr constant_pool_tag tag = constant_pool_tag::module;
230 static constexpr std::size_t slot_count = 1;
232 RPNX_MEMBER_METADATA(module_constant, name_index);
233 };
234
237 {
238 static constexpr constant_pool_tag tag = constant_pool_tag::package;
239 static constexpr std::size_t slot_count = 1;
241 RPNX_MEMBER_METADATA(package_constant, name_index);
242 };
243
245 using constant_pool_entry = std::variant< utf8_constant, integer_constant, float_constant, long_constant, double_constant, class_constant, string_constant, fieldref_constant, methodref_constant, interface_methodref_constant, name_and_type_constant, method_handle_constant, method_type_constant, dynamic_constant, invoke_dynamic_constant, module_constant, package_constant >;
246
248 enum class compression_method : std::uint16_t { stored = 0, deflated = 8 };
249
251 enum class jar_entry_flags : std::uint16_t { none = 0, utf8_names = 0x0800 };
252
255 {
256 std::uint16_t encoded_value{};
257 RPNX_MEMBER_METADATA(zip_dos_time, encoded_value);
258 };
259
262 {
263 std::uint16_t encoded_value{};
264 RPNX_MEMBER_METADATA(zip_dos_date, encoded_value);
265 };
266
269 {
270 std::uint16_t encoded_value{};
271 RPNX_MEMBER_METADATA(zip_internal_attributes, encoded_value);
272 };
273
276 {
277 std::uint32_t encoded_value{};
278 RPNX_MEMBER_METADATA(zip_external_attributes, encoded_value);
279 };
280
296
298 struct jar_file
299 {
300 std::vector< jar_entry > entries;
301 std::string comment;
302 RPNX_MEMBER_METADATA(jar_file, entries, comment);
303 };
304
307 {
308 std::size_t maximum_entry_uncompressed_size{256U * 1024U * 1024U};
309 std::size_t maximum_total_uncompressed_size{1024U * 1024U * 1024U};
311 };
312} // namespace rpnx::cortado
313
314#endif // RPNX_CORTADO_TYPES_HPP
JVM class-file, bytecode, validation, generation, and JAR APIs.
compression_method
Compression methods supported by JAR serialization.
Definition types.hpp:248
constant_pool_tag
A JVM constant-pool tag from JVMS section 4.4.
Definition types.hpp:30
method_handle_reference_kind
Valid reference-kind discriminators for CONSTANT_MethodHandle.
Definition types.hpp:55
field_access_flags
JVM field access flags.
Definition types.hpp:67
std::variant< utf8_constant, integer_constant, float_constant, long_constant, double_constant, class_constant, string_constant, fieldref_constant, methodref_constant, interface_methodref_constant, name_and_type_constant, method_handle_constant, method_type_constant, dynamic_constant, invoke_dynamic_constant, module_constant, package_constant > constant_pool_entry
A typed JVM constant-pool entry.
Definition types.hpp:245
class_access_flags
JVM class access flags.
Definition types.hpp:58
method_access_flags
JVM method access flags.
Definition types.hpp:76
constexpr std::uint32_t class_file_magic
The fixed magic value at the start of every JVM class file.
Definition types.hpp:27
jar_entry_flags
JAR entry flags preserved by this library.
Definition types.hpp:251
constexpr class_access_flags operator|(class_access_flags left, class_access_flags right) noexcept
Combines JVM class access flags without discarding their domain type.
Definition types.hpp:61
A type-safe index into the BootstrapMethods attribute.
Definition types.hpp:41
std::uint16_t value
Zero-based index into bootstrap_methods_attribute::methods.
Definition types.hpp:42
A CONSTANT_Class entry.
Definition types.hpp:131
constant_pool_index name_index
Index of a utf8_constant containing an internal class or array name.
Definition types.hpp:134
A JVM class-file version pair.
Definition types.hpp:48
std::uint16_t minor
Minor class-file version, including 65535 for preview features.
Definition types.hpp:49
std::uint16_t major
Major class-file version; this release supports values 45 through 70.
Definition types.hpp:50
A type-safe index into a JVM constant pool.
Definition types.hpp:34
std::uint16_t value
One-based logical pool slot, or zero where the enclosing structure permits a sentinel.
Definition types.hpp:35
A CONSTANT_Double entry represented by its exact IEEE 754 bits.
Definition types.hpp:122
std::uint64_t bits
Exact IEEE 754 binary64 representation, preserving NaN payloads.
Definition types.hpp:125
A CONSTANT_Dynamic entry.
Definition types.hpp:208
constant_pool_index name_and_type_index
Index describing the dynamic constant's name and field descriptor.
Definition types.hpp:212
bootstrap_method_index bootstrap_method_attr_index
Bootstrap method used to compute the constant.
Definition types.hpp:211
A CONSTANT_Fieldref entry.
Definition types.hpp:149
constant_pool_index class_index
Index of the declaring class_constant.
Definition types.hpp:152
constant_pool_index name_and_type_index
Index of the field's name_and_type_constant.
Definition types.hpp:153
A CONSTANT_Float entry represented by its exact IEEE 754 bits.
Definition types.hpp:104
std::uint32_t bits
Exact IEEE 754 binary32 representation, preserving NaN payloads.
Definition types.hpp:107
A CONSTANT_Integer entry represented by its exact IEEE/JVM bits.
Definition types.hpp:95
std::uint32_t bits
Exact two's-complement bit pattern of the JVM int value.
Definition types.hpp:98
A CONSTANT_InterfaceMethodref entry.
Definition types.hpp:169
constant_pool_index class_index
Index of the declaring interface's class_constant.
Definition types.hpp:172
constant_pool_index name_and_type_index
Index of the interface method's name_and_type_constant.
Definition types.hpp:173
A CONSTANT_InvokeDynamic entry.
Definition types.hpp:218
constant_pool_index name_and_type_index
Index describing the call-site name and method descriptor.
Definition types.hpp:222
bootstrap_method_index bootstrap_method_attr_index
Bootstrap method used to link the call site.
Definition types.hpp:221
One owning JAR/ZIP entry, with its data stored uncompressed in memory.
Definition types.hpp:283
zip_dos_time modification_time
Packed last-modification time.
Definition types.hpp:290
zip_dos_date modification_date
Packed last-modification date.
Definition types.hpp:291
std::string comment
Exact entry-comment bytes, excluding its wire length.
Definition types.hpp:286
zip_external_attributes external_attributes
Preserved central-directory external attributes.
Definition types.hpp:293
std::vector< std::byte > extra
Exact central-directory extra field, excluding its wire length.
Definition types.hpp:285
jar_entry_flags flags
Preserved supported general-purpose flags.
Definition types.hpp:289
std::string name
Entry path bytes; use / separators for interoperable JAR names.
Definition types.hpp:284
std::vector< std::byte > data
Owning uncompressed entry contents.
Definition types.hpp:287
compression_method compression
Storage method to use when serializing.
Definition types.hpp:288
zip_internal_attributes internal_attributes
Preserved central-directory internal attributes.
Definition types.hpp:292
An owning JAR archive representation.
Definition types.hpp:299
std::vector< jar_entry > entries
Entries in central-directory order; duplicate names remain distinct.
Definition types.hpp:300
std::string comment
Exact end-of-central-directory archive comment.
Definition types.hpp:301
Explicit resource limits applied while reading an untrusted JAR archive.
Definition types.hpp:307
std::size_t maximum_total_uncompressed_size
Maximum inflated bytes accepted across the archive.
Definition types.hpp:309
std::size_t maximum_entry_uncompressed_size
Maximum inflated bytes accepted for one entry.
Definition types.hpp:308
A CONSTANT_Long entry represented by its exact two's-complement bits.
Definition types.hpp:113
std::uint64_t bits
Exact two's-complement bit pattern of the JVM long value.
Definition types.hpp:116
A CONSTANT_MethodHandle entry.
Definition types.hpp:189
constant_pool_index reference_index
Index of the compatible field or method reference constant.
Definition types.hpp:193
method_handle_reference_kind reference_kind
Operation performed by the handle.
Definition types.hpp:192
A CONSTANT_MethodType entry.
Definition types.hpp:199
constant_pool_index descriptor_index
Index of a utf8_constant containing a method descriptor.
Definition types.hpp:202
A CONSTANT_Methodref entry.
Definition types.hpp:159
constant_pool_index name_and_type_index
Index of the method's name_and_type_constant.
Definition types.hpp:163
constant_pool_index class_index
Index of the declaring class or interface constant.
Definition types.hpp:162
A CONSTANT_Module entry.
Definition types.hpp:228
constant_pool_index name_index
Index of the module-name utf8_constant.
Definition types.hpp:231
A CONSTANT_NameAndType entry.
Definition types.hpp:179
constant_pool_index descriptor_index
Index of the field or method descriptor utf8_constant.
Definition types.hpp:183
constant_pool_index name_index
Index of the member-name utf8_constant.
Definition types.hpp:182
A CONSTANT_Package entry.
Definition types.hpp:237
constant_pool_index name_index
Index of the package-name utf8_constant.
Definition types.hpp:240
A CONSTANT_String entry.
Definition types.hpp:140
constant_pool_index string_index
Index of the utf8_constant containing the string contents.
Definition types.hpp:143
A CONSTANT_Utf8 entry.
Definition types.hpp:86
static constexpr constant_pool_tag tag
Wire tag for this entry type.
Definition types.hpp:87
std::string bytes
Exact modified UTF-8 bytes, without the wire length prefix.
Definition types.hpp:89
static constexpr std::size_t slot_count
Number of logical constant-pool slots occupied.
Definition types.hpp:88
A packed MS-DOS date value from a ZIP entry header.
Definition types.hpp:262
std::uint16_t encoded_value
Packed ZIP year-since-1980, month, and day fields.
Definition types.hpp:263
A packed MS-DOS time value from a ZIP entry header.
Definition types.hpp:255
std::uint16_t encoded_value
Packed ZIP hour, minute, and two-second-resolution second fields.
Definition types.hpp:256
Host-defined external attributes from a ZIP central-directory entry.
Definition types.hpp:276
std::uint32_t encoded_value
Exact central-directory host-defined external-attributes field.
Definition types.hpp:277
Host-defined internal attributes from a ZIP central-directory entry.
Definition types.hpp:269
std::uint16_t encoded_value
Exact central-directory internal-attributes field.
Definition types.hpp:270