summaryrefslogtreecommitdiff
path: root/src/cbor/include/cbor_decoder.hpp
blob: 249db9cc2096887775eac55395d09384df9625ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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