summaryrefslogtreecommitdiff
path: root/src/detached
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-21 17:25:52 -0300
committerGabriel Schneider <[email protected]>2026-10-22 10:03:15 -0300
commit23518c9d7c061f8a06f6632da8b64b37801b514f (patch)
tree1f9688a5c2b2c224f47dd538ffab275b1f54da5c /src/detached
parentbc3d18d27f9fc1155db7fac3946c4d38774f9e65 (diff)
downloadpardes-23518c9d7c061f8a06f6632da8b64b37801b514f.tar.gz
pardes-23518c9d7c061f8a06f6632da8b64b37801b514f.zip
zig fmt for Zig 0.17
Diffstat (limited to 'src/detached')
-rw-r--r--src/detached/client.zig2
-rw-r--r--src/detached/server.zig4
-rw-r--r--src/detached/wire.zig82
3 files changed, 44 insertions, 44 deletions
diff --git a/src/detached/client.zig b/src/detached/client.zig
index cf1842d9..60950208 100644
--- a/src/detached/client.zig
+++ b/src/detached/client.zig
@@ -1209,7 +1209,7 @@ test "detached session: a frontend is never asked to fork, write, or watch" {
}
const named = for (allowed) |ok| {
const want = std.meta.stringToEnum(wire.ServerTag, ok).?;
- if (@intFromEnum(want) == tag) break true;
+ if (@backingInt(want) == tag) break true;
} else false;
if (!named) {
std.debug.print("tag 0x{x:0>2} is decodable by a frontend and is not one of the nine\n", .{tag});
diff --git a/src/detached/server.zig b/src/detached/server.zig
index 79d1189a..41bc054f 100644
--- a/src/detached/server.zig
+++ b/src/detached/server.zig
@@ -1049,7 +1049,7 @@ pub const Session = struct {
}
fn apply(s: *Session, c: *Client, slot: u8, tag: u8, payload: []const u8) wire.Error!void {
- if (tag == @intFromEnum(wire.ClientTag.hello)) {
+ if (tag == @backingInt(wire.ClientTag.hello)) {
if (c.attached) return error.BadValue;
const claimed = try wire.helloVersion(payload);
if (claimed != wire.version) {
@@ -1124,7 +1124,7 @@ pub const Session = struct {
if (entry.scene == null) break true;
} else false;
const compiled = s.shaders.sync(s.gpa, s.io, s.core, if (files) s.inotify() else s.inotify_fd, &s.watches, .{ .ctx = &s.mailbox, .call = wakeForExit });
- const key = @as(u64, s.shaders.revision) << 8 | @intFromEnum(s.core.settings.shader_animation);
+ const key = @as(u64, s.shaders.revision) << 8 | @backingInt(s.core.settings.shader_animation);
var chain: wire.Post = .{ .animation = s.core.settings.shader_animation, .len = s.core.settings.post.len };
_ = s.shaders.view(&s.core.settings.post, &chain.passes);
for (&s.clients) |*c| {
diff --git a/src/detached/wire.zig b/src/detached/wire.zig
index f1b7a1b3..d57a28be 100644
--- a/src/detached/wire.zig
+++ b/src/detached/wire.zig
@@ -569,13 +569,13 @@ pub fn framed(buf: []const u8) Error!?Framed {
fn putColor(w: *Writer, c: pardes.Color) Error!void {
switch (c) {
- .default => try w.putByte(@intFromEnum(ColorTag.default)),
+ .default => try w.putByte(@backingInt(ColorTag.default)),
.index => |i| {
- try w.putByte(@intFromEnum(ColorTag.index));
+ try w.putByte(@backingInt(ColorTag.index));
try w.putByte(i);
},
.rgb => |v| {
- try w.putByte(@intFromEnum(ColorTag.rgb));
+ try w.putByte(@backingInt(ColorTag.rgb));
try w.putBytes(&v);
},
}
@@ -606,7 +606,7 @@ const Ul = @FieldType(pardes.CellStyle, "ul");
/// the `inline else`, exactly as `clientTag` keeps the machine-local reports.
fn putUl(w: *Writer, u: Ul) Error!void {
try w.putByte(switch (u) {
- inline else => |t| @intFromEnum(@field(UlTag, @tagName(t))),
+ inline else => |t| @backingInt(@field(UlTag, @tagName(t))),
});
}
@@ -618,7 +618,7 @@ fn getUl(r: *Reader) Error!Ul {
fn putFont(w: *Writer, f: pardes.FontRole) Error!void {
try w.putByte(switch (f) {
- inline else => |t| @intFromEnum(@field(FontTag, @tagName(t))),
+ inline else => |t| @backingInt(@field(FontTag, @tagName(t))),
});
}
@@ -795,12 +795,12 @@ pub fn encodeFrameLayers(out: []u8, cols: u16, rows: u16, cursor: ?Cursor, point
std.debug.assert(cells.len == @as(usize, cols) * @as(usize, rows));
const full = prev.len != cells.len;
var w: Writer = .init(out);
- const at = try beginMessage(&w, @intFromEnum(ServerTag.frame));
+ const at = try beginMessage(&w, @backingInt(ServerTag.frame));
const header: FrameHeader = if (pointer_shape == .link)
(if (full) .full_link else .diff_link)
else
(if (full) .full else .diff);
- try w.putByte(@intFromEnum(header));
+ try w.putByte(@backingInt(header));
try w.putU16(cols);
try w.putU16(rows);
try putCursor(&w, cursor, cols, rows);
@@ -837,7 +837,7 @@ pub fn encodeFrameLayers(out: []u8, cols: u16, rows: u16, cursor: ?Cursor, point
for (tags) |layer| {
if (layer.rows == 0) continue;
if (layer.cells.len != @as(usize, layer.cols) * layer.rows) return error.BadValue;
- try w.putByte(@intFromEnum(layer.kind));
+ try w.putByte(@backingInt(layer.kind));
try w.putU16(layer.id);
try w.putU32(layer.serial);
try w.putU16(layer.viewport.x);
@@ -852,7 +852,7 @@ pub fn encodeFrameLayers(out: []u8, cols: u16, rows: u16, cursor: ?Cursor, point
}
try w.putU16(@intCast(regions.len));
for (regions) |region| {
- try w.putByte(@intFromEnum(region.kind));
+ try w.putByte(@backingInt(region.kind));
try w.putByte(region.owner);
try w.putU32(region.serial);
try w.putU16(region.rect.x);
@@ -1003,7 +1003,7 @@ fn getBodyHit(r: *Reader) Error!?pardes.Mouse.BodyHit {
fn putTagHit(w: *Writer, hit: ?pardes.TagHit) Error!void {
try w.putBool(hit != null);
if (hit) |h| {
- try w.putByte(@intFromEnum(h.kind));
+ try w.putByte(@backingInt(h.kind));
try w.putU16(h.id);
try w.putU32(h.serial);
try w.putU16(h.col);
@@ -1030,7 +1030,7 @@ fn getTagHit(r: *Reader) Error!?pardes.TagHit {
pub fn encodeClient(out: []u8, msg: ClientMsg) Error![]const u8 {
var w: Writer = .init(out);
- const at = try beginMessage(&w, @intFromEnum(clientTag(msg)));
+ const at = try beginMessage(&w, @backingInt(clientTag(msg)));
switch (msg) {
.hello => |h| {
try w.putU16(h.version);
@@ -1048,10 +1048,10 @@ pub fn encodeClient(out: []u8, msg: ClientMsg) Error![]const u8 {
},
.mouse => |m| {
try w.putByte(switch (m.button) {
- inline else => |t| @intFromEnum(@field(ButtonTag, @tagName(t))),
+ inline else => |t| @backingInt(@field(ButtonTag, @tagName(t))),
});
try w.putByte(switch (m.kind) {
- inline else => |t| @intFromEnum(@field(KindTag, @tagName(t))),
+ inline else => |t| @backingInt(@field(KindTag, @tagName(t))),
});
try w.putU16(m.col);
try w.putU16(m.row);
@@ -1164,7 +1164,7 @@ fn serverTag(msg: ServerMsg) ServerTag {
/// payload is a walk of two grids rather than a value (see `encodeFrame`).
pub fn encodeServer(out: []u8, msg: ServerMsg) Error![]const u8 {
var w: Writer = .init(out);
- const at = try beginMessage(&w, @intFromEnum(serverTag(msg)));
+ const at = try beginMessage(&w, @backingInt(serverTag(msg)));
switch (msg) {
.welcome => |v| {
try w.putU16(v.version);
@@ -1172,7 +1172,7 @@ pub fn encodeServer(out: []u8, msg: ServerMsg) Error![]const u8 {
try w.putU16(v.cols);
try w.putU16(v.rows);
},
- .refuse => |why| try w.putByte(@intFromEnum(why)),
+ .refuse => |why| try w.putByte(@backingInt(why)),
// A frame's runs are not a value this union can hold; the server calls
// encodeFrame directly and this arm exists so the switch stays
// exhaustive over ServerMsg.
@@ -1182,11 +1182,11 @@ pub fn encodeServer(out: []u8, msg: ServerMsg) Error![]const u8 {
.read_clipboard => {},
.open_link => |u| try w.putSlice16(u),
.post => |p| {
- try w.putByte(@intFromEnum(p.animation));
+ try w.putByte(@backingInt(p.animation));
try w.putByte(p.len);
for (p.list()) |pass| {
// 0 a file, else a bundled scene and one.
- try w.putByte(if (pass.scene) |scene| @as(u8, @intFromEnum(scene)) + 1 else 0);
+ try w.putByte(if (pass.scene) |scene| @as(u8, @backingInt(scene)) + 1 else 0);
try w.putByte(pass.level);
try w.putByte(@intFromBool(pass.animated));
try w.putU32(pass.revision);
@@ -1341,9 +1341,9 @@ test "detached wire: every Event variant round-trips" {
// The tag space is the protocol's own, so assert the numbers themselves:
// a renumbering here breaks every deployed frontend and must be a diff
// somebody reads, not a silent change.
- try testing.expectEqual(@as(u8, 0x01), @intFromEnum(ClientTag.hello));
- try testing.expectEqual(@as(u8, 0x10), @intFromEnum(ClientTag.key));
- try testing.expectEqual(@as(u8, 0x1d), @intFromEnum(ClientTag.pointer_leave));
+ try testing.expectEqual(@as(u8, 0x01), @backingInt(ClientTag.hello));
+ try testing.expectEqual(@as(u8, 0x10), @backingInt(ClientTag.key));
+ try testing.expectEqual(@as(u8, 0x1d), @backingInt(ClientTag.pointer_leave));
{
const got = try roundClient(&buf, .{ .hello = .{ .cols = 80, .rows = 24 } });
@@ -1506,7 +1506,7 @@ test "detached wire: a session is never told to do a frontend's remembering" {
}
const named = for (allowed) |ok| {
const want = std.meta.stringToEnum(ClientTag, ok).?;
- if (@intFromEnum(want) == tag) break true;
+ if (@backingInt(want) == tag) break true;
} else false;
if (!named) {
std.debug.print("tag 0x{x:0>2} is decodable by a session and is not something a human did\n", .{tag});
@@ -1752,8 +1752,8 @@ test "detached wire: a truncated frame is refused at every length" {
for (0..header_len + 1) |cut|
try testing.expectEqual(@as(?Framed, null), try framed(copy[0..cut]));
// A payload with bytes LEFT OVER is refused too: it is not this message.
- try testing.expectError(error.Trailing, decodeClient(@intFromEnum(ClientTag.pointer_leave), "x"));
- try testing.expectError(error.Trailing, decodeServer(@intFromEnum(ServerTag.quit), "x"));
+ try testing.expectError(error.Trailing, decodeClient(@backingInt(ClientTag.pointer_leave), "x"));
+ try testing.expectError(error.Trailing, decodeServer(@backingInt(ServerTag.quit), "x"));
}
test "detached wire: an unknown tag is refused, never guessed" {
@@ -1765,9 +1765,9 @@ test "detached wire: an unknown tag is refused, never guessed" {
}
// A tag NESTED in a payload gets the same treatment: a color, an
// underline style, a mouse button, a refusal reason.
- try testing.expectError(error.BadTag, decodeServer(@intFromEnum(ServerTag.refuse), &.{0x7f}));
+ try testing.expectError(error.BadTag, decodeServer(@backingInt(ServerTag.refuse), &.{0x7f}));
try testing.expectError(error.BadTag, decodeClient(
- @intFromEnum(ClientTag.mouse),
+ @backingInt(ClientTag.mouse),
&.{ 0xff, 0x00, 0, 0, 0, 0, 0 },
));
}
@@ -1775,7 +1775,7 @@ test "detached wire: an unknown tag is refused, never guessed" {
test "detached wire: an over-long length prefix is refused before it is believed" {
// The prefix a hostile or corrupt peer sends to make the receiver allocate
// or index by it. `framed` must refuse rather than wait for 4 GiB.
- var head: [header_len]u8 = .{ @intFromEnum(ClientTag.paste), 0, 0, 0, 0 };
+ var head: [header_len]u8 = .{ @backingInt(ClientTag.paste), 0, 0, 0, 0 };
std.mem.writeInt(u32, head[1..5], max_payload + 1, .little);
try testing.expectError(error.Overlong, framed(&head));
std.mem.writeInt(u32, head[1..5], std.math.maxInt(u32), .little);
@@ -1789,10 +1789,10 @@ test "detached wire: an over-long length prefix is refused before it is believed
var paste: [8]u8 = undefined;
std.mem.writeInt(u32, paste[0..4], 4096, .little);
@memcpy(paste[4..8], "abcd");
- try testing.expectError(error.Truncated, decodeClient(@intFromEnum(ClientTag.paste), &paste));
+ try testing.expectError(error.Truncated, decodeClient(@backingInt(ClientTag.paste), &paste));
// ...and past the cap, which is refused rather than read.
std.mem.writeInt(u32, paste[0..4], max_payload + 1, .little);
- try testing.expectError(error.Overlong, decodeClient(@intFromEnum(ClientTag.paste), &paste));
+ try testing.expectError(error.Overlong, decodeClient(@backingInt(ClientTag.paste), &paste));
}
test "detached wire: a frame that lies about its runs cannot walk out of the grid" {
@@ -1837,13 +1837,13 @@ test "detached wire: a frame that lies about its runs cannot walk out of the gri
// it is used to bound the walk.
var head: [frame_head]u8 = undefined;
var w: Writer = .init(&head);
- try w.putByte(@intFromEnum(FrameKind.diff));
+ try w.putByte(@backingInt(FrameKind.diff));
try w.putU16(cols);
try w.putU16(rows);
try putCursor(&w, null, cols, rows);
try w.putU32(0); // no body layers
try w.putU32(9);
- try testing.expectError(error.Overlong, decodeServer(@intFromEnum(ServerTag.frame), w.written()));
+ try testing.expectError(error.Overlong, decodeServer(@backingInt(ServerTag.frame), w.written()));
// ...and a grid of the wrong size is the receiver's own bug, not a frame
// it should paint half of.
@@ -1885,7 +1885,7 @@ test "detached wire: a cursor outside the grid is refused, not painted" {
var head: [frame_head]u8 = undefined;
for ([_][2]u16{ .{ cols, 0 }, .{ 0, rows }, .{ 0xffff, 0xffff } }) |xy| {
var w: Writer = .init(&head);
- try w.putByte(@intFromEnum(FrameKind.diff));
+ try w.putByte(@backingInt(FrameKind.diff));
try w.putU16(cols);
try w.putU16(rows);
// Written by hand: `putCursor` now refuses this too, which is the
@@ -1897,19 +1897,19 @@ test "detached wire: a cursor outside the grid is refused, not painted" {
try w.putU32(0);
try testing.expectError(
error.BadValue,
- decodeServer(@intFromEnum(ServerTag.frame), w.written()),
+ decodeServer(@backingInt(ServerTag.frame), w.written()),
);
}
// The last cell IS in the grid, and a frame carrying it decodes.
{
var w: Writer = .init(&head);
- try w.putByte(@intFromEnum(FrameKind.diff));
+ try w.putByte(@backingInt(FrameKind.diff));
try w.putU16(cols);
try w.putU16(rows);
try putCursor(&w, .{ .x = cols - 1, .y = rows - 1, .bar = true }, cols, rows);
try w.putU32(0); // no body layers
try w.putU32(0);
- const got = (try decodeServer(@intFromEnum(ServerTag.frame), w.written())).frame;
+ const got = (try decodeServer(@backingInt(ServerTag.frame), w.written())).frame;
try testing.expectEqual(@as(u16, cols - 1), got.cursor.?.x);
try testing.expectEqual(@as(u16, rows - 1), got.cursor.?.y);
}
@@ -1933,25 +1933,25 @@ test "detached wire: values a field cannot mean are refused" {
// A bool is 0 or 1. `2` used to be "true" in every hand-written codec that
// ever silently accepted a corrupt stream.
try testing.expectError(error.BadValue, decodeClient(
- @intFromEnum(ClientTag.key),
+ @backingInt(ClientTag.key),
&.{ 'a', 0, 0, 0, 0, 0, 2, 0, 0 },
));
// A codepoint past Unicode's last: @intCast into Key.cp's u21 would panic.
try testing.expectError(error.BadValue, decodeClient(
- @intFromEnum(ClientTag.key),
+ @backingInt(ClientTag.key),
&.{ 0x00, 0x00, 0x11, 0x00, 0, 0, 0, 0, 0 },
));
// A pane the core cannot index. `pdf_scroll` reads its pane byte before the
// f32 that follows, so a one-byte payload reaches the check this is about
// rather than tripping `Truncated` first.
try testing.expectError(error.BadValue, decodeClient(
- @intFromEnum(ClientTag.pdf_scroll),
+ @backingInt(ClientTag.pdf_scroll),
&.{pardes.MAX_PANES},
));
// A zero-column grid would collapse a shared session; an over-wide one is
// past what this protocol carries.
try testing.expectError(error.BadValue, decodeClient(
- @intFromEnum(ClientTag.hello),
+ @backingInt(ClientTag.hello),
&.{ 1, 0, 0, 0, 24, 0 },
));
{
@@ -1959,15 +1959,15 @@ test "detached wire: values a field cannot mean are refused" {
std.mem.writeInt(u16, hello[0..2], version, .little);
std.mem.writeInt(u16, hello[2..4], max_cols + 1, .little);
std.mem.writeInt(u16, hello[4..6], 24, .little);
- try testing.expectError(error.BadValue, decodeClient(@intFromEnum(ClientTag.hello), &hello));
+ try testing.expectError(error.BadValue, decodeClient(@backingInt(ClientTag.hello), &hello));
}
// A NaN scroll distance. `pinch` multiplies into a zoom the pane keeps.
{
var pinch: [4]u8 = undefined;
std.mem.writeInt(u32, &pinch, @bitCast(std.math.nan(f32)), .little);
- try testing.expectError(error.BadValue, decodeClient(@intFromEnum(ClientTag.pinch), &pinch));
+ try testing.expectError(error.BadValue, decodeClient(@backingInt(ClientTag.pinch), &pinch));
std.mem.writeInt(u32, &pinch, @bitCast(std.math.inf(f32)), .little);
- try testing.expectError(error.BadValue, decodeClient(@intFromEnum(ClientTag.touch_scroll), &pinch));
+ try testing.expectError(error.BadValue, decodeClient(@backingInt(ClientTag.touch_scroll), &pinch));
}
// A cell with the reserved attribute bit set, and one with an impossible
// grapheme length. Both are bytes this protocol has no meaning for.