summaryrefslogtreecommitdiff
path: root/mcproto/packet.ha
diff options
context:
space:
mode:
Diffstat (limited to 'mcproto/packet.ha')
-rw-r--r--mcproto/packet.ha13
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...);
+};