diff options
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)?; +}; |