Fix connect parsing

This commit is contained in:
2026-01-02 20:04:55 +00:00
parent 5f24108014
commit 9e9f7e8e50

View File

@@ -270,7 +270,7 @@ pub const Message = union(MessageType) {
// for storing the json string // for storing the json string
var connect_string_writer_allocating: std.Io.Writer.Allocating = .init(alloc); var connect_string_writer_allocating: std.Io.Writer.Allocating = .init(alloc);
defer connect_string_writer_allocating.deinit(); defer connect_string_writer_allocating.deinit();
var connect_string_writer = connect_string_writer_allocating.writer; var connect_string_writer = &connect_string_writer_allocating.writer;
// for parsing the json string // for parsing the json string
var connect_arena_allocator: std.heap.ArenaAllocator = .init(alloc); var connect_arena_allocator: std.heap.ArenaAllocator = .init(alloc);
@@ -280,15 +280,17 @@ pub const Message = union(MessageType) {
try in.discardAll(1); // throw away space try in.discardAll(1); // throw away space
// Should read the next JSON object to the fixed buffer writer. // Should read the next JSON object to the fixed buffer writer.
_ = try in.streamDelimiter(&connect_string_writer, '}'); _ = try in.streamDelimiter(connect_string_writer, '}');
try connect_string_writer.writeByte('}'); try connect_string_writer.writeByte('}');
try expectStreamBytes(in, "}\r\n"); // discard '}\r\n' try expectStreamBytes(in, "}\r\n"); // discard '}\r\n'
const connect_str = try connect_string_writer_allocating.toOwnedSlice();
defer alloc.free(connect_str);
// TODO: should be CONNECTION allocator // TODO: should be CONNECTION allocator
const res = try std.json.parseFromSliceLeaky( const res = try std.json.parseFromSliceLeaky(
Connect, Connect,
connect_allocator, connect_allocator,
connect_string_writer.buffered(), connect_str,
.{ .allocate = .alloc_always }, .{ .allocate = .alloc_always },
); );