| ... | ... | @@ -109,6 +109,7 @@ pub fn writeStream( |
| 109 | 109 | /// `max_depth` is rounded up to the nearest multiple of 8. |
| 110 | 110 | /// If the nesting depth exceeds `max_depth`, it is detectable illegal behavior. |
| 111 | 111 | /// Give `null` for `max_depth` to disable safety checks for the grammar and allow arbitrary nesting depth. |
| 112 | /// In `ReleaseFast` and `ReleaseSmall`, `max_depth` is ignored, effectively equivalent to passing `null`. |
| 112 | 113 | /// Alternatively, see `writeStreamArbitraryDepth` to do safety checks to arbitrary depth. |
| 113 | 114 | /// |
| 114 | 115 | /// The caller does *not* need to call `deinit()` on the returned object. |
| ... | ... | @@ -130,6 +131,9 @@ pub fn writeStreamMaxDepth( |
| 130 | 131 | /// This version of the write stream enables safety checks to arbitrarily deep nesting levels |
| 131 | 132 | /// by using the given allocator. |
| 132 | 133 | /// The caller should call `deinit()` on the returned object to free allocated memory. |
| 134 | /// |
| 135 | /// In `ReleaseFast` and `ReleaseSmall` mode, this function is effectively equivalent to calling `writeStreamMaxDepth(..., null)`; |
| 136 | /// in those build modes, the allocator is *not used*. |
| 133 | 137 | pub fn writeStreamArbitraryDepth( |
| 134 | 138 | allocator: Allocator, |
| 135 | 139 | out_stream: anytype, |
| ... | ... | @@ -176,9 +180,11 @@ pub fn writeStreamArbitraryDepth( |
| 176 | 180 | /// * If the enum declares a method `pub fn jsonStringify(self: *@This(), jw: anytype) !void`, it is called to do the serialization instead of the default behavior. The given `jw` is a pointer to this `WriteStream`. |
| 177 | 181 | /// * Zig error -> JSON string naming the error. |
| 178 | 182 | /// * Zig `*T` -> the rendering of `T`. Note there is no guard against circular-reference infinite recursion. |
| 183 | /// |
| 184 | /// In `ReleaseFast` and `ReleaseSmall` mode, the given `safety_checks_hint` is ignored and is always treated as `.assumed_correct`. |
| 179 | 185 | pub fn WriteStream( |
| 180 | 186 | comptime OutStream: type, |
| 181 | | comptime safety_checks: union(enum) { |
| 187 | comptime safety_checks_hint: union(enum) { |
| 182 | 188 | checked_to_arbitrary_depth, |
| 183 | 189 | checked_to_fixed_depth: usize, // Rounded up to the nearest multiple of 8. |
| 184 | 190 | assumed_correct, |
| ... | ... | @@ -186,6 +192,10 @@ pub fn WriteStream( |
| 186 | 192 | ) type { |
| 187 | 193 | return struct { |
| 188 | 194 | const Self = @This(); |
| 195 | const safety_checks: @TypeOf(safety_checks_hint) = switch (@import("builtin").mode) { |
| 196 | .Debug, .ReleaseSafe => safety_checks_hint, |
| 197 | .ReleaseFast, .ReleaseSmall => .assumed_correct, |
| 198 | }; |
| 189 | 199 | |
| 190 | 200 | pub const Stream = OutStream; |
| 191 | 201 | pub const Error = switch (safety_checks) { |