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/packet.ha |
Diffstat (limited to 'mcproto/packet.ha')
-rw-r--r-- | mcproto/packet.ha | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/mcproto/packet.ha b/mcproto/packet.ha new file mode 100644 index 0000000..669df56 --- /dev/null +++ b/mcproto/packet.ha @@ -0,0 +1,13 @@ +use math; +use trace; + +export fn encode_packet(out: *[]u8, packet_id: i32, in: []u8) void = { + let id_size = math::bit_size_u32(packet_id: u32); + if (id_size == 0) id_size = 1; + const id_size = id_size / 7 + id_size % 7; + assert(len(in) + id_size <= 0x1fffff, + "TODO: sent packet too long. this should be handled better."); + + encode_varint(out, packet_id); + append(out, in...); +}; |