diff options
-rw-r--r-- | include/erebos/storage.h | 10 | ||||
-rw-r--r-- | src/storage.cpp | 14 |
2 files changed, 22 insertions, 2 deletions
diff --git a/include/erebos/storage.h b/include/erebos/storage.h index d855460..d23022f 100644 --- a/include/erebos/storage.h +++ b/include/erebos/storage.h @@ -160,12 +160,19 @@ class RecordT public: class Item { public: + struct UnknownType + { + std::string type; + std::string value; + }; + typedef std::variant< std::monostate, int, std::string, std::vector<uint8_t>, - typename S::Ref> Variant; + typename S::Ref, + UnknownType> Variant; Item(const std::string & name): Item(name, std::monostate()) {} @@ -184,6 +191,7 @@ public: std::optional<std::string> asText() const; std::optional<std::vector<uint8_t>> asBinary() const; std::optional<typename S::Ref> asRef() const; + std::optional<UnknownType> asUnknown() const; template<typename T> std::optional<Stored<T>> as() const; diff --git a/src/storage.cpp b/src/storage.cpp index 6b2e4f8..db9f629 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -574,6 +574,14 @@ optional<typename S::Ref> RecordT<S>::Item::asRef() const return nullopt; } +template<class S> +optional<typename RecordT<S>::Item::UnknownType> RecordT<S>::Item::asUnknown() const +{ + if (holds_alternative<typename Item::UnknownType>(value)) + return std::get<typename Item::UnknownType>(value); + return nullopt; +} + template<class S> RecordT<S>::RecordT(const vector<Item> & from): @@ -625,7 +633,8 @@ optional<RecordT<S>> RecordT<S>::decode(const S & st, items->emplace_back(name, st.ref(Digest(value))); } } else - throw runtime_error("unknown record item type"); + items->emplace_back(name, + typename Item::UnknownType { type, value }); begin = newline + 1; } @@ -696,6 +705,9 @@ vector<uint8_t> RecordT<S>::encodeInner() const } else if (auto x = item.asRef()) { type = "r.b2"; value = string(x->digest()); + } else if (auto x = item.asUnknown()) { + type = x->type; + value = x->value; } else { throw runtime_error("unhandeled record item type"); } |