diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-10-13 15:05:49 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-10-13 15:05:49 +1100 |
| commit | afbf3c31f4d1a605c264f719531f4183ee5a3022 (patch) | |
| tree | 43c75029ff6dfe3e44137f6b3d0de3498f247bf2 /src/database/include | |
| parent | 20d1c280a77eadcea18438453dc37daaf1d85e2d (diff) | |
| download | tangara-fw-afbf3c31f4d1a605c264f719531f4183ee5a3022.tar.gz | |
Use libcppbor for much much nicer db encoding
Diffstat (limited to 'src/database/include')
| -rw-r--r-- | src/database/include/records.hpp | 31 | ||||
| -rw-r--r-- | src/database/include/track.hpp | 5 |
2 files changed, 9 insertions, 27 deletions
diff --git a/src/database/include/records.hpp b/src/database/include/records.hpp index e7d7738c..e13c6568 100644 --- a/src/database/include/records.hpp +++ b/src/database/include/records.hpp @@ -22,32 +22,19 @@ namespace database { /* - * Helper class for creating leveldb Slices bundled with the data they point to. - * Slices are otherwise non-owning, which can make handling them post-creation - * difficult. - */ -class OwningSlice { - public: - std::pmr::string data; - leveldb::Slice slice; - - explicit OwningSlice(std::pmr::string d); -}; - -/* * Returns the prefix added to every TrackData key. This can be used to iterate * over every data record in the database. */ -auto EncodeDataPrefix() -> OwningSlice; +auto EncodeDataPrefix() -> std::string; /* Encodes a data key for a track with the specified id. */ -auto EncodeDataKey(const TrackId& id) -> OwningSlice; +auto EncodeDataKey(const TrackId& id) -> std::string; /* * Encodes a TrackData instance into bytes, in preparation for storing it within * the database. This encoding is consistent, and will remain stable over time. */ -auto EncodeDataValue(const TrackData& track) -> OwningSlice; +auto EncodeDataValue(const TrackData& track) -> std::string; /* * Parses bytes previously encoded via EncodeDataValue back into a TrackData. @@ -56,14 +43,14 @@ auto EncodeDataValue(const TrackData& track) -> OwningSlice; auto ParseDataValue(const leveldb::Slice& slice) -> std::shared_ptr<TrackData>; /* Encodes a hash key for the specified hash. */ -auto EncodeHashKey(const uint64_t& hash) -> OwningSlice; +auto EncodeHashKey(const uint64_t& hash) -> std::string; /* * Encodes a hash value (at this point just a track id) into bytes, in * preparation for storing within the database. This encoding is consistent, and * will remain stable over time. */ -auto EncodeHashValue(TrackId id) -> OwningSlice; +auto EncodeHashValue(TrackId id) -> std::string; /* * Parses bytes previously encoded via EncodeHashValue back into a track id. May @@ -72,17 +59,17 @@ auto EncodeHashValue(TrackId id) -> OwningSlice; auto ParseHashValue(const leveldb::Slice&) -> std::optional<TrackId>; /* Encodes a prefix that matches all index keys, of all ids and depths. */ -auto EncodeAllIndexesPrefix() -> OwningSlice; +auto EncodeAllIndexesPrefix() -> std::string; /* */ -auto EncodeIndexPrefix(const IndexKey::Header&) -> OwningSlice; +auto EncodeIndexPrefix(const IndexKey::Header&) -> std::string; -auto EncodeIndexKey(const IndexKey&) -> OwningSlice; +auto EncodeIndexKey(const IndexKey&) -> std::string; auto ParseIndexKey(const leveldb::Slice&) -> std::optional<IndexKey>; /* Encodes a TrackId as bytes. */ -auto TrackIdToBytes(TrackId id) -> OwningSlice; +auto TrackIdToBytes(TrackId id) -> std::string; /* * Converts a track id encoded via TrackIdToBytes back into a TrackId. May diff --git a/src/database/include/track.hpp b/src/database/include/track.hpp index 3c7b20fa..44bfbc54 100644 --- a/src/database/include/track.hpp +++ b/src/database/include/track.hpp @@ -117,7 +117,6 @@ class TrackData { const TrackId id_; const std::pmr::string filepath_; const uint64_t tags_hash_; - const uint32_t play_count_; const bool is_tombstoned_; public: @@ -126,18 +125,15 @@ class TrackData { : id_(id), filepath_(path, &memory::kSpiRamResource), tags_hash_(hash), - play_count_(0), is_tombstoned_(false) {} TrackData(TrackId id, const std::pmr::string& path, uint64_t hash, - uint32_t play_count, bool is_tombstoned) : id_(id), filepath_(path, &memory::kSpiRamResource), tags_hash_(hash), - play_count_(play_count), is_tombstoned_(is_tombstoned) {} TrackData(TrackData&& other) = delete; @@ -147,7 +143,6 @@ class TrackData { auto id() const -> TrackId { return id_; } auto filepath() const -> std::pmr::string { return filepath_; } - auto play_count() const -> uint32_t { return play_count_; } auto tags_hash() const -> uint64_t { return tags_hash_; } auto is_tombstoned() const -> bool { return is_tombstoned_; } |
