new cspot/bell

This commit is contained in:
philippe44
2023-05-06 23:50:26 +02:00
parent e0e7e718ba
commit 8bad480112
163 changed files with 6611 additions and 6739 deletions

View File

@@ -1,51 +1,36 @@
#pragma once
#include <pb_encode.h>
#include <string_view>
#include <vector>
#include <optional>
#include "NanoPBHelper.h"
#include "Utils.h"
#include "pb_decode.h"
#include "protobuf/spirc.pb.h"
namespace cspot {
namespace cspot {
struct TrackReference {
static constexpr auto base62Alphabet =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
TrackReference();
// Resolved track GID
std::vector<uint8_t> gid;
std::string uri, context;
std::optional<bool> queued;
// Type identifier
enum class Type { TRACK, EPISODE };
Type type;
static TrackReference fromTrackRef(TrackRef* ref) {
TrackReference trackRef;
if (ref->gid != nullptr) {
// For tracks, the GID is already in the protobuf
trackRef.gid = pbArrayToVector(ref->gid);
trackRef.type = Type::TRACK;
} else {
// Episode GID is being fetched via base62 encoded URI
auto uri = std::string(ref->uri);
auto idString = uri.substr(uri.find_last_of(":") + 1, uri.size());
trackRef.gid = {0};
void decodeURI();
std::string_view alphabet(base62Alphabet);
for (int x = 0; x < idString.size(); x++) {
size_t d = alphabet.find(idString[x]);
trackRef.gid = bigNumMultiply(trackRef.gid, 62);
trackRef.gid = bigNumAdd(trackRef.gid, d);
}
}
bool operator==(const TrackReference& other) const;
return trackRef;
}
// Encodes list of track references into a pb structure, used by nanopb
static bool pbEncodeTrackList(pb_ostream_t* stream, const pb_field_t* field,
void* const* arg);
static TrackReference fromGID(std::vector<uint8_t> gid, bool isEpisode) {
TrackReference trackRef;
trackRef.gid = gid;
trackRef.type = isEpisode ? Type::EPISODE : Type::TRACK;
return trackRef;
}
static bool pbDecodeTrackList(pb_istream_t* stream, const pb_field_t* field,
void** arg);
};
} // namespace cspot
} // namespace cspot