You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// * Zig `i32`, `u64`, etc. -> JSON number or string.
168
-
/// * When option `emit_nonportable_numbers_as_strings` is true, if the value is outside the range `+-1<<53` (the precise integer range of f64), it is rendered as a JSON string in base 10. Otherwise, it is rendered as JSON number.
169
-
/// * Zig floats -> JSON number or string.
170
-
/// * If the value cannot be precisely represented by an f64, it is rendered as a JSON string. Otherwise, it is rendered as JSON number.
171
-
/// * TODO: Float rendering will likely change in the future, e.g. to remove the unnecessary "e+00".
172
-
/// * Zig `[]const u8`, `[]u8`, `*[N]u8`, `@Vector(N, u8)`, and similar -> JSON string.
173
-
/// * See `StringifyOptions.emit_strings_as_arrays`.
174
-
/// * If the content is not valid UTF-8, rendered as an array of numbers instead.
175
-
/// * Zig `[]T`, `[N]T`, `*[N]T`, `@Vector(N, T)`, and similar -> JSON array of the rendering of each item.
176
-
/// * Zig tuple -> JSON array of the rendering of each item.
177
-
/// * Zig `struct` -> JSON object with each field in declaration order.
178
-
/// * If the struct 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`. See `std.json.Value` for an example.
179
-
/// * See `StringifyOptions.emit_null_optional_fields`.
180
-
/// * Zig `union(enum)` -> JSON object with one field named for the active tag and a value representing the payload.
181
-
/// * If the payload is `void`, then the emitted value is `{}`.
182
-
/// * If the union 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`.
183
-
/// * Zig `enum` -> JSON string naming the active tag.
184
-
/// * 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`.
185
-
/// * Zig untyped enum literal -> JSON string naming the active tag.
186
-
/// * Zig error -> JSON string naming the error.
187
-
/// * Zig `*T` -> the rendering of `T`. Note there is no guard against circular-reference infinite recursion.
188
-
///
167
+
/// The `safety_checks_hint` parameter determines how much memory is used to enable assertions that the above grammar is being followed,
168
+
/// e.g. tripping an assertion rather than allowing `endObject` to emit the final `}` in `[[[]]}`.
169
+
/// "Depth" in this context means the depth of nested `[]` or `{}` expressions
170
+
/// (or equivalently the amount of recursion on the `<value>` grammar expression above).
171
+
/// For example, emitting the JSON `[[[]]]` requires a depth of 3.
172
+
/// If `.checked_to_fixed_depth` is used, there is additionally an assertion that the nesting depth never exceeds the given limit.
173
+
/// `.checked_to_arbitrary_depth` requires a runtime allocator for the memory.
174
+
/// `.checked_to_fixed_depth` embeds the storage required in the `WriteStream` struct.
175
+
/// `.assumed_correct` requires no space and performs none of these assertions.
189
176
/// In `ReleaseFast` and `ReleaseSmall` mode, the given `safety_checks_hint` is ignored and is always treated as `.assumed_correct`.
if (build_mode_has_safety) assert(self.raw_streaming_mode==.none);
411
436
assert(quoted_key.len>=2andquoted_key[0] =='"'andquoted_key[quoted_key.len-1] =='"'); // quoted_key should be "quoted".
412
437
tryself.objectFieldStart();
413
438
tryself.stream.writeAll(quoted_key);
414
439
self.next_punctuation=.colon;
415
440
}
416
441
417
-
/// See `WriteStream`.
442
+
/// In the rare case that you need to write very long object field names,
443
+
/// this is an alternative to `objectField` and `objectFieldRaw` that allows you to write directly to the `.stream` field
444
+
/// similar to `beginWriteRaw`.
445
+
/// Call `endObjectFieldRaw()` when you're done.
446
+
pubfnbeginObjectFieldRaw(self: *Self) !void {
447
+
if (build_mode_has_safety) {
448
+
assert(self.raw_streaming_mode==.none);
449
+
self.raw_streaming_mode=.objectField;
450
+
}
451
+
tryself.objectFieldStart();
452
+
}
453
+
454
+
/// See `beginObjectFieldRaw`.
455
+
pubfnendObjectFieldRaw(self: *Self) void {
456
+
if (build_mode_has_safety) {
457
+
assert(self.raw_streaming_mode==.objectField);
458
+
self.raw_streaming_mode=.none;
459
+
}
460
+
self.next_punctuation=.colon;
461
+
}
462
+
463
+
/// Renders the given Zig value as JSON.
464
+
///
465
+
/// Supported types:
466
+
/// * Zig `bool` -> JSON `true` or `false`.
467
+
/// * Zig `?T` -> `null` or the rendering of `T`.
468
+
/// * Zig `i32`, `u64`, etc. -> JSON number or string.
469
+
/// * When option `emit_nonportable_numbers_as_strings` is true, if the value is outside the range `+-1<<53` (the precise integer range of f64), it is rendered as a JSON string in base 10. Otherwise, it is rendered as JSON number.
470
+
/// * Zig floats -> JSON number or string.
471
+
/// * If the value cannot be precisely represented by an f64, it is rendered as a JSON string. Otherwise, it is rendered as JSON number.
472
+
/// * TODO: Float rendering will likely change in the future, e.g. to remove the unnecessary "e+00".
473
+
/// * Zig `[]const u8`, `[]u8`, `*[N]u8`, `@Vector(N, u8)`, and similar -> JSON string.
474
+
/// * See `StringifyOptions.emit_strings_as_arrays`.
475
+
/// * If the content is not valid UTF-8, rendered as an array of numbers instead.
476
+
/// * Zig `[]T`, `[N]T`, `*[N]T`, `@Vector(N, T)`, and similar -> JSON array of the rendering of each item.
477
+
/// * Zig tuple -> JSON array of the rendering of each item.
478
+
/// * Zig `struct` -> JSON object with each field in declaration order.
479
+
/// * If the struct 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`. See `std.json.Value` for an example.
480
+
/// * See `StringifyOptions.emit_null_optional_fields`.
481
+
/// * Zig `union(enum)` -> JSON object with one field named for the active tag and a value representing the payload.
482
+
/// * If the payload is `void`, then the emitted value is `{}`.
483
+
/// * If the union 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`.
484
+
/// * Zig `enum` -> JSON string naming the active tag.
485
+
/// * 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`.
486
+
/// * Zig untyped enum literal -> JSON string naming the active tag.
487
+
/// * Zig error -> JSON string naming the error.
488
+
/// * Zig `*T` -> the rendering of `T`. Note there is no guard against circular-reference infinite recursion.
489
+
///
490
+
/// See also alternative functions `print` and `beginWriteRaw`.
491
+
/// For writing object field names, use `objectField` instead.
0 commit comments