summaryrefslogtreecommitdiff
path: root/src/cbor/include/cbor_encoder.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_encoder.hpp
parent9f8cfaa7a8abd885785830e03d7c417e856b8a22 (diff)
downloadtangara-fw-9176ef187227ffb56c249c5f321cd1bf50d4cfcc.tar.gz
Add cbor wrapper, and chunk streaming util
Diffstat (limited to 'src/cbor/include/cbor_encoder.hpp')
-rw-r--r--src/cbor/include/cbor_encoder.hpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/cbor/include/cbor_encoder.hpp b/src/cbor/include/cbor_encoder.hpp
new file mode 100644
index 00000000..0edbbdff
--- /dev/null
+++ b/src/cbor/include/cbor_encoder.hpp
@@ -0,0 +1,30 @@
+#pragma once
+
+#include <cstdint>
+#include "esp-idf/components/cbor/tinycbor/src/cbor.h"
+namespace cbor {
+
+ class Encoder {
+ public:
+ enum ContainerType {
+ CONTAINER_ARRAY,
+ CONTAINER_MAP
+ };
+ Encoder(ContainerType type, uint32_t container_len, uint8_t *buffer, size_t buffer_len);
+
+ auto WriteString(const std::string &val) -> void;
+ auto WriteUnsigned(uint32_t val) -> void;
+ auto WriteSigned(int32_t val) -> void;
+
+ auto Finish() -> cpp::result<size_t, CborError>;
+
+ Encoder(const Encoder&) = delete;
+ Encoder& operator=(const Encoder&) = delete;
+ private:
+ CborEncoder root_encoder_;
+ CborEncoder container_encoder_;
+
+ CborError error_ = CborNoError;
+ };
+
+} // namespace cbor