diff options
| author | rimio <vasi.vilvoiu@gmail.com> | 2018-03-02 00:04:17 +0200 |
|---|---|---|
| committer | rimio <vasi.vilvoiu@gmail.com> | 2018-03-02 00:04:17 +0200 |
| commit | 760860f3a34873e00cbf2ccb473f78cf3933a2f2 (patch) | |
| tree | e9bed480f87a69225b5715ab8b6c7c9610292494 /src/ecbor_decoder.c | |
| parent | 3d821056f53edcf6fc8786f0d156fa56720a0c5a (diff) | |
Added support for boolean and null types; added test case answers
Diffstat (limited to 'src/ecbor_decoder.c')
| -rw-r--r-- | src/ecbor_decoder.c | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/src/ecbor_decoder.c b/src/ecbor_decoder.c index 8d114dd..9990ac5 100644 --- a/src/ecbor_decoder.c +++ b/src/ecbor_decoder.c @@ -195,6 +195,31 @@ ecbor_decode_fp64 (ecbor_decode_context_t *context, return ECBOR_OK; } +static inline ecbor_error_t +ecbor_decode_simple_value (ecbor_item_t *item) +{ + switch (item->value.uinteger) { + case ECBOR_SIMPLE_FALSE: + case ECBOR_SIMPLE_TRUE: + item->type = ECBOR_TYPE_BOOL; + item->value.uinteger = + (item->value.uinteger == ECBOR_SIMPLE_FALSE ? 0 : 1); + break; + + case ECBOR_SIMPLE_NULL: + item->type = ECBOR_TYPE_NULL; + break; + + case ECBOR_SIMPLE_UNDEFINED: + break; + + default: + return ECBOR_ERR_CURRENTLY_NOT_SUPPORTED; + } + + return ECBOR_OK; +} + static ecbor_error_t ecbor_decode_next_internal (ecbor_decode_context_t *context, ecbor_item_t *item, @@ -471,8 +496,16 @@ ecbor_decode_next_internal (ecbor_decode_context_t *context, item->size = 1; return ECBOR_END_OF_INDEFINITE; } else if (additional <= ECBOR_ADDITIONAL_1BYTE) { - return ecbor_decode_uint (context, &item->value.uinteger, &item->size, - additional); + ecbor_error_t rc; + /* read integer simple value */ + rc = ecbor_decode_uint (context, &item->value.uinteger, &item->size, + additional); + if (rc != ECBOR_OK) { + return rc; + } + + /* parse simple value */ + return ecbor_decode_simple_value (item); } else if (additional == ECBOR_ADDITIONAL_2BYTE) { /* currently we do not support half float */ return ECBOR_ERR_CURRENTLY_NOT_SUPPORTED; |
