summaryrefslogtreecommitdiff
path: root/src/cbor/cbor_decoder.cpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2022-11-22 23:10:42 +1100
committerjacqueline <me@jacqueline.id.au>2022-11-22 23:10:42 +1100
commitdfa9ab6e04689b99267092e016a91d9254f94cd8 (patch)
tree6f33f8d0d099fb85efa746e041e836f4505371ee /src/cbor/cbor_decoder.cpp
parent9176ef187227ffb56c249c5f321cd1bf50d4cfcc (diff)
downloadtangara-fw-dfa9ab6e04689b99267092e016a91d9254f94cd8.tar.gz
template-ify the cbor stuff
Diffstat (limited to 'src/cbor/cbor_decoder.cpp')
-rw-r--r--src/cbor/cbor_decoder.cpp63
1 files changed, 1 insertions, 62 deletions
diff --git a/src/cbor/cbor_decoder.cpp b/src/cbor/cbor_decoder.cpp
index eb43e163..f0b497b3 100644
--- a/src/cbor/cbor_decoder.cpp
+++ b/src/cbor/cbor_decoder.cpp
@@ -18,68 +18,6 @@ static auto ArrayDecoder::Create(uint8_t *buffer, size_t buffer_len) -> cpp::res
return std::move(decoder);
}
-
-auto ArrayDecoder::ParseString() -> cpp::result<std::string, CborError> {
- if (error_ != CborNoError) {
- return cpp::fail(error_);
- }
-
- if (!cbor_value_is_byte_string(&it_)) {
- error_ = CborErrorIllegalType;
- return cpp::fail(error_);
- }
- uint8_t *buf; size_t len; CborValue new_val;
- error_ = cbor_value_dup_byte_string(&it_, &buf, &len, &new_val);
- if (error_ != CborNoError) {
- return cpp::fail(error_);
- }
- std::string ret(buf, len);
- free(buf);
- val_ = new_val;
- return ret;
-}
-
-auto ArrayDecoder::ParseUnsigned() -> cpp::result<uint32_t, CborError> {
- if (error_ != CborNoError) {
- return cpp::fail(error_);
- }
-
- if (!cbor_value_is_unsigned_integer(&it_)) {
- error_ = CborErrorIllegalType;
- return cpp::fail(error_);
- }
- uint64_t ret;
- error_ = cbor_value_get_uint64(&it_, &ret);
- if (error_ != CborNoError) {
- return cpp::fail(error_);
- }
- error_ = cbor_value_advance(&it_);
- if (error_ != CborNoError) {
- return cpp::fail(error_);
- }
- return ret;
-}
-
-auto ArrayDecoder::ParseSigned() -> cpp::result<int32_t, CborError> {
- if (error_ != CborNoError) {
- return cpp::fail(error_);
- }
- if (!cbor_value_is_unsigned_integer(&it_)) {
- error_ = CborErrorIllegalType;
- return cpp::fail(error_);
- }
- uint64_t ret;
- error_ = cbor_value_get_uint64(&it_, &ret);
- if (error_ != CborNoError) {
- return cpp::fail(error_);
- }
- error_ = cbor_value_advance(&it_);
- if (error_ != CborNoError) {
- return cpp::fail(error_);
- }
- return ret;
-}
-
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_);
@@ -141,6 +79,7 @@ auto MapDecoder::FindSigned(const std::string &key) -> std::optional<int32_t> {
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)) {