From a7df2855889055976956a58d2a36f23626371ee9 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 23 Nov 2022 17:15:06 +1100 Subject: Mostly done pipeline arch. Now onto cleanup and building. --- src/cbor/cbor_decoder.cpp | 48 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) (limited to 'src/cbor/cbor_decoder.cpp') diff --git a/src/cbor/cbor_decoder.cpp b/src/cbor/cbor_decoder.cpp index f0b497b3..20696afb 100644 --- a/src/cbor/cbor_decoder.cpp +++ b/src/cbor/cbor_decoder.cpp @@ -5,7 +5,8 @@ namespace cbor { -static auto ArrayDecoder::Create(uint8_t *buffer, size_t buffer_len) -> cpp::result, CborError> { +static auto ArrayDecoder::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_); if (!cbor_value_is_array(&decoder->root_)) { @@ -18,7 +19,23 @@ static auto ArrayDecoder::Create(uint8_t *buffer, size_t buffer_len) -> cpp::res return std::move(decoder); } -static auto MapDecoder::Create(uint8_t *buffer, size_t buffer_len) -> cpp::result, CborError> { +static auto ArrayDecoder::Create(CborValue& root) + -> cpp::result, CborError> { + auto decoder = std::make_unique(); + decoder->root_ = root; + if (!cbor_value_is_array(&decoder->root_)) { + return cpp::fail(CborErrorIllegalType); + } + + CborError err = cbor_value_enter_container(&decoder->root_, &decoder->it_); + if (err != CborNoError) { + return cpp::fail(err); + } + return std::move(decoder); +} + +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_); if (!cbor_value_is_map(&decoder->root_)) { @@ -31,7 +48,22 @@ static auto MapDecoder::Create(uint8_t *buffer, size_t buffer_len) -> cpp::resul return std::move(decoder); } -auto MapDecoder::FindString(const std::string &key) -> std::optional { +static auto MapDecoder::Create(CborValue& root) + -> cpp::result, CborError> { + auto decoder = std::make_unique(); + decoder->root_ = root; + if (!cbor_value_is_map(&decoder->root_)) { + return cpp::fail(CborErrorIllegalType); + } + CborError err = cbor_value_enter_container(&decoder->root_, &decoder->it_); + if (err != CborNoError) { + return cpp::fail(err); + } + return std::move(decoder); +} + +auto MapDecoder::FindString(const std::string& key) + -> std::optional { CborValue val; if (error_ != CborNoError) { return {}; @@ -43,7 +75,8 @@ auto MapDecoder::FindString(const std::string &key) -> std::optional std::optional std::optional { +auto MapDecoder::FindUnsigned(const std::string& key) + -> std::optional { CborValue val; if (error_ != CborNoError) { return {}; @@ -73,7 +107,7 @@ auto MapDecoder::FindUnsigned(const std::string &key) -> std::optional return ret; } -auto MapDecoder::FindSigned(const std::string &key) -> std::optional { +auto MapDecoder::FindSigned(const std::string& key) -> std::optional { CborValue val; if (error_ != CborNoError) { return {}; @@ -94,4 +128,4 @@ auto MapDecoder::FindSigned(const std::string &key) -> std::optional { return ret; } -} // namespace cbor +} // namespace cbor -- cgit v1.2.3