diff options
Diffstat (limited to 'drawing/op.ha')
-rw-r--r-- | drawing/op.ha | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/drawing/op.ha b/drawing/op.ha index acbca29..532fd75 100644 --- a/drawing/op.ha +++ b/drawing/op.ha @@ -1,25 +1,35 @@ use io; use endian; -export type op_circle = pos; +export type op_circle = struct { + pos: pos, + radius: u8, + color: u32 +}; export type op_other = void; export type op = (op_circle| op_other); +def SER_LEN: size = 13; + // return value must be freed... for now. ehh export fn ser_op(op: op) []u8 = { const opc = op as op_circle; - let buf: []u8 = alloc([0...],8); - endian::leputu32(buf[0..4], opc.0: u32); - endian::leputu32(buf[4..8], opc.1: u32); + let buf: []u8 = alloc([0...],SER_LEN); + endian::leputu32(buf[0..4], opc.pos.0: u32); + endian::leputu32(buf[4..8], opc.pos.1: u32); + endian::leputu32(buf[8..12], opc.color: u32); + buf[12] = opc.radius; return 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; + assert(len(bytes) == SER_LEN, "wrong length somehow"); + return op_circle { + pos = (endian::legetu32(bytes[0..4]): i32, + endian::legetu32(bytes[4..8]): i32), + color = endian::legetu32(bytes[8..12]), + radius = bytes[12], + }; }; |