summaryrefslogtreecommitdiff
path: root/src/audio/stream_info.cpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2022-12-02 13:39:00 +1100
committerjacqueline <me@jacqueline.id.au>2022-12-02 13:39:00 +1100
commit222c810b07ffc635fc7908d121e97e4d65ccc5c8 (patch)
tree91c7b5c72a11770ebf3695bf0c234597b2bc419d /src/audio/stream_info.cpp
parent71a4f5166f5491dc0982a18d62c63e28b3a52faa (diff)
downloadtangara-fw-222c810b07ffc635fc7908d121e97e4d65ccc5c8.tar.gz
fix build errors
Diffstat (limited to 'src/audio/stream_info.cpp')
-rw-r--r--src/audio/stream_info.cpp53
1 files changed, 30 insertions, 23 deletions
diff --git a/src/audio/stream_info.cpp b/src/audio/stream_info.cpp
index 6011571d..a5f7bebf 100644
--- a/src/audio/stream_info.cpp
+++ b/src/audio/stream_info.cpp
@@ -1,26 +1,31 @@
#include "stream_info.hpp"
+
#include <cstdint>
+#include <string>
+
+#include "cbor.h"
+
#include "cbor_decoder.hpp"
-#include "esp-idf/components/cbor/tinycbor/src/cbor.h"
+#include "cbor_encoder.hpp"
#include "stream_message.hpp"
namespace audio {
-static const char* kKeyPath = "p";
-static const char* kKeyChannels = "c";
-static const char* kKeyBitsPerSample = "b";
-static const char* kKeySampleRate = "r";
+static const std::string kKeyPath = "p";
+static const std::string kKeyChannels = "c";
+static const std::string kKeyBitsPerSample = "b";
+static const std::string kKeySampleRate = "r";
-static auto StreamInfo::Create(const uint8_t* buffer, size_t length)
+auto StreamInfo::Create(const uint8_t* buffer, size_t length)
-> cpp::result<StreamInfo, ParseError> {
CborParser parser;
CborValue value;
- cbor_parser_init(buffer, len, 0, &parser, &value);
+ cbor_parser_init(buffer, length, 0, &parser, &value);
- uint8_t type = 0;
- if (!cbor_value_is_integer(&value) ||
- !cbor_value_get_integer(&value, &type) || type != STREAM_INFO) {
+ int type = 0;
+ if (!cbor_value_is_integer(&value) || !cbor_value_get_int(&value, &type) ||
+ type != TYPE_STREAM_INFO) {
return cpp::fail(WRONG_TYPE);
}
@@ -30,26 +35,28 @@ static auto StreamInfo::Create(const uint8_t* buffer, size_t length)
return cpp::fail(MISSING_MAP);
}
- return StreamInfo(value);
+ auto map_decoder = cbor::MapDecoder::Create(value);
+ if (map_decoder.has_value()) {
+ return StreamInfo(map_decoder.value().get());
+ }
+ return cpp::fail(CBOR_ERROR);
}
-StreamInfo::StreamInfo(CborValue& map) {
+StreamInfo::StreamInfo(cbor::MapDecoder* decoder) {
// TODO: this method is n^2, which seems less than ideal. But you don't do it
// that frequently, so maybe it's okay? Needs investigation.
- cbor::MapDecoder decoder(map);
- channels_ = decoder.FindValue(kKeyChannels);
- bits_per_sample_ = decoder.FindValue(kKeyBitsPerSample);
- sample_rate_ = decoder.FindValue(kKeySampleRate);
- path_ = decoder.FindValue(kKeyPath);
+ channels_ = decoder->FindValue<uint64_t>(kKeyChannels);
+ bits_per_sample_ = decoder->FindValue<uint64_t>(kKeyBitsPerSample);
+ sample_rate_ = decoder->FindValue<uint64_t>(kKeySampleRate);
+ path_ = decoder->FindValue<std::string>(kKeyPath);
}
auto StreamInfo::WriteToMap(cbor::Encoder& map_encoder)
- -> cpp::result<size_t, EncodeError> {
- CborEncoder map;
- map_encoder.WriteKeyValue(kKeyChannels, channels_);
- map_encoder.WriteKeyValue(kKeyBitsPerSample, bits_per_sample_);
- map_encoder.WriteKeyValue(kKeySampleRate, sample_rate_);
- map_encoder.WriteKeyValue(kKeyPath, path_);
+ -> cpp::result<size_t, CborError> {
+ map_encoder.WriteKeyValue<uint64_t>(kKeyChannels, channels_);
+ map_encoder.WriteKeyValue<uint64_t>(kKeyBitsPerSample, bits_per_sample_);
+ map_encoder.WriteKeyValue<uint64_t>(kKeySampleRate, sample_rate_);
+ map_encoder.WriteKeyValue<std::string>(kKeyPath, path_);
return map_encoder.Finish();
}