From a7bf90f50beb956355a8f027bc673481b070f6f2 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 8 Jan 2018 22:22:24 -0800 Subject: [PATCH] Serialize cacheFormat as string literal --- src/serializer.cc | 16 ++++++++++++++++ src/serializer.h | 7 ++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/serializer.cc b/src/serializer.cc index 271bce3a..9c447b17 100644 --- a/src/serializer.cc +++ b/src/serializer.cc @@ -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) { diff --git a/src/serializer.h b/src/serializer.h index 801236af..29c9a41c 100644 --- a/src/serializer.h +++ b/src/serializer.h @@ -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 Deserialize(SerializeFormat format,