summaryrefslogtreecommitdiff
path: root/src/cbor/include/cbor_decoder.hpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2022-11-22 17:05:02 +1100
committerjacqueline <me@jacqueline.id.au>2022-11-22 17:05:02 +1100
commit9176ef187227ffb56c249c5f321cd1bf50d4cfcc (patch)
treea846c8fc4e5788e97d6fca43c2807c4bf0ae0214 /src/cbor/include/cbor_decoder.hpp
parent9f8cfaa7a8abd885785830e03d7c417e856b8a22 (diff)
downloadtangara-fw-9176ef187227ffb56c249c5f321cd1bf50d4cfcc.tar.gz
Add cbor wrapper, and chunk streaming util
Diffstat (limited to 'src/cbor/include/cbor_decoder.hpp')
-rw-r--r--src/cbor/include/cbor_decoder.hpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/cbor/include/cbor_decoder.hpp b/src/cbor/include/cbor_decoder.hpp
new file mode 100644
index 00000000..249db9cc
--- /dev/null
+++ b/src/cbor/include/cbor_decoder.hpp
@@ -0,0 +1,47 @@
+#pragma once
+
+#include <cstdint>
+namespace cbor {
+
+ class ArrayDecoder {
+ public:
+ static auto Create(uint8_t *buffer, size_t buffer_len) -> cpp::result<std::unique_ptr<ArrayDecoder>, CborError>;
+
+ auto ParseString() -> cpp::result<std::string, CborError>;
+ auto ParseUnsigned() -> cpp::result<uint32_t, CborError>;
+ auto ParseSigned() -> cpp::result<int32_t, CborError>;
+
+ auto Failed() -> CborError { return error_; }
+
+ ArrayDecoder(const ArrayDecoder&) = delete;
+ ArrayDecoder& operator=(const ArrayDecoder&) = delete;
+ private:
+ CborParser parser_;
+ CborValue root_;
+
+ CborValue it_;
+ CborError error_ = CborNoError;
+ };
+
+ class MapDecoder {
+ public:
+ static auto Create(uint8_t *buffer, size_t buffer_len) -> cpp::result<std::unique_ptr<MapDecoder>, CborError>;
+
+ auto FindString(const std::string &key) -> std::optional<std::string>;
+ auto FindUnsigned(const std::string &key) -> std::optional<uint32_t>;
+ auto FindSigned(const std::string &key) -> std::optional<int32_t>;
+
+ auto Failed() -> CborError { return error_; }
+
+ MapDecoder(const MapDecoder&) = delete;
+ MapDecoder& operator=(const MapDecoder&) = delete;
+ private:
+ CborParser parser_;
+ CborValue root_;
+
+ CborValue it_;
+ CborError error_ = CborNoError;
+ };
+
+
+} // namespace cbor