refactor: improve type safety of Buffer.Ref values in messages

This commit is contained in:
CJ van den Berg 2026-01-22 15:12:57 +01:00
parent 0abfabc365
commit 6d86807e21
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 6 additions and 4 deletions

View file

@ -1760,12 +1760,12 @@ pub const Ref = enum(usize) {
pub fn cborEncode(self: @This(), writer: *std.Io.Writer) std.io.Writer.Error!void {
const value: usize = @intFromEnum(self);
try cbor.writeValue(writer, value);
try cbor.writeValue(writer, .{ "BREF", value });
}
pub fn cborExtract(self: *@This(), iter: *[]const u8) cbor.Error!bool {
var value: usize = 0;
if (try cbor.matchValue(iter, cbor.extract(&value))) {
if (try cbor.matchValue(iter, .{ "BREF", cbor.extract(&value) })) {
self.* = @enumFromInt(value);
return true;
}

View file

@ -1361,10 +1361,12 @@ const cmds = struct {
return error.InvalidShellArgument;
const cmd = ctx.args;
const handlers = struct {
fn out(buffer_ref: usize, parent: tp.pid_ref, _: []const u8, output: []const u8) void {
fn out(context: usize, parent: tp.pid_ref, _: []const u8, output: []const u8) void {
const buffer_ref: Buffer.Ref = @enumFromInt(context);
parent.send(.{ "cmd", "shell_execute_stream_output", .{ buffer_ref, output } }) catch {};
}
fn exit(buffer_ref: usize, parent: tp.pid_ref, arg0: []const u8, err_msg: []const u8, exit_code: i64) void {
fn exit(context: usize, parent: tp.pid_ref, arg0: []const u8, err_msg: []const u8, exit_code: i64) void {
const buffer_ref: Buffer.Ref = @enumFromInt(context);
var buf: [256]u8 = undefined;
var stream = std.io.fixedBufferStream(&buf);
const writer = stream.writer();