WIP: refactor: add remote_roundtrip_test

This commit is contained in:
CJ van den Berg 2026-03-06 21:32:14 +01:00
parent 47f4202b94
commit b580d9da36
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
4 changed files with 152 additions and 0 deletions

View file

@ -0,0 +1,24 @@
/// Child process for the remoting round-trip test.
/// Reads one framed CBOR message from stdin, expects ["ping"],
/// and replies with ["pong"] on stdout.
const std = @import("std");
const cbor = @import("cbor");
const framing = @import("framing");
pub fn main() !void {
var acc: framing.Accumulator = .{};
var read_buf: [4096]u8 = undefined;
const frame = while (true) {
const n = try std.fs.File.stdin().read(&read_buf);
if (n == 0) return error.UnexpectedEof;
if (acc.feed(read_buf[0..n])) |f| break f;
};
if (!try cbor.match(frame, .{"ping"})) return error.UnexpectedMessage;
var msg_buf: [64]u8 = undefined;
var stream: std.Io.Writer = .fixed(&msg_buf);
try cbor.writeValue(&stream, .{"pong"});
try framing.write_frame(std.fs.File.stdout(), stream.buffered());
}