Skip to documentation
SLOP

tiny.choir.serialization.binary

Reference tiny.choir serialization binary

Defined in serialization.

API (8)

Actions

Public operations.

Types and contracts

Public types and contracts.

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

Source

Source: lib/choir/src/serialization/binary/model.zig:11

zig
pub const Error = error{    Truncated,    InvalidValue,    InvalidTag,    LimitExceeded,};

Source: lib/choir/src/serialization/binary/model.zig:3

zig
pub const Limits = struct {    serialized_bytes: usize,    string_bytes: usize,    blob_bytes: usize,    collection_entries: usize,    total_entries: usize,};

Source: lib/choir/src/serialization/binary/reader.zig:4

zig
pub fn Reader(comptime limits: binary.Limits) type {    return struct {        bytes: []const u8,        offset: usize = 0,        total_entries: usize = 0,        const Self = @This();        pub fn init(bytes: []const u8) binary.Error!Self {            if (bytes.len > limits.serialized_bytes) return error.LimitExceeded;            return .{ .bytes = bytes };        }        pub fn atEnd(self: Self) bool {            return self.offset == self.bytes.len;        }        pub fn readRaw(self: *Self, length: usize) binary.Error![]const u8 {            if (length > self.bytes.len - self.offset) return error.Truncated;            const value = self.bytes[self.offset..][0..length];            self.offset += length;            return value;        }        pub fn readInt(self: *Self, comptime T: type) binary.Error!T {            const value = try self.readRaw(@sizeOf(T));            return std.mem.readInt(T, value[0..@sizeOf(T)], .little);        }        pub fn readBool(self: *Self) binary.Error!bool {            return switch (try self.readInt(u8)) {                0 => false,                1 => true,                else => error.InvalidValue,            };        }        pub fn readTag(self: *Self, comptime T: type) binary.Error!T {            return try binary.decodeTag(T, try self.readInt(u8));        }        pub fn readCount(self: *Self) binary.Error!usize {            const count: usize = @intCast(try self.readInt(u32));            if (count > limits.collection_entries) return error.LimitExceeded;            if (count > self.bytes.len - self.offset) return error.Truncated;            self.total_entries = std.math.add(usize, self.total_entries, count) catch return error.LimitExceeded;            if (self.total_entries > limits.total_entries) return error.LimitExceeded;            return count;        }        pub fn readString(self: *Self) binary.Error![]const u8 {            return try self.readLengthPrefixed(limits.string_bytes);        }        pub fn readBlob(self: *Self) binary.Error![]const u8 {            return try self.readLengthPrefixed(limits.blob_bytes);        }        pub fn readOptionalString(self: *Self) binary.Error!?[]const u8 {            if (!try self.readBool()) return null;            return try self.readString();        }        pub fn readOptionalU16(self: *Self) binary.Error!?u16 {            if (!try self.readBool()) return null;            return try self.readInt(u16);        }        fn readLengthPrefixed(self: *Self, maximum: usize) binary.Error![]const u8 {            const length: usize = @intCast(try self.readInt(u32));            if (length > maximum) return error.LimitExceeded;            return try self.readRaw(length);        }    };}
Called byCallsNo direct callstest sourcelib.choir.src.serialization.binary.readertest: binary reader rejects malformed...serialization.binaryReader
Static calls · unresolved targets: 0 · external targets: 6.

Source: lib/choir/src/serialization/binary/tag.zig:7

zig
pub fn decodeTag(comptime T: type, value: u8) error{InvalidTag}!T {    return std.enums.fromInt(T, value) orelse error.InvalidTag;}

Source: lib/choir/src/serialization/binary/tag.zig:3

zig
pub fn encodeTag(value: anytype) error{LimitExceeded}!u8 {    return std.math.cast(u8, @backingInt(value)) orelse error.LimitExceeded;}

Source: lib/choir/src/serialization/binary/writer.zig:11

zig
/// Has no allocator capability. Its finished bytes borrow the caller's buffer.pub fn FixedWriter(comptime limits: binary.Limits) type {    return BufferWriter(limits, .borrowed);}
Called byCallstest sourcelib.choir.src.serialization.binary.writertest: fixed binary writer borrows out...private sourcelib.choir.src.serialization.binary.writerBufferWriterserialization.binaryFixedWriter
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/choir/src/serialization/binary/writer.zig:6

zig
pub fn Writer(comptime limits: binary.Limits) type {    return BufferWriter(limits, .allocated);}
Called byCallsNo direct callersprivate sourcelib.choir.src.serialization.binary.writerBufferWriterserialization.binaryWriter
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/choir/src/serialization/binary/root.zig

zig
const model = @import("model.zig");const tag = @import("tag.zig");pub const Limits = model.Limits;pub const Error = model.Error;pub const WriteError = model.WriteError;pub const Reader = @import("reader.zig").Reader;pub const Writer = @import("writer.zig").Writer;pub const FixedWriter = @import("writer.zig").FixedWriter;pub const encodeTag = tag.encodeTag;pub const decodeTag = tag.decodeTag;

Source: lib/choir/src/serialization/root.zig:1

zig
pub const binary = @import("binary/root.zig");

Audit

Definitions8
Public names8
Members9
Version26.7.0
Revisiondaab053ee433