blob: d5ee4c1166d4996ae27e08e969225862ae294097 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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)?;
};
|