From ae44478b30d890fe0fb04022f44d474dcdcc3f9d Mon Sep 17 00:00:00 2001 From: Lassi Pulkkinen Date: Thu, 31 Oct 2024 03:11:21 +0200 Subject: Initial commit (import old repo) --- mcproto/frame.ha | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 mcproto/frame.ha (limited to 'mcproto/frame.ha') diff --git a/mcproto/frame.ha b/mcproto/frame.ha new file mode 100644 index 0000000..d5ee4c1 --- /dev/null +++ b/mcproto/frame.ha @@ -0,0 +1,22 @@ +use bufio; +use io; +use trace; + +export fn write_frame(out: io::handle, in: []u8) (void | io::error) = { + assert(len(in) <= 0x1fffff, "write_frame: too long"); + let length_buf: [3]u8 = [0...]; + let length_buf = length_buf[..0]; + encode_varint(&length_buf, len(in): i32); + io::writeall(out, length_buf)?; + io::writeall(out, in)?; +}; + +export fn write_packet(out: io::handle, packet_id: i32, payload: []u8) + (void | io::error) = { + static let packet_buf: [0x1fffff]u8 = [0...]; + + let packet = packet_buf[..0]; + encode_packet(&packet, packet_id, payload); + + write_frame(out, packet)?; +}; -- cgit v1.2.3