RPNXCortado
C++23 JVM class-file, bytecode, validation, and JAR toolkit
Loading...
Searching...
No Matches
class_file.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
7
8#ifndef RPNX_CORTADO_CLASS_FILE_HPP
9#define RPNX_CORTADO_CLASS_FILE_HPP
10
11#include <cstddef>
12#include <iterator>
16#include <span>
17#include <stdexcept>
18#include <utility>
19#include <vector>
20
21namespace rpnx::cortado
22{
25 {
26 processing_mode mode{processing_mode::strict};
27 std::size_t maximum_attribute_length{256U * 1024U * 1024U};
28 std::size_t maximum_total_attribute_bytes{1024U * 1024U * 1024U};
29 std::size_t maximum_nesting_depth{256};
30 std::size_t maximum_structure_nodes{1'000'000};
32 };
33
36 {
37 processing_mode mode{processing_mode::strict};
38 RPNX_MEMBER_METADATA(class_file_write_options, mode);
39 };
40
42 template < typename T >
44 {
46 std::size_t bytes_read{};
47 };
48
55 [[nodiscard]] std::vector< std::byte > serialize_class_file(class_file const& value, class_file_write_options const& options = {});
56
63 [[nodiscard]] class_file deserialize_class_file(std::span< std::byte const > bytes, class_file_read_options const& options = {});
64
71 [[nodiscard]] deserialization_result< class_file > deserialize_class_file_prefix(std::span< std::byte const > bytes, class_file_read_options const& options = {});
72
80 template < typename OutputIt >
81 auto serialize_iter(class_file const& value, OutputIt output, class_file_write_options const& options = {}) -> OutputIt
82 {
83 std::vector< std::byte > const bytes = serialize_class_file(value, options);
84 for (std::byte const byte : bytes)
85 {
86 *output = byte;
87 ++output;
88 }
89 return output;
90 }
91
101 template < typename OutputIt >
102 auto serialize_iter(class_file const& value, OutputIt output, OutputIt end, class_file_write_options const& options = {}) -> OutputIt
103 {
104 std::vector< std::byte > const bytes = serialize_class_file(value, options);
105 for (std::byte const byte : bytes)
106 {
107 if (output == end)
108 {
109 throw std::length_error("output range is too small for the JVM class file");
110 }
111 *output = byte;
112 ++output;
113 }
114 return output;
115 }
116
126 template < std::forward_iterator InputIt, std::sentinel_for< InputIt > Sentinel >
127 auto deserialize_iter(class_file& value, InputIt input, Sentinel end, class_file_read_options const& options = {}) -> InputIt
128 {
129 std::vector< std::byte > bytes;
130 for (InputIt cursor = input; cursor != end; ++cursor)
131 {
132 bytes.push_back(static_cast< std::byte >(*cursor));
133 }
134 deserialization_result< class_file > result = deserialize_class_file_prefix(bytes, options);
135 value = std::move(result.value);
136 std::advance(input, static_cast< std::iter_difference_t< InputIt > >(result.bytes_read));
137 return input;
138 }
139} // namespace rpnx::cortado
140
141#endif // RPNX_CORTADO_CLASS_FILE_HPP
Typed JVM attributes and the complete owning class-file model.
Exception types used by parsing, validation, and assembly APIs.
JVM class-file, bytecode, validation, generation, and JAR APIs.
processing_mode
Controls whether invalid-but-preservable tool input is accepted.
Definition bytecode.hpp:26
std::vector< std::byte > serialize_class_file(class_file const &value, class_file_write_options const &options={})
Serializes a class file using the big-endian JVM class-file format.
class_file deserialize_class_file(std::span< std::byte const > bytes, class_file_read_options const &options={})
Deserializes exactly one class file and rejects trailing bytes.
auto serialize_iter(code_body const &value, OutputIt output, bytecode_write_options const &options={}) -> OutputIt
Serial4-style bytecode output-iterator interface.
Definition bytecode.hpp:371
deserialization_result< class_file > deserialize_class_file_prefix(std::span< std::byte const > bytes, class_file_read_options const &options={})
Deserializes one class file prefix and reports the number of bytes consumed.
auto deserialize_iter(code_body &value, InputIt input, Sentinel end, bytecode_read_options const &options={}) -> InputIt
Serial4-style bytecode forward-iterator interface.
Definition bytecode.hpp:417
Resource and strictness controls for class-file decoding.
std::size_t maximum_total_attribute_bytes
Aggregate attribute payload budget.
processing_mode mode
Strict validation or loss-preserving tooling behavior.
std::size_t maximum_attribute_length
Largest individual attribute payload accepted.
std::size_t maximum_nesting_depth
Maximum recursive annotation and attribute depth.
std::size_t maximum_structure_nodes
Maximum decoded aggregate nodes.
Strictness controls for class-file encoding.
processing_mode mode
Strict validation or tooling-preserving output behavior.
An owning, typed representation of one JVM class file.
A decoded value and the number of source bytes it consumed.
T value
Fully decoded owning value.
std::size_t bytes_read
Number of input bytes belonging to value.
Bounded, non-throwing validation for structured class-file models.