Skip to documentation
SLOP

tiny.quic.packet

Reference tiny.quic packet

Defined in tiny.quic.

API (23)

Actions

Public operations.

Types and contracts

Public types and contracts.

Values and defaults

Public values and defaults.

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

Source

Source: lib/quic/src/packet/model.zig:32

zig
pub const Common = struct {    first: u8,    version: u32,    destination: ConnectionId,    source: ConnectionId,};

Source: lib/quic/src/packet/model.zig:12

zig
/// A 20-byte array with the count of bytes in use holds the identifier a packet header carries, the/// connection ID. A caller reads one out of a decoded header, or builds one to encode, and passes/// it by value. RFC 9000 section 17.2 bounds a version 1 connection ID at 20 bytes, so the array/// holds every legal value and the value copies without touching an allocator. Building one from a/// longer slice gives `ConnectionIdTooLong`. The bytes past the length are zero, and `slice`/// returns the bytes in use.pub const ConnectionId = struct {    bytes: ConnectionIdBytes,    length: u5,    pub fn init(input: []const u8) error{ConnectionIdTooLong}!ConnectionId {        if (input.len > connection_id_bytes_max) return error.ConnectionIdTooLong;        var result = ConnectionId{            .bytes = @splat(0),            .length = @intCast(input.len),        };        @memcpy(result.bytes[0..input.len], input);        return result;    }    pub fn slice(self: *const ConnectionId) []const u8 {        std.debug.assert(self.length <= connection_id_bytes_max);        return self.bytes[0..self.length];    }};

Source: lib/quic/src/packet/model.zig:39

zig
pub const Initial = struct {    common: Common,    token: []const u8,    length: u62,    packet_number_offset: usize,};

Source: lib/quic/src/packet/model.zig:81

zig
pub const Long = union(enum) {    initial: Initial,    zero_rtt: Protected,    handshake: Protected,    retry: Retry,    version_negotiation: VersionNegotiation,    pub fn packetNumberOffset(self: Long) ?usize {        return switch (self) {            .initial => |value| value.packet_number_offset,            .zero_rtt, .handshake => |value| value.packet_number_offset,            .retry, .version_negotiation => null,        };    }};

Source: lib/quic/src/packet/model.zig:46

zig
pub const Protected = struct {    common: Common,    length: u62,    packet_number_offset: usize,};

Source: lib/quic/src/packet/model.zig:52

zig
pub const Retry = struct {    common: Common,    token: []const u8,    integrity_tag: [16]u8,};

Source: lib/quic/src/packet/model.zig:97

zig
pub const Short = struct {    first: u8,    destination: ConnectionId,    packet_number_offset: usize,};

Source: lib/quic/src/packet/model.zig:67

zig
pub const VersionIterator = struct {    bytes: []const u8,    index: usize,    pub fn next(self: *VersionIterator) ?u32 {        std.debug.assert(self.index <= self.bytes.len);        if (self.index == self.bytes.len) return null;        std.debug.assert(self.bytes.len - self.index >= 4);        const value = std.mem.readInt(u32, self.bytes[self.index..][0..4], .big);        self.index += 4;        return value;    }};

Source: lib/quic/src/packet/model.zig:58

zig
pub const VersionNegotiation = struct {    common: Common,    versions: []const u8,    pub fn iterator(self: VersionNegotiation) VersionIterator {        return .{ .bytes = self.versions, .index = 0 };    }};

Source: lib/quic/src/packet/header.zig:25

zig
pub const DecodeError = cursor.ReadError || varint.DecodeError || DecodeSpecific;

Source: lib/quic/src/packet/header.zig:26

zig
pub const EncodeError = cursor.WriteError || varint.EncodeError || EncodeSpecific;

Source: lib/quic/src/packet/header.zig:94

zig
pub fn decodeLong(bytes: []const u8) DecodeError!model.Long {    var input = cursor.Read.init(bytes);    const first = try input.byte();    if (first & 0x80 == 0) return error.InvalidHeader;    const version = try input.int(u32);    const common = try readCommon(&input, first, version);    if (version == 0) return decodeVersionNegotiation(&input, common);    if (version != 1) return error.UnsupportedVersion;    if (first & 0x40 == 0) return error.InvalidHeader;    return switch ((first >> 4) & 0x03) {        0 => decodeInitial(&input, common),        1 => .{ .zero_rtt = try decodeProtected(&input, common) },        2 => .{ .handshake = try decodeProtected(&input, common) },        3 => decodeRetry(&input, common),        else => unreachable,    };}
Called byCallsNo direct callerscursor.Readbytecursor.Readinitcursor.Readintprivate sourcelib.quic.src.packet.headerdecodeInitialprivate sourcelib.quic.src.packet.headerdecodeProtected+3 morepacketdecodeLong
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/quic/src/packet/header.zig:168

