implement new wire API
Simplify working with raw wire format (and make it safer):
Instead of:
if (avail < size) {
return KNOT_EMALF;
}
uint8_t *pos = wire;
uint16_t type = knot_wire_read_u16(*pos);
*pos += sizeof(uint16_t);
uint16_t rclass = knot_wire_read_u16(*pos);
*pos += sizeof(uint16_t);
*ttl = knot_wire_read_u32(*pos);
*pos += sizeof(uint32_t);
*rdlen = knot_wire_read_u16(*pos);
*pos += sizeof(uint16_t);
assert(pos == wire + size);
Use something like this:
wire_ctx_t ctx = wire_ctx_init(wire, avail);
uint16_t type = wire_ctx_read_u16(&ctx);
uint16_t rclass = wire_ctx_read_u16(&ctx);
uint32_t ttl = wire_ctx_read_u32(&ctx);
uint16_t rdlen = wire_ctx_read_u16(&ctx);
if (ctx->error) {
return KNOT_EMALF;
}