Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
schema_json.hpp
Go to the documentation of this file.
1#pragma once
2
6
7#include <cstddef>
8#include <cstdint>
9#include <memory>
10#include <optional>
11#include <string>
12#include <string_view>
13#include <utility>
14#include <vector>
15
16namespace pulp::timeline {
17
21
39
48 PersistenceError() = default;
57 explicit PersistenceError(PersistenceErrorCode error_code, std::size_t offset = 0,
58 std::uint64_t observed = 0, std::uint64_t maximum = 0,
59 std::string error_path = {},
60 std::optional<ModelError> rejected_model = {})
61 : code(error_code), byte_offset(offset), actual(observed), limit(maximum),
62 path(std::move(error_path)), model_error(rejected_model) {}
63
65 std::size_t byte_offset = 0;
66 std::uint64_t actual = 0;
67 std::uint64_t limit = 0;
68 std::string path;
69 std::optional<ModelError> model_error;
70};
71
80 std::size_t max_input_bytes = 1024ull * 1024ull * 1024ull;
82 std::size_t max_depth = 64;
84 std::size_t max_total_values = 30'000'000;
86 std::size_t max_array_elements = 10'000'000;
88 std::size_t max_object_members = 4'096;
90 std::size_t max_string_bytes = 16ull * 1024ull * 1024ull;
92 std::size_t max_opaque_bytes = 64ull * 1024ull * 1024ull;
94 std::size_t max_migration_steps = 64;
96 std::size_t max_assets = 100'000;
98 std::size_t max_audio_loop_points = 1'000'000;
100 std::size_t max_audio_loop_tags = 100'000;
102 std::size_t max_sequences = 100'000;
104 std::size_t max_tracks = 10'000;
106 std::size_t max_clips = 100'000;
108 std::size_t max_notes = 5'000'000;
110 std::size_t max_locators = 1'000'000;
112 std::size_t max_representations = 1'000'000;
114 std::size_t max_device_placements = 100'000;
116 std::size_t max_automation_lanes = 100'000;
118 std::size_t max_automation_points = 5'000'000;
120 std::size_t max_modulators = 100'000;
122 std::size_t max_macro_controls = 100'000;
124 std::size_t max_modulation_routes = 1'000'000;
126 std::size_t max_take_lanes = 100'000;
128 std::size_t max_takes = 5'000'000;
130 std::size_t max_take_comp_segments = 5'000'000;
132 std::size_t max_markers = 100'000;
134 std::size_t max_regions = 100'000;
136 std::size_t max_scenes = 100'000;
138 std::size_t max_slots = 1'000'000;
140 std::size_t max_chord_scale_events = 1'000'000;
142 std::size_t max_dynamics_events = 1'000'000;
144 std::size_t max_groove_steps = 100'000;
146 std::size_t max_midi_lanes = 100'000;
148 std::size_t max_midi_lane_points = 5'000'000;
149
151 static DecodeLimits web_defaults() noexcept;
152};
153
154struct JsonObjectMember;
155
160struct JsonValue {
162 enum class Kind : std::uint8_t {
163 Null,
165 Number,
169 };
170
174 bool boolean = false;
176 std::string scalar;
178 std::vector<JsonValue> array;
180 std::vector<JsonObjectMember> object;
182 std::size_t begin = 0;
184 std::size_t end = 0;
185
191 const JsonValue* find(std::string_view key) const noexcept;
192};
193
202 std::string first;
204};
205
210class ParsedJson {
211 public:
213 const JsonValue& root() const noexcept {
214 return root_;
215 }
216
217 std::string_view source() const noexcept {
218 return *source_;
219 }
220
230 std::string_view raw(const JsonValue& value) const noexcept;
231
232 private:
233 // Parameters are named here to match the free function's declaration.
234 // Doxygen attaches that function's `@param` block to this friend
235 // declaration, and unnamed parameters make the names unresolvable —
236 // a strict docs build then fails on `argument 'json' ... is not found`.
238 parse_json(std::string_view json, const DecodeLimits& limits);
239
240 ParsedJson() = default;
241 ParsedJson(const ParsedJson&) = delete;
242 ParsedJson& operator=(const ParsedJson&) = delete;
243 ParsedJson(ParsedJson&&) = delete;
244 ParsedJson& operator=(ParsedJson&&) = delete;
245
246 std::shared_ptr<const std::string> source_;
247 JsonValue root_;
248};
249
259parse_json(std::string_view json, const DecodeLimits& limits = {});
260
273validate_exact_envelope(const JsonValue& value, std::string_view expected_type,
274 std::uint32_t expected_version, std::string path = {},
276
289preflight_timeline_structure(std::string_view json, const DecodeLimits& limits);
290
306std::string quote_json_string(std::string_view value);
315 std::string path = {});
325 std::string path = {});
335 std::string path = {});
336
338
339} // namespace pulp::timeline
Result<T, E> — either holds a T or an E, never both.
Definition result.hpp:76
std::string_view source() const noexcept
Returns the complete owned source.
Definition schema_json.hpp:217
friend runtime::Result< std::shared_ptr< const ParsedJson >, PersistenceError > parse_json(std::string_view json, const DecodeLimits &limits)
Parses one complete UTF-8 JSON value into an owning immutable document.
const JsonValue & root() const noexcept
Returns the root node.
Definition schema_json.hpp:213
std::string_view raw(const JsonValue &value) const noexcept
Returns the original byte slice for a node from this parse.
@ OutputLimitExceeded
Definition note_transform.hpp:63
@ LimitExceeded
A configured import resource limit was exceeded.
Definition dawproject_import.hpp:50
@ ModelRejected
The assembled Project violates a model invariant.
Definition dawproject_import.hpp:49
runtime::Result< std::string, PersistenceError > canonicalize_json(const JsonValue &value)
Serializes a DOM value as deterministic JSON with sorted object keys.
runtime::Result< std::uint32_t, PersistenceError > parse_u32_number(const JsonValue &value, std::string path={})
Parses an integral JSON number representable as uint32_t.
PersistenceErrorCode
Stable category for a JSON, schema, quota, migration, or model rejection.
Definition schema_json.hpp:23
runtime::Result< const JsonValue *, PersistenceError > validate_exact_envelope(const JsonValue &value, std::string_view expected_type, std::uint32_t expected_version, std::string path={}, PersistenceErrorCode failure_code=PersistenceErrorCode::InvalidSchema)
Validates an exact extension or migration envelope.
runtime::Result< std::int64_t, PersistenceError > parse_canonical_i64_string(const JsonValue &value, std::string path={})
Parses a canonical decimal signed integer stored as a JSON string.
runtime::Result< std::uint64_t, PersistenceError > parse_canonical_u64_string(const JsonValue &value, std::string path={})
Parses a canonical decimal unsigned integer stored as a JSON string.
std::string quote_json_string(std::string_view value)
Quotes and escapes a byte sequence as a JSON string token.
runtime::Result< StructuralPreflightSuccess, PersistenceError > preflight_timeline_structure(std::string_view json, const DecodeLimits &limits)
Performs an allocation-light, schema-aware Timeline quota scan.
runtime::Result< std::shared_ptr< const ParsedJson >, PersistenceError > parse_json(std::string_view json, const DecodeLimits &limits={})
Parses one complete UTF-8 JSON value into an owning immutable document.
@ MigrationPathMissing
Registered migrations do not connect source to target.
Definition schema_json.hpp:34
@ InvalidSchema
A schema identity, envelope, or codec contract is invalid.
Definition schema_json.hpp:31
@ InvalidJson
JSON syntax or document shape is invalid.
Definition schema_json.hpp:24
@ MissingField
A required schema field is absent.
Definition schema_json.hpp:28
@ MigrationFailed
A migration returned or produced invalid output.
Definition schema_json.hpp:35
@ InvalidNumber
A numeric value is malformed or out of range.
Definition schema_json.hpp:30
@ UnsupportedStructuralType
Structural preflight encountered an unknown typed envelope.
Definition schema_json.hpp:32
@ UnexpectedType
A JSON value has the wrong kind.
Definition schema_json.hpp:29
@ UnsupportedSchemaVersion
No supported decoder version accepts the envelope.
Definition schema_json.hpp:33
@ InvalidUtf8
A required string is not valid UTF-8.
Definition schema_json.hpp:25
@ DuplicateKey
An object repeats a member name.
Definition schema_json.hpp:26
@ String
Definition schema_registry.hpp:35
@ Boolean
Definition schema_registry.hpp:31
@ Array
Definition schema_registry.hpp:37
@ Object
Definition schema_registry.hpp:36
Definition program_compiler.hpp:18
STL namespace.
Result<T, E> — success / failure union for fallible operations.
Parser, migration, opaque-payload, and Timeline structure quotas.
Definition schema_json.hpp:78
std::size_t max_take_lanes
Maximum take lanes across all tracks.
Definition schema_json.hpp:126
std::size_t max_automation_lanes
Maximum automation lanes across all tracks.
Definition schema_json.hpp:116
std::size_t max_automation_points
Maximum automation points across all lanes.
Definition schema_json.hpp:118
std::size_t max_sequences
Maximum project sequences.
Definition schema_json.hpp:102
std::size_t max_total_values
Maximum total DOM values.
Definition schema_json.hpp:84
std::size_t max_audio_loop_tags
Maximum loop tags across all assets.
Definition schema_json.hpp:100
static DecodeLimits web_defaults() noexcept
Returns tighter ceilings suitable for memory-constrained web runtimes.
std::size_t max_notes
Maximum note events across all note content.
Definition schema_json.hpp:108
std::size_t max_device_placements
Maximum device placements across all tracks.
Definition schema_json.hpp:114
std::size_t max_chord_scale_events
Maximum chord/scale events.
Definition schema_json.hpp:140
std::size_t max_string_bytes
Maximum decoded bytes in one string or key.
Definition schema_json.hpp:90
std::size_t max_macro_controls
Maximum macro controls across all tracks.
Definition schema_json.hpp:122
std::size_t max_tracks
Maximum tracks across all sequences.
Definition schema_json.hpp:104
std::size_t max_takes
Maximum takes across all take lanes.
Definition schema_json.hpp:128
std::size_t max_modulation_routes
Maximum modulation routes across all tracks.
Definition schema_json.hpp:124
std::size_t max_representations
Maximum alternate asset representations.
Definition schema_json.hpp:112
std::size_t max_audio_loop_points
Maximum loop slice points across all assets.
Definition schema_json.hpp:98
std::size_t max_slots
Maximum launch slots across all scenes.
Definition schema_json.hpp:138
std::size_t max_object_members
Maximum members in one JSON object.
Definition schema_json.hpp:88
std::size_t max_dynamics_events
Maximum dynamics events.
Definition schema_json.hpp:142
std::size_t max_clips
Maximum clips across all tracks.
Definition schema_json.hpp:106
std::size_t max_depth
Maximum JSON container nesting depth.
Definition schema_json.hpp:82
std::size_t max_modulators
Maximum modulators across all tracks.
Definition schema_json.hpp:120
std::size_t max_opaque_bytes
Maximum raw bytes retained by one opaque envelope.
Definition schema_json.hpp:92
std::size_t max_regions
Maximum sequence regions.
Definition schema_json.hpp:134
std::size_t max_groove_steps
Maximum groove-template steps.
Definition schema_json.hpp:144
std::size_t max_array_elements
Maximum elements in one JSON array.
Definition schema_json.hpp:86
std::size_t max_input_bytes
Maximum complete input size.
Definition schema_json.hpp:80
std::size_t max_migration_steps
Maximum adjacent migration callbacks per value.
Definition schema_json.hpp:94
std::size_t max_markers
Maximum sequence markers.
Definition schema_json.hpp:132
std::size_t max_locators
Maximum asset locators.
Definition schema_json.hpp:110
std::size_t max_midi_lane_points
Maximum controller points across all lanes.
Definition schema_json.hpp:148
std::size_t max_midi_lanes
Maximum controller/expression lanes across all MIDI content.
Definition schema_json.hpp:146
std::size_t max_scenes
Maximum launch scenes.
Definition schema_json.hpp:136
std::size_t max_assets
Maximum media assets in one project.
Definition schema_json.hpp:96
std::size_t max_take_comp_segments
Maximum take-comp segments across all lanes.
Definition schema_json.hpp:130
Pair-like owning member of a JSON object.
Definition schema_json.hpp:201
std::string first
Decoded object key.
Definition schema_json.hpp:202
JsonValue second
Owning object value.
Definition schema_json.hpp:203
Owning JSON DOM node with source byte bounds.
Definition schema_json.hpp:160
std::vector< JsonObjectMember > object
Decoded key/value pairs when kind is Object.
Definition schema_json.hpp:180
const JsonValue * find(std::string_view key) const noexcept
Finds an exact member on an object.
std::size_t end
Exclusive source byte offset.
Definition schema_json.hpp:184
std::string scalar
Decoded string or original number spelling.
Definition schema_json.hpp:176
std::size_t begin
Inclusive source byte offset.
Definition schema_json.hpp:182
Kind
JSON value category.
Definition schema_json.hpp:162
@ Null
JSON null.
Definition schema_json.hpp:163
std::vector< JsonValue > array
Child values when kind is Array.
Definition schema_json.hpp:178
Kind kind
Value category.
Definition schema_json.hpp:172
Structured persistence failure.
Definition schema_json.hpp:46
PersistenceError(PersistenceErrorCode error_code, std::size_t offset=0, std::uint64_t observed=0, std::uint64_t maximum=0, std::string error_path={}, std::optional< ModelError > rejected_model={})
Constructs a structured persistence error from stage-specific details.
Definition schema_json.hpp:57
std::optional< ModelError > model_error
Underlying ModelRejected detail.
Definition schema_json.hpp:69
std::uint64_t actual
Observed size or count for a quota failure.
Definition schema_json.hpp:66
std::size_t byte_offset
Source byte offset, when available.
Definition schema_json.hpp:65
std::uint64_t limit
Configured ceiling for a quota failure.
Definition schema_json.hpp:67
std::string path
JSON Pointer-like path to the rejected value.
Definition schema_json.hpp:68
PersistenceErrorCode code
Failure category.
Definition schema_json.hpp:64
PersistenceError()=default
Constructs an InvalidJson error with no source location.
Empty success value returned by structural preflight.
Definition schema_json.hpp:278