| 241 | } |
| 242 | |
| 243 | static int |
| 244 | cbor_handler (XO_ENCODER_HANDLER_ARGS) |
| 245 | { |
| 246 | int rc = 0; |
| 247 | cbor_private_t *cbor = private; |
| 248 | xo_buffer_t *xbp = cbor ? &cbor->c_data : NULL; |
| 249 | |
| 250 | if (xo_get_flags(xop) & XOF_PRETTY) { |
| 251 | printf("%*sop %s: [%s] [%s]\n", cbor ? cbor->c_indent * 2 + 4 : 0, "", |
| 252 | xo_encoder_op_name(op), name, value); |
| 253 | fflush(stdout); |
| 254 | } |
| 255 | |
| 256 | /* If we don't have private data, we're sunk */ |
| 257 | if (cbor == NULL && op != XO_OP_CREATE) |
| 258 | return -1; |
| 259 | |
| 260 | switch (op) { |
| 261 | case XO_OP_CREATE: /* Called when the handle is init'd */ |
| 262 | rc = cbor_create(xop); |
| 263 | break; |
| 264 | |
| 265 | case XO_OP_OPEN_CONTAINER: |
| 266 | cbor_append(xop, cbor, xbp, CBOR_STRING, strlen(name), name); |
| 267 | cbor_append(xop, cbor, xbp, CBOR_MAP | CBOR_INDEF, 0, NULL); |
| 268 | cbor->c_indent += 1; |
| 269 | break; |
| 270 | |
| 271 | case XO_OP_CLOSE_CONTAINER: |
| 272 | cbor_append(xop, cbor, xbp, CBOR_BREAK, 0, NULL); |
| 273 | cbor->c_indent -= 1; |
| 274 | break; |
| 275 | |
| 276 | case XO_OP_OPEN_LIST: |
| 277 | cbor_append(xop, cbor, xbp, CBOR_STRING, strlen(name), name); |
| 278 | cbor_append(xop, cbor, xbp, CBOR_ARRAY | CBOR_INDEF, 0, NULL); |
| 279 | cbor->c_indent += 1; |
| 280 | break; |
| 281 | |
| 282 | case XO_OP_CLOSE_LIST: |
| 283 | cbor_append(xop, cbor, xbp, CBOR_BREAK, 0, NULL); |
| 284 | cbor->c_indent -= 1; |
| 285 | break; |
| 286 | |
| 287 | case XO_OP_OPEN_LEAF_LIST: |
| 288 | cbor_append(xop, cbor, xbp, CBOR_STRING, strlen(name), name); |
| 289 | cbor_append(xop, cbor, xbp, CBOR_ARRAY | CBOR_INDEF, 0, NULL); |
| 290 | cbor->c_indent += 1; |
| 291 | cbor->c_open_leaf_list = 1; |
| 292 | break; |
| 293 | |
| 294 | case XO_OP_CLOSE_LEAF_LIST: |
| 295 | cbor_append(xop, cbor, xbp, CBOR_BREAK, 0, NULL); |
| 296 | cbor->c_indent -= 1; |
| 297 | cbor->c_open_leaf_list = 0; |
| 298 | break; |
| 299 | |
| 300 | case XO_OP_OPEN_INSTANCE: |
nothing calls this directly
no test coverage detected