Serialize cacheFormat as string literal

This commit is contained in:
Fangrui Song 2018-01-08 22:22:24 -08:00
parent c0a9b7189f
commit a7bf90f50b
2 changed files with 22 additions and 1 deletions

View File

@ -201,6 +201,22 @@ void Reflect(TVisitor& visitor, IndexFile& value) {
REFLECT_MEMBER_END();
}
void Reflect(Reader& visitor, SerializeFormat& value) {
std::string fmt = visitor.GetString();
value = fmt[0] == 'm' ? SerializeFormat::MessagePack : SerializeFormat::Json;
}
void Reflect(Writer& visitor, SerializeFormat& value) {
switch (value) {
case SerializeFormat::Json:
visitor.String("json");
break;
case SerializeFormat::MessagePack:
visitor.String("msgpack");
break;
}
}
std::string Serialize(SerializeFormat format, IndexFile& file) {
switch (format) {

View File

@ -253,7 +253,12 @@ void ReflectMember(Reader& visitor, const char* name, T& value) {
visitor.DoMember(name, [&](Reader& child) { Reflect(child, value); });
}
MAKE_REFLECT_TYPE_PROXY(SerializeFormat, int)
// Specializations
void Reflect(Reader& visitor, SerializeFormat& value);
void Reflect(Writer& visitor, SerializeFormat& value);
// API
std::string Serialize(SerializeFormat format, IndexFile& file);
std::unique_ptr<IndexFile> Deserialize(SerializeFormat format,