zig
pub fn decodeShort(bytes: []const u8, destination_length: u5) DecodeError!model.Short {    if (destination_length > model.connection_id_bytes_max) {        return error.ConnectionIdTooLong;    }    var input = cursor.Read.init(bytes);    const first = try input.byte();    if (first & 0x80 != 0) return error.InvalidHeader;    if (first & 0x40 == 0) return error.InvalidHeader;    const destination = model.ConnectionId.init(try input.take(destination_length)) catch        return error.ConnectionIdTooLong;    return .{        .first = first,        .destination = destination,        .packet_number_offset = input.index,    };}
Called byCallsNo direct callerscursor.Readbytecursor.Readinitcursor.Readtakepacket.ConnectionIdinitpacketdecodeShort
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/quic/src/packet/header.zig:139

zig
pub fn encodeLong(value: model.Long, output: *cursor.Write) EncodeError!void {    switch (value) {        .version_negotiation => |packet| {            if (packet.common.version != 0) return error.InvalidHeader;            if (packet.versions.len == 0) return error.InvalidVersionList;            if (packet.versions.len % 4 != 0) return error.InvalidVersionList;            try writeCommon(packet.common, output);            try output.put(packet.versions);        },        .initial => |packet| {            try validateVersionOne(packet.common, 0);            if (packet.length == 0) return error.InvalidLength;            try writeCommon(packet.common, output);            _ = try varint.write(@intCast(packet.token.len), output);            try output.put(packet.token);            _ = try varint.write(packet.length, output);        },        .zero_rtt => |packet| try writeProtected(packet, 1, output),        .handshake => |packet| try writeProtected(packet, 2, output),        .retry => |packet| {            try validateVersionOne(packet.common, 3);            if (packet.token.len == 0) return error.InvalidRetry;            try writeCommon(packet.common, output);            try output.put(packet.token);            try output.put(&packet.integrity_tag);        },    }}
Called byCallsNo direct callersprivate sourcelib.quic.src.packet.headervalidateVersionOneprivate sourcelib.quic.src.packet.headerwriteCommonprivate sourcelib.quic.src.packet.headerwriteProtectedvarintwritepacketencodeLong
Static calls · unresolved targets: 1 · external targets: 0.

Source: lib/quic/src/packet/header.zig:185

zig
pub fn encodeShort(value: model.Short, output: *cursor.Write) EncodeError!void {    if (value.first & 0x80 != 0) return error.InvalidHeader;    if (value.first & 0x40 == 0) return error.InvalidHeader;    try output.byte(value.first);    try output.put(value.destination.slice());}

Source: lib/quic/src/packet/header.zig:192

zig
pub fn packetNumberLength(first: u8) u3 {    return @as(u3, @intCast(first & 0x03)) + 1;}
Called byCallsNo direct callspacketdecodeShortprivate sourcelib.quic.src.packet.headerreadConnectionIdpacket.ConnectionIdinit
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/quic/src/packet/model.zig:3

zig
pub const connection_id_bytes_max: u5 = 20;

Source: lib/quic/src/packet/root.zig

zig
const header = @import("header.zig");const model = @import("model.zig");const number = @import("number.zig");pub const connection_id_bytes_max = model.connection_id_bytes_max;pub const ConnectionId = model.ConnectionId;pub const Common = model.Common;pub const Initial = model.Initial;pub const Protected = model.Protected;pub const Retry = model.Retry;pub const VersionNegotiation = model.VersionNegotiation;pub const VersionIterator = model.VersionIterator;pub const Long = model.Long;pub const Short = model.Short;pub const Number = struct {    pub const Truncated: type = number.Truncated;    pub const truncate = number.truncate;    pub const expand = number.expand;};pub const DecodeError = header.DecodeError;pub const EncodeError = header.EncodeError;pub const decodeLong = header.decodeLong;pub const encodeLong = header.encodeLong;pub const decodeShort = header.decodeShort;pub const encodeShort = header.encodeShort;pub const packetNumberLength = header.packetNumberLength;

Source: lib/quic/src/root.zig:48

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

Complete call list for packet.decodeLong

8 direct calls.

Audit

Definitions23
Public names23
Members28
Version26.7.0
Revisiondaab053ee433