Lines Matching refs:ws
38 #define ensure_writable(sz) if ((ws->offset<0) || (ws->offset + (sz) >= ws->size)) { \
39 ws->offset = -1; \
44 ws->buf[ws->offset++] = (b); \
45 memcpy(ws->buf+ws->offset, (data), (sz)); \
46 ws->offset += sz;
49 ws->buf[ws->offset++] = (b); \
79 static void _write_positive(cn_write_state *ws, cn_cbor_type typ, uint64_t val) { in _write_positive() argument
86 ws->offset = -1; in _write_positive()
116 static void _write_double(cn_write_state *ws, double val) in _write_double() argument
221 if (ws->offset < 0) { return; }
225 cn_write_state *ws = context; in _encoder_visitor() local
233 CHECK(_write_positive(ws, CN_CBOR_ARRAY, cb->length)); in _encoder_visitor()
240 CHECK(_write_positive(ws, CN_CBOR_MAP, cb->length/2)); in _encoder_visitor()
250 CHECK(_write_positive(ws, cb->type, cb->length)); in _encoder_visitor()
252 memcpy(ws->buf+ws->offset, cb->v.str, cb->length); in _encoder_visitor()
253 ws->offset += cb->length; in _encoder_visitor()
266 CHECK(_write_positive(ws, cb->type, cb->v.uint)); in _encoder_visitor()
271 CHECK(_write_positive(ws, CN_CBOR_INT, ~(cb->v.sint))); in _encoder_visitor()
276 CHECK(_write_double(ws, cb->v.dbl)); in _encoder_visitor()
281 ws->offset = -1; in _encoder_visitor()
288 cn_write_state *ws = context; in _encoder_breaker() local
299 cn_write_state ws = { buf, buf_offset, buf_size }; in cn_cbor_encoder_write() local
300 _visit(cb, _encoder_visitor, _encoder_breaker, &ws); in cn_cbor_encoder_write()
301 if (ws.offset < 0) { return -1; } in cn_cbor_encoder_write()
302 return ws.offset - buf_offset; in cn_cbor_encoder_write()