Skip to documentation
SLOP

tiny.reticulum.wire.flags

Reference tiny.reticulum wire flags

Defined in wire.

API (7)

Actions

Public operations.

Types and contracts

Public types and contracts.

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

Source

Called byCallsNo direct callstest sourcelib.reticulum.src.wire.flags.test_Reticulum@1...py:251-255 preserves every flag bitprivate sourcelib.reticulum.src.wire.hashsuffixOffsetwire.headerdecodetest sourcelib.reticulum.src.wire.header.test_Reticulum@...py:172,184-186 frames link request pr...wire.linklinkIdwire.Flagsdecode
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/reticulum/src/wire/flags.zig

zig
const std = @import("std");pub const HeaderType = enum(u1) {    one = 0,    two = 1,};pub const TransportType = enum(u1) {    broadcast = 0,    transport = 1,};pub const DestinationType = enum(u2) {    single = 0,    group = 1,    plain = 2,    link = 3,};pub const PacketType = enum(u2) {    data = 0,    announce = 1,    link_request = 2,    proof = 3,};pub const Flags = struct {    ifac: u1,    header: HeaderType,    context: u1,    transport: TransportType,    destination: DestinationType,    packet: PacketType,    /// Packs the six flag fields into the byte that leads a packet header: the    /// access-code flag at bit 7, the header shape at bit 6, the context flag    /// at bit 5, whether the packet is carried for another node at bit 4, the    /// destination type at bits 3 and 2, and the packet type at bits 1 and 0,    /// for a caller building that header, following Reticulum@1.5.0    /// RNS/Packet.py:172-174.    pub fn encode(self: Flags) u8 {        return (@as(u8, self.ifac) << 7) |            (@as(u8, @backingInt(self.header)) << 6) |            (@as(u8, self.context) << 5) |            (@as(u8, @backingInt(self.transport)) << 4) |            (@as(u8, @backingInt(self.destination)) << 2) |            @as(u8, @backingInt(self.packet));    }    /// Reads the six flag fields back out of the first byte of an arriving    /// packet, at the bit positions the packing uses, following Reticulum@1.5.0    /// RNS/Packet.py:251-255. Every bit pattern names a value in its field, so    /// any byte decodes and encodes back to itself.    pub fn decode(byte: u8) Flags {        return .{            .ifac = @truncate(byte >> 7),            .header = @fromBackingInt(@intCast(@as(u1, @truncate(byte >> 6)))),            .context = @truncate(byte >> 5),            .transport = @fromBackingInt(@intCast(@as(u1, @truncate(byte >> 4)))),            .destination = @fromBackingInt(@intCast(@as(u2, @truncate(byte >> 2)))),            .packet = @fromBackingInt(@intCast(@as(u2, @truncate(byte)))),        };    }};test "Reticulum@1.5.0 RNS/Packet.py:172-174 packs each header type" {    const base = Flags{        .ifac = 0,        .header = .one,        .context = 0,        .transport = .broadcast,        .destination = .single,        .packet = .data,    };    try std.testing.expectEqual(@as(u8, 0x00), base.encode());    var header_two = base;    header_two.header = .two;    try std.testing.expectEqual(@as(u8, 0x40), header_two.encode());}test "Reticulum@1.5.0 RNS/Packet.py:172-174 packs each destination type" {    var value = Flags{        .ifac = 0,        .header = .one,        .context = 0,        .transport = .broadcast,        .destination = .single,        .packet = .data,    };    for ([_]u8{ 0x00, 0x04, 0x08, 0x0c }, 0..) |expected, raw| {        value.destination = @fromBackingInt(@intCast(@as(u2, @intCast(raw))));        try std.testing.expectEqual(expected, value.encode());    }}test "Reticulum@1.5.0 RNS/Packet.py:60-63,172 packs each packet type" {    var value = Flags{        .ifac = 0,        .header = .one,        .context = 0,        .transport = .broadcast,        .destination = .single,        .packet = .data,    };    for ([_]u8{ 0x00, 0x01, 0x02, 0x03 }, 0..) |expected, raw| {        value.packet = @fromBackingInt(@intCast(@as(u2, @intCast(raw))));        try std.testing.expectEqual(expected, value.encode());    }}test "Reticulum@1.5.0 RNS/Packet.py:251-255 preserves every flag bit" {    const decoded = Flags.decode(0xff);    try std.testing.expectEqual(@as(u1, 1), decoded.ifac);    try std.testing.expectEqual(HeaderType.two, decoded.header);    try std.testing.expectEqual(@as(u1, 1), decoded.context);    try std.testing.expectEqual(TransportType.transport, decoded.transport);    try std.testing.expectEqual(DestinationType.link, decoded.destination);    try std.testing.expectEqual(PacketType.proof, decoded.packet);    try std.testing.expectEqual(@as(u8, 0xff), decoded.encode());}

Source: lib/reticulum/src/wire/root.zig:49

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

Audit

Definitions8
Public names19
Members18
Version26.7.0
Revisiondaab053ee433