summaryrefslogtreecommitdiff
path: root/src/storage.cpp
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2020-01-27 21:56:06 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2020-02-05 21:02:08 +0100
commit495d2cb6b47b309070b31e0ef83fa5731a150a6d (patch)
treedddf94ae3513409d2e80801b085686cf88c760a5 /src/storage.cpp
parentab86a1f0c3b86050e65fc5b7ac1e88a00f0d228c (diff)
Storage: handle record items with unknown type
Diffstat (limited to 'src/storage.cpp')
-rw-r--r--src/storage.cpp14
1 files changed, 13 insertions, 1 deletions
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");
}