diff options
author | ubq323 <ubq323@ubq323.website> | 2024-04-10 20:06:49 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2024-04-10 20:06:53 +0100 |
commit | 2677d3ae0f4f5323ca67c6436cd3a55fd4fe8021 (patch) | |
tree | 16532c2cd1b1478f0adc8dd1efc96564ee25c396 /drawing | |
parent | 40231bd839dbe5b8aa65e8f3bde31bd33b9a9190 (diff) |
send and recv drawing ops c2s
Diffstat (limited to 'drawing')
-rw-r--r-- | drawing/op.ha | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/drawing/op.ha b/drawing/op.ha index ef39161..deda81c 100644 --- a/drawing/op.ha +++ b/drawing/op.ha @@ -1,4 +1,25 @@ +use io; +use endian; + export type op_circle = pos; export type op_other = void; export type op = (op_circle| op_other); + + + +export fn send_op(file: io::handle, op: op) (void | io::error) = { + static let buf: [8]u8 = [0...]; + const opc = op as op_circle; + endian::leputu32(buf[0..4], opc.0: u32); + endian::leputu32(buf[4..8], opc.1: u32); + io::writeall(file, buf)?; +}; + +export fn deser_op(bytes: []u8) op = { + assert(len(bytes) == 8, "wrong length somehow"); + return ( + endian::legetu32(bytes[0..4]): i32, + endian::legetu32(bytes[4..8]): i32, + ) : op_circle; +}; |