diff options
| author | rimio <vasi.vilvoiu@gmail.com> | 2018-03-01 21:51:15 +0200 |
|---|---|---|
| committer | rimio <vasi.vilvoiu@gmail.com> | 2018-03-01 21:51:15 +0200 |
| commit | ffd6cf087b78beffd9cce75c4b197a9474c48504 (patch) | |
| tree | 7ffab870776a58ef15e6da8e4dc78142c14f8800 | |
| parent | dd2de65b85cdc7a7744145214ecf8ea5ebe46c25 (diff) | |
Fixed printing of byte strings; fixed wrong type comparison on TAG
| -rw-r--r-- | src/ecbor.c | 4 | ||||
| -rw-r--r-- | src/ecbor_decoder.c | 10 | ||||
| -rw-r--r-- | src/ecbor_describe.c | 31 |
3 files changed, 39 insertions, 6 deletions
diff --git a/src/ecbor.c b/src/ecbor.c index dbbed96..2a9b5fb 100644 --- a/src/ecbor.c +++ b/src/ecbor.c @@ -235,14 +235,14 @@ ecbor_get_tag_item (ecbor_item_t *tag, ecbor_item_t *item) if (!tag) { return ECBOR_ERR_NULL_ITEM; } - if (tag->major_type != ECBOR_MT_ARRAY) { + if (tag->major_type != ECBOR_MT_TAG) { return ECBOR_ERR_INVALID_TYPE; } if (!item) { return ECBOR_ERR_NULL_VALUE; } - rc = ecbor_initialize_decode (&context, tag->value.items, tag->size); + rc = ecbor_initialize_decode (&context, tag->value.tag.child, tag->size); if (rc != ECBOR_OK) { return rc; } diff --git a/src/ecbor_decoder.c b/src/ecbor_decoder.c index d9cea78..66d4426 100644 --- a/src/ecbor_decoder.c +++ b/src/ecbor_decoder.c @@ -400,8 +400,14 @@ ecbor_decode_next_internal (ecbor_decode_context_t *context, ecbor_item_t child; /* not in streamed mode; compute size so we can advance */ - return ecbor_decode_next_internal (context, &child, false, - ECBOR_MT_UNDEFINED); + rc = ecbor_decode_next_internal (context, &child, false, + ECBOR_MT_UNDEFINED); + if (rc != ECBOR_OK) { + return rc; + } + + /* add child size to item size */ + item->size += child.size; } } break; diff --git a/src/ecbor_describe.c b/src/ecbor_describe.c index de1025c..bf1337b 100644 --- a/src/ecbor_describe.c +++ b/src/ecbor_describe.c @@ -128,7 +128,7 @@ print_ecbor_item (ecbor_item_t *item, unsigned int level, char *prefix) } else { printf ("'"); for (i = 0; i < len; i ++) { - printf("%2x", val[i]); + printf("%02x", val[i]); } printf ("'\n"); } @@ -154,7 +154,10 @@ print_ecbor_item (ecbor_item_t *item, unsigned int level, char *prefix) return rc; } - print_ecbor_item (&child, level+1, ""); + rc = print_ecbor_item (&child, level+1, ""); + if (rc != ECBOR_OK) { + return rc; + } } } break; @@ -194,6 +197,30 @@ print_ecbor_item (ecbor_item_t *item, unsigned int level, char *prefix) } break; + case ECBOR_MT_TAG: + { + int64_t val; + ecbor_item_t child; + + rc = ecbor_get_value (item, (void *) &val); + if (rc != ECBOR_OK) { + return rc; + } + + printf ("[TAG] value %lld\n", (long long int)val); + + rc = ecbor_get_tag_item (item, &child); + if (rc != ECBOR_OK) { + return rc; + } + + rc = print_ecbor_item (&child, level+1, ""); + if (rc != ECBOR_OK) { + return rc; + } + } + break; + default: printf ("[UNKNOWN]\n"); break; |
