Skip to documentation
SLOP

tiny.closure.receipt.json

Reference tiny.closure receipt json

Defined in receipt.

API (3)

Actions

Public operations.

Types and contracts

Public types and contracts.

No direct callersNo direct callsreceiptjson
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Called byCallsNo direct callsqualifyfreezequalifyreceiptprivate sourcelib.closure.src.receipt.encodefixedReceiptLengthtest sourcelib.closure.src.receipt.jsontest: bounded JSON measures and rende...test sourcelib.closure.src.receipt.jsontest: bounded JSON rejects short outp...receipt.jsonmeasure
Static calls · unresolved targets: 0 · external targets: 1.
Called byCallsNo direct callstest sourcelib.closure.src.receipt.jsontest: bounded JSON measures and rende...test sourcelib.closure.src.receipt.jsontest: bounded JSON rejects short outp...receipt.jsonrender
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/closure/src/receipt/json.zig

zig
const std = @import("std");const pretty_json = @import("pretty").json;pub const Error = error{ReceiptCapacityExceeded};const measurement_buffer_bytes: usize = 256;pub fn measure(    comptime write: anytype,    args: anytype,) Error!usize {    var buffer: [measurement_buffer_bytes]u8 = undefined;    var discarding = std.Io.Writer.Discarding.init(&buffer);    @call(.auto, write, .{&discarding.writer} ++ args) catch        return error.ReceiptCapacityExceeded;    return std.math.cast(usize, discarding.fullCount()) orelse        error.ReceiptCapacityExceeded;}pub fn render(    output: []u8,    expected: usize,    comptime write: anytype,    args: anytype,) Error![]const u8 {    if (expected > output.len) return error.ReceiptCapacityExceeded;    var writer = std.Io.Writer.fixed(output);    @call(.auto, write, .{&writer} ++ args) catch        return error.ReceiptCapacityExceeded;    if (writer.end != expected) return error.ReceiptCapacityExceeded;    return output[0..writer.end];}fn writeFixture(writer: *std.Io.Writer, value: []const u8) std.Io.Writer.Error!void {    var json = pretty_json.Writer.init(writer, .minified);    const object = try json.object();    try object.byteString("value", value);    try object.endLine();}test "bounded JSON measures and renders arbitrary byte strings exactly" {    const expected = "{\"value\":\"quote\\\"\\n\\u0080\\u00ff\"}\n";    const length = try measure(writeFixture, .{"quote\"\n\x80\xff"});    try std.testing.expectEqual(expected.len, length);    var output: [expected.len]u8 = undefined;    const rendered = try render(        &output,        length,        writeFixture,        .{"quote\"\n\x80\xff"},    );    try std.testing.expectEqualStrings(expected, rendered);}test "bounded JSON rejects short output without mutation" {    const length = try measure(writeFixture, .{"value"});    var output: [1]u8 = .{0xa5};    try std.testing.expectError(        error.ReceiptCapacityExceeded,        render(&output, length, writeFixture, .{"value"}),    );    try std.testing.expectEqual(@as(u8, 0xa5), output[0]);}

Source: lib/closure/src/receipt/root.zig:4

zig
pub const json = @import("json.zig");

Audit

Definitions4
Public names4
Members1
Version26.7.0
Revisiondaab053ee433