Skip to content

first pckt post!

nate
Jan 4, 20262 min read2 reads
1

have been writing a lot of atproto things in zig!

and so, i have started working on a zig SDK for atproto so that i don't need to reimplement DID parsing or handle resolution over and over again (which is not a bad thing to have to do at first, as it helps remind me how the protocol works and also ziglang, which is relatively new to me)

here's the (wip) SDK:

zzstoatzz.io/zat

zzstoatzz.io/zat

atproto tools in zig

the thing most interesting about zig in my opinion is comptime

for example, this base58 decode table is computed at compile time and baked directly into the binary - no runtime initialization, no lazy statics, etc:

// base58 decode table - computed at compile time, embedded in binary
// no runtime initialization, no lazy statics, just data

const decode_table: [256]i8 = blk: {
    const alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
    var table: [256]i8 = .{-1} ** 256;  // -1 = invalid character
    for (alphabet, 0..) |c, i| {
        table[c] = @intCast(i);
    }
    break :blk table;
};

// at runtime, decoding is just a lookup: table['Z'] -> 32

The initialization value of container level variables is implicitly comptime.

naively, it seems like comptime is a good fit when dealing with (parts of) a protocol like atproto where there's a lot of static structure - defined once, used everywhere

we'll see how my use progresses!

Did you enjoy this article?

Recommend it — Standard Reader surfaces well-loved writing to more readers across the network.

Across the AtmosphereDiscussions