diff options
| author | jacqueline <me@jacqueline.id.au> | 2022-11-23 17:15:06 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2022-11-23 17:15:06 +1100 |
| commit | a7df2855889055976956a58d2a36f23626371ee9 (patch) | |
| tree | 16e180e57f84474acaeb1893208cc07e278af6f4 /src/cbor/include/cbor_encoder.hpp | |
| parent | dfa9ab6e04689b99267092e016a91d9254f94cd8 (diff) | |
| download | tangara-fw-a7df2855889055976956a58d2a36f23626371ee9.tar.gz | |
Mostly done pipeline arch. Now onto cleanup and building.
Diffstat (limited to 'src/cbor/include/cbor_encoder.hpp')
| -rw-r--r-- | src/cbor/include/cbor_encoder.hpp | 55 |
1 files changed, 31 insertions, 24 deletions
diff --git a/src/cbor/include/cbor_encoder.hpp b/src/cbor/include/cbor_encoder.hpp index 0edbbdff..9479a3b6 100644 --- a/src/cbor/include/cbor_encoder.hpp +++ b/src/cbor/include/cbor_encoder.hpp @@ -4,27 +4,34 @@ #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 +class Encoder { + public: + enum ContainerType { CONTAINER_ARRAY, CONTAINER_MAP }; + Encoder(ContainerType type, + uint32_t container_len, + uint8_t* buffer, + size_t buffer_len); + + template <typename T> + auto WriteKeyValue(const std::string& key, const T& val) -> void { + WriteValue(key); + WriteValue(val); + } + + auto WriteValue(const std::string& val) -> void; + auto WriteValue(uint32_t val) -> void; + auto WriteValue(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 |
