refactor: improve type safety of Buffer.Ref values in messages
This commit is contained in:
parent
0abfabc365
commit
6d86807e21
2 changed files with 6 additions and 4 deletions
|
|
@ -1760,12 +1760,12 @@ pub const Ref = enum(usize) {
|
||||||
|
|
||||||
pub fn cborEncode(self: @This(), writer: *std.Io.Writer) std.io.Writer.Error!void {
|
pub fn cborEncode(self: @This(), writer: *std.Io.Writer) std.io.Writer.Error!void {
|
||||||
const value: usize = @intFromEnum(self);
|
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 {
|
pub fn cborExtract(self: *@This(), iter: *[]const u8) cbor.Error!bool {
|
||||||
var value: usize = 0;
|
var value: usize = 0;
|
||||||
if (try cbor.matchValue(iter, cbor.extract(&value))) {
|
if (try cbor.matchValue(iter, .{ "BREF", cbor.extract(&value) })) {
|
||||||
self.* = @enumFromInt(value);
|
self.* = @enumFromInt(value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1361,10 +1361,12 @@ const cmds = struct {
|
||||||
return error.InvalidShellArgument;
|
return error.InvalidShellArgument;
|
||||||
const cmd = ctx.args;
|
const cmd = ctx.args;
|
||||||
const handlers = struct {
|
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 {};
|
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 buf: [256]u8 = undefined;
|
||||||
var stream = std.io.fixedBufferStream(&buf);
|
var stream = std.io.fixedBufferStream(&buf);
|
||||||
const writer = stream.writer();
|
const writer = stream.writer();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue