tiny.preserves.packed_constants
Defined in tiny.preserves.
The tag bytes of the binary syntax, one per kind of value, plus the end marker.
API (1)
Types and contracts
Public types and contracts.
Tag: The tag byte that starts each encoded value, as an enum overu8, so code that writes encoded bytes by hand names each tag through it.
Source
Source: lib/preserves/src/packed/constants.zig
zig
//! The tag bytes of the binary syntax, one per kind of value, plus the end marker. Code that writes//! or checks encoded bytes by hand has to use the same bytes as the packed writer and reader.const std = @import("std");/// The tag byte that starts each encoded value, as an enum over `u8`, so code that writes encoded/// bytes by hand names each tag through it. The packed reader rejects a byte outside these fourteen/// values as `UnknownTag`.pub const Tag = enum(u8) { false_ = 0x80, true_ = 0x81, /// The byte 0x84, which closes a record, sequence, set or dictionary. At the start of a value, /// the packed reader rejects it as `UnexpectedEndMarker`. end = 0x84, /// The byte 0x85, which starts an annotation in the binary syntax. The packed writer never /// writes it, and the packed reader rejects it as `AnnotationNotSupported`. annotation = 0x85, /// The byte 0x86, which starts an embedded value. The packed writer writes it before an /// embedded value's bytes, which come from its type's `encodePacked`. The packed reader rejects /// it as `EmbeddedNotSupported`, so bytes holding an embedded value never decode. embedded = 0x86, /// The byte 0x87, which starts a double: a length of 8, then the double's eight bytes, /// big-endian. ieee754 = 0x87, signed_integer = 0xb0, string = 0xb1, byte_string = 0xb2, symbol = 0xb3, record = 0xb4, sequence = 0xb5, set = 0xb6, dictionary = 0xb7, /// Returns the byte value of the tag, for code that writes a tag into a byte buffer. pub fn byte(self: Tag) u8 { return @backingInt(self); } /// Returns the tag whose byte is `b`, or null otherwise, so the packed reader calls it on each /// tag byte for the kind of value that follows. `fromByte(t.byte())` returns `t` for every tag. pub fn fromByte(b: u8) ?Tag { return switch (b) { 0x80 => .false_, 0x81 => .true_, 0x84 => .end, 0x85 => .annotation, 0x86 => .embedded, 0x87 => .ieee754, 0xb0 => .signed_integer, 0xb1 => .string, 0xb2 => .byte_string, 0xb3 => .symbol, 0xb4 => .record, 0xb5 => .sequence, 0xb6 => .set, 0xb7 => .dictionary, else => null, }; }};test "Tag round-trips through byte" { const all = [_]Tag{ .false_, .true_, .end, .annotation, .embedded, .ieee754, .signed_integer, .string, .byte_string, .symbol, .record, .sequence, .set, .dictionary, }; for (all) |t| { try std.testing.expectEqual(t, Tag.fromByte(t.byte()).?); } try std.testing.expectEqual(@as(?Tag, null), Tag.fromByte(0x00)); try std.testing.expectEqual(@as(?Tag, null), Tag.fromByte(0x82)); try std.testing.expectEqual(@as(?Tag, null), Tag.fromByte(0xb8));}Source: lib/preserves/src/root.zig:122
zig
pub const packed_constants = @"packed".constants;Also reachable as
Audit
| Definitions | 1 |
|---|---|
| Public names | 2 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |