WIP: refactor: add remote_roundtrip_test
This commit is contained in:
parent
47f4202b94
commit
b580d9da36
4 changed files with 152 additions and 0 deletions
24
test/remote_child_roundtrip.zig
Normal file
24
test/remote_child_roundtrip.zig
Normal 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());
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue