summaryrefslogtreecommitdiff
path: root/src/cbor/cbor_decoder.cpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2022-12-02 13:39:00 +1100
committerjacqueline <me@jacqueline.id.au>2022-12-02 13:39:00 +1100
commit222c810b07ffc635fc7908d121e97e4d65ccc5c8 (patch)
tree91c7b5c72a11770ebf3695bf0c234597b2bc419d /src/cbor/cbor_decoder.cpp
parent71a4f5166f5491dc0982a18d62c63e28b3a52faa (diff)
downloadtangara-fw-222c810b07ffc635fc7908d121e97e4d65ccc5c8.tar.gz
fix build errors
Diffstat (limited to 'src/cbor/cbor_decoder.cpp')
-rw-r--r--src/cbor/cbor_decoder.cpp131
1 files changed, 0 insertions, 131 deletions
diff --git a/src/cbor/cbor_decoder.cpp b/src/cbor/cbor_decoder.cpp
deleted file mode 100644
index 20696afb..00000000
--- a/src/cbor/cbor_decoder.cpp
+++ /dev/null
@@ -1,131 +0,0 @@
-#include "cbor_decoder.hpp"
-#include <cstdint>
-#include "esp-idf/components/cbor/tinycbor/src/cbor.h"
-#include "include/cbor_decoder.hpp"
-
-namespace cbor {
-
-static auto ArrayDecoder::Create(uint8_t* buffer, size_t buffer_len)
- -> cpp::result<std::unique_ptr<ArrayDecoder>, CborError> {
- auto decoder = std::make_unique<ArrayDecoder>();
- cbor_parser_init(buffer, buffer_len, &decoder->parser_, &decoder->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 ArrayDecoder::Create(CborValue& root)
- -> cpp::result<std::unique_ptr<ArrayDecoder>, CborError> {
- auto decoder = std::make_unique<ArrayDecoder>();
- 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<std::unique_ptr<MapDecoder>, CborError> {
- auto decoder = std::make_unique<MapDecoder>();
- cbor_parser_init(buffer, buffer_len, &decoder->parser_, &decoder->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);
-}
-
-static auto MapDecoder::Create(CborValue& root)
- -> cpp::result<std::unique_ptr<MapDecoder>, CborError> {
- auto decoder = std::make_unique<MapDecoder>();
- 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<std::string> {
- CborValue val;
- if (error_ != CborNoError) {
- return {};
- }
- if (cbor_value_map_find_value(&it_, key.c_str(), &val) != CborNoError) {
- return {};
- }
- if (!cbor_value_is_byte_string(&val)) {
- error_ = CborErrorIllegalType;
- return {};
- }
- uint8_t* buf;
- size_t len;
- error_ = cbor_value_dup_byte_string(&val, &buf, &len, NULL);
- if (error_ != CborNoError) {
- return cpp::fail(error_);
- }
- std::string ret(buf, len);
- free(buf);
- return ret;
-}
-
-auto MapDecoder::FindUnsigned(const std::string& key)
- -> std::optional<uint32_t> {
- CborValue val;
- if (error_ != CborNoError) {
- return {};
- }
- if (cbor_value_map_find_value(&it_, key.c_str(), &val) != CborNoError) {
- return {};
- }
- if (!cbor_value_is_unsigned_integer(&val)) {
- error_ = CborErrorIllegalType;
- return {};
- }
- uint64_t ret;
- error_ = cbor_value_get_uint64(&val, &ret);
- if (error_ != CborNoError) {
- return cpp::fail(error_);
- }
- return ret;
-}
-
-auto MapDecoder::FindSigned(const std::string& key) -> std::optional<int32_t> {
- CborValue val;
- if (error_ != CborNoError) {
- 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)) {
- error_ = CborErrorIllegalType;
- return {};
- }
- int32_t ret;
- error_ = cbor_value_get_int(&val, &ret);
- if (error_ != CborNoError) {
- return cpp::fail(error_);
- }
- return ret;
-}
-
-} // namespace cbor