From dfa9ab6e04689b99267092e016a91d9254f94cd8 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 22 Nov 2022 23:10:42 +1100 Subject: template-ify the cbor stuff --- src/cbor/cbor_decoder.cpp | 63 +---------------------------------------------- 1 file changed, 1 insertion(+), 62 deletions(-) (limited to 'src/cbor/cbor_decoder.cpp') diff --git a/src/cbor/cbor_decoder.cpp b/src/cbor/cbor_decoder.cpp index eb43e163..f0b497b3 100644 --- a/src/cbor/cbor_decoder.cpp +++ b/src/cbor/cbor_decoder.cpp @@ -18,68 +18,6 @@ static auto ArrayDecoder::Create(uint8_t *buffer, size_t buffer_len) -> cpp::res return std::move(decoder); } - -auto ArrayDecoder::ParseString() -> cpp::result { - if (error_ != CborNoError) { - return cpp::fail(error_); - } - - if (!cbor_value_is_byte_string(&it_)) { - error_ = CborErrorIllegalType; - return cpp::fail(error_); - } - uint8_t *buf; size_t len; CborValue new_val; - error_ = cbor_value_dup_byte_string(&it_, &buf, &len, &new_val); - if (error_ != CborNoError) { - return cpp::fail(error_); - } - std::string ret(buf, len); - free(buf); - val_ = new_val; - return ret; -} - -auto ArrayDecoder::ParseUnsigned() -> cpp::result { - if (error_ != CborNoError) { - return cpp::fail(error_); - } - - if (!cbor_value_is_unsigned_integer(&it_)) { - error_ = CborErrorIllegalType; - return cpp::fail(error_); - } - uint64_t ret; - error_ = cbor_value_get_uint64(&it_, &ret); - if (error_ != CborNoError) { - return cpp::fail(error_); - } - error_ = cbor_value_advance(&it_); - if (error_ != CborNoError) { - return cpp::fail(error_); - } - return ret; -} - -auto ArrayDecoder::ParseSigned() -> cpp::result { - if (error_ != CborNoError) { - return cpp::fail(error_); - } - if (!cbor_value_is_unsigned_integer(&it_)) { - error_ = CborErrorIllegalType; - return cpp::fail(error_); - } - uint64_t ret; - error_ = cbor_value_get_uint64(&it_, &ret); - if (error_ != CborNoError) { - return cpp::fail(error_); - } - error_ = cbor_value_advance(&it_); - if (error_ != CborNoError) { - return cpp::fail(error_); - } - return ret; -} - static auto MapDecoder::Create(uint8_t *buffer, size_t buffer_len) -> cpp::result, CborError> { auto decoder = std::make_unique(); cbor_parser_init(buffer, buffer_len, &decoder->parser_, &decoder->root_); @@ -141,6 +79,7 @@ auto MapDecoder::FindSigned(const std::string &key) -> std::optional { return {}; } if (cbor_value_map_find_value(&it_, key.c_str(), &val) != CborNoError) { + // Don't store this as an error; missing keys are fine. return {}; } if (!cbor_value_is_integer(&val)) { -- cgit v1.2.3