diff options
author | Lassi Pulkkinen <lassi@pulk.fi> | 2024-10-31 03:11:21 +0200 |
---|---|---|
committer | Lassi Pulkkinen <lassi@pulk.fi> | 2024-10-31 03:51:35 +0200 |
commit | ae44478b30d890fe0fb04022f44d474dcdcc3f9d (patch) | |
tree | 5f462459ae4b47d22114eed717d1382d08cf4dfe /mcproto/frame.ha |
Diffstat (limited to 'mcproto/frame.ha')
-rw-r--r-- | mcproto/frame.ha | 22 |
1 files changed, 22 insertions, 0 deletions
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)?; +}; |