diff options
| author | rimio <vasi.vilvoiu@gmail.com> | 2018-03-02 00:20:16 +0200 |
|---|---|---|
| committer | rimio <vasi.vilvoiu@gmail.com> | 2018-03-02 00:20:16 +0200 |
| commit | e1c8564af2b02122e442503dd2c0fb77d2b935e4 (patch) | |
| tree | 0efeaf0062c7fbea8a5a34b39a8d968d1e6c5291 | |
| parent | 760860f3a34873e00cbf2ccb473f78cf3933a2f2 (diff) | |
Added UNDEFINED type; old error case renamed to NONE; added test case answers
| -rw-r--r-- | include/ecbor.h | 8 | ||||
| -rw-r--r-- | src/ecbor.c | 4 | ||||
| -rw-r--r-- | src/ecbor_decoder.c | 13 | ||||
| -rw-r--r-- | src/ecbor_describe.c | 4 | ||||
| -rw-r--r-- | test/files/appendix_a/0043.answer | 1 |
5 files changed, 19 insertions, 11 deletions
diff --git a/include/ecbor.h b/include/ecbor.h index 0977e4b..c8a43f7 100644 --- a/include/ecbor.h +++ b/include/ecbor.h @@ -61,8 +61,9 @@ typedef enum { * CBOR types */ typedef enum { - /* Unknown type */ - ECBOR_TYPE_UNDEFINED = -1, + /* This is used when, for some reason, no other type could be resolved; + Usually denotes an error occured. */ + ECBOR_TYPE_NONE = -1, /* First type, used for bounds checking */ ECBOR_TYPE_FIRST = 0, @@ -84,9 +85,10 @@ typedef enum { ECBOR_TYPE_FP64 = 10, ECBOR_TYPE_BOOL = 11, ECBOR_TYPE_NULL = 12, + ECBOR_TYPE_UNDEFINED = 13, /* Last type, used for bounds checking */ - ECBOR_TYPE_LAST = ECBOR_TYPE_NULL + ECBOR_TYPE_LAST = ECBOR_TYPE_UNDEFINED } ecbor_type_t; /* diff --git a/src/ecbor.c b/src/ecbor.c index 2093366..96cc4cc 100644 --- a/src/ecbor.c +++ b/src/ecbor.c @@ -88,11 +88,11 @@ extern ecbor_type_t ecbor_get_type (ecbor_item_t *item) { if (!item) { - return ECBOR_TYPE_UNDEFINED; + return ECBOR_TYPE_NONE; } if (item->type < ECBOR_TYPE_FIRST || item->type > ECBOR_TYPE_LAST) { - return ECBOR_TYPE_UNDEFINED; + return ECBOR_TYPE_NONE; } return item->type; } diff --git a/src/ecbor_decoder.c b/src/ecbor_decoder.c index 9990ac5..437698d 100644 --- a/src/ecbor_decoder.c +++ b/src/ecbor_decoder.c @@ -211,6 +211,7 @@ ecbor_decode_simple_value (ecbor_item_t *item) break; case ECBOR_SIMPLE_UNDEFINED: + item->type = ECBOR_TYPE_UNDEFINED; break; default: @@ -239,7 +240,7 @@ ecbor_decode_next_internal (ecbor_decode_context_t *context, } /* clear item, just so we do not leave garbage on partial read */ - item->type = ECBOR_TYPE_UNDEFINED; + item->type = ECBOR_TYPE_NONE; item->size = 0; item->length = 0; item->is_indefinite = false; @@ -384,7 +385,7 @@ ecbor_decode_next_internal (ecbor_decode_context_t *context, while (true) { /* read next chunk */ rc = ecbor_decode_next_internal (context, &child, false, - ECBOR_TYPE_UNDEFINED); + ECBOR_TYPE_NONE); if (rc != ECBOR_OK) { if (rc == ECBOR_END_OF_INDEFINITE) { /* stop code found, break from loop */ @@ -434,7 +435,7 @@ ecbor_decode_next_internal (ecbor_decode_context_t *context, for (child_no = 0; child_no < item->length; child_no ++) { /* read next child */ rc = ecbor_decode_next_internal (context, &child, false, - ECBOR_TYPE_UNDEFINED); + ECBOR_TYPE_NONE); if (rc != ECBOR_OK) { if (rc == ECBOR_END_OF_INDEFINITE) { /* stop code found, but none is expected */ @@ -476,7 +477,7 @@ ecbor_decode_next_internal (ecbor_decode_context_t *context, /* not in streamed mode; compute size so we can advance */ rc = ecbor_decode_next_internal (context, &child, false, - ECBOR_TYPE_UNDEFINED); + ECBOR_TYPE_NONE); if (rc != ECBOR_OK) { return rc; } @@ -550,7 +551,7 @@ ecbor_decode (ecbor_decode_context_t *context, ecbor_item_t *item) } /* we just get the next item */ - return ecbor_decode_next_internal (context, item, false, ECBOR_TYPE_UNDEFINED); + return ecbor_decode_next_internal (context, item, false, ECBOR_TYPE_NONE); } extern ecbor_error_t @@ -587,7 +588,7 @@ ecbor_decode_tree (ecbor_decode_context_t *context) /* consume next item */ rc = ecbor_decode_next_internal (context, &curr_node->item, false, - ECBOR_TYPE_UNDEFINED); + ECBOR_TYPE_NONE); /* handle end of indefinite */ if (rc == ECBOR_END_OF_INDEFINITE) { diff --git a/src/ecbor_describe.c b/src/ecbor_describe.c index fea511c..2ae9ccf 100644 --- a/src/ecbor_describe.c +++ b/src/ecbor_describe.c @@ -263,6 +263,10 @@ print_ecbor_item (ecbor_item_t *item, unsigned int level, char *prefix) case ECBOR_TYPE_NULL: printf ("[NULL]\n"); break; + + case ECBOR_TYPE_UNDEFINED: + printf ("[UNDEFINED]\n"); + break; default: printf ("[UNKNOWN]\n"); diff --git a/test/files/appendix_a/0043.answer b/test/files/appendix_a/0043.answer new file mode 100644 index 0000000..da54660 --- /dev/null +++ b/test/files/appendix_a/0043.answer @@ -0,0 +1 @@ +[UNDEFINED] |
