#ifndef __STATE_SERIALIZER_HPP__ #define __STATE_SERIALIZER_HPP__ #include #include // For ArrayInputStream. #include #include #include namespace mesos { namespace internal { namespace state { struct StringSerializer { template static Try deserialize(const std::string& value) { return value; } template static Try serialize(const std::string& value) { return value; } }; struct ProtobufSerializer { template static Try deserialize(const std::string& value) { T t; (void)static_cast(&t); google::protobuf::io::ArrayInputStream stream(value.data(), value.size()); if (!t.ParseFromZeroCopyStream(&stream)) { return Error( "Failed to deserialize " + t.GetDescriptor()->full_name()); } return t; } template static Try serialize(const T& t) { // TODO(benh): Actually store the descriptor so that we can verify // type information (and compatibility) when we deserialize. std::string value; if (!t.SerializeToString(&value)) { return Error( "Failed to serialize " + t.GetDescriptor()->full_name()); } return value; } }; } // namespace state { } // namespace internal { } // namespace mesos { #endif // __STATE_SERIALIZER_HPP__