RPNXCortado
C++23 JVM class-file, bytecode, validation, and JAR toolkit
Loading...
Searching...
No Matches
jar.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_JAR_HPP
9#define RPNX_CORTADO_JAR_HPP
10
11#include <cstddef>
12#include <iterator>
14#include <span>
15#include <vector>
16
17namespace rpnx::cortado
18{
25 [[nodiscard]] std::vector< std::byte > serialize_jar(jar_file const& value);
26
33 [[nodiscard]] jar_file deserialize_jar(std::span< std::byte const > bytes, jar_read_options const& options = {});
34
41 template < typename OutputIt >
42 auto serialize_iter(jar_file const& value, OutputIt output) -> OutputIt
43 {
44 std::vector< std::byte > const bytes = serialize_jar(value);
45 for (std::byte const byte : bytes)
46 {
47 *output = byte;
48 ++output;
49 }
50 return output;
51 }
52
61 template < typename OutputIt >
62 auto serialize_iter(jar_file const& value, OutputIt output, OutputIt end) -> OutputIt
63 {
64 std::vector< std::byte > const bytes = serialize_jar(value);
65 for (std::byte const byte : bytes)
66 {
67 if (output == end)
68 {
69 throw std::length_error("output range is too small for the JAR archive");
70 }
71 *output = byte;
72 ++output;
73 }
74 return output;
75 }
76
85 template < std::forward_iterator InputIt, std::sentinel_for< InputIt > Sentinel >
86 auto deserialize_iter(jar_file& value, InputIt input, Sentinel end) -> InputIt
87 {
88 std::vector< std::byte > bytes;
89 for (InputIt cursor = input; cursor != end; ++cursor)
90 {
91 bytes.push_back(static_cast< std::byte >(*cursor));
92 }
93 value = deserialize_jar(bytes);
94 while (input != end)
95 {
96 ++input;
97 }
98 return input;
99 }
100} // namespace rpnx::cortado
101
102#endif // RPNX_CORTADO_JAR_HPP
Class-file serialization, deserialization, and iterator adapters.
JVM class-file, bytecode, validation, generation, and JAR APIs.
std::vector< std::byte > serialize_jar(jar_file const &value)
Serializes an archive as a non-Zip64 JAR-compatible ZIP file.
jar_file deserialize_jar(std::span< std::byte const > bytes, jar_read_options const &options={})
Deserializes exactly one JAR archive and validates entry sizes and CRC-32 values.
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
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
An owning JAR archive representation.
Definition types.hpp:299
Explicit resource limits applied while reading an untrusted JAR archive.
Definition types.hpp:307