MCPcopy Create free account
hub / github.com/apache/qpid-proton / pni_encoder_exit

Function pni_encoder_exit

c/src/core/encoder.c:346–393  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

344#include <stdio.h>
345
346static int pni_encoder_exit(void *ctx, pn_data_t *data, pni_node_t *node)
347{
348 pn_encoder_t *encoder = (pn_encoder_t *) ctx;
349 size_t pos;
350
351 // Special case 0 length list, but not as element in an array
352 pni_node_t *parent = pn_data_node(data, node->parent);
353 if (node->atom.type==PN_LIST && node->children-encoder->null_count==0 && !pn_is_in_array(data, parent, node)) {
354 encoder->position = node->start-1; // position of list opcode
355 pn_encoder_writef8(encoder, PNE_LIST0);
356 encoder->null_count = 0;
357 return 0;
358 }
359
360 switch (node->atom.type) {
361 case PN_ARRAY:
362 if ((node->described && node->children == 1) || (!node->described && node->children == 0)) {
363 pn_encoder_writef8(encoder, pn_type2code(encoder, node->type));
364 }
365 PN_FALLTHROUGH;
366 case PN_LIST:
367 case PN_MAP:
368 pos = encoder->position;
369 encoder->position = node->start;
370 if (node->small) {
371 // backfill size
372 size_t size = pos - node->start - 1;
373 pn_encoder_writef8(encoder, size);
374 // Adjust count
375 if (encoder->null_count) {
376 pn_encoder_writef8(encoder, node->children-encoder->null_count);
377 }
378 } else {
379 // backfill size
380 size_t size = pos - node->start - 4;
381 pn_encoder_writef32(encoder, size);
382 // Adjust count
383 if (encoder->null_count) {
384 pn_encoder_writef32(encoder, node->children-encoder->null_count);
385 }
386 }
387 encoder->position = pos;
388 encoder->null_count = 0;
389 return 0;
390 default:
391 return 0;
392 }
393}
394
395ssize_t pn_encoder_encode(pn_encoder_t *encoder, pn_data_t *src, char *dst, size_t size)
396{

Callers

nothing calls this directly

Calls 5

pn_data_nodeFunction · 0.85
pn_is_in_arrayFunction · 0.85
pn_encoder_writef8Function · 0.85
pn_type2codeFunction · 0.85
pn_encoder_writef32Function · 0.85

Tested by

no test coverage detected