blob: 669df56d95efd896fdf0bf5c60713cddd7e8768e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
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...);
};
|