1
0
mirror of https://github.com/anope/anope.git synced 2026-06-30 23:06:40 +02:00

Move serialization from Serializable to a Serialize::Type child.

This commit is contained in:
Sadie Powell
2025-03-12 10:29:11 +00:00
parent 718f2e922a
commit cdcf0e2f9a
40 changed files with 778 additions and 452 deletions
+45 -32
View File
@@ -38,20 +38,26 @@ AutoKick::~AutoKick()
}
}
void AutoKick::Serialize(Serialize::Data &data) const
AutoKick::Type::Type()
: Serialize::Type("AutoKick")
{
data.Store("ci", this->ci->name);
if (this->nc)
data.Store("nc", this->nc->display);
else
data.Store("mask", this->mask);
data.Store("reason", this->reason);
data.Store("creator", this->creator);
data.Store("addtime", this->addtime);
data.Store("last_used", this->last_used);
}
Serializable *AutoKick::Unserialize(Serializable *obj, Serialize::Data &data)
void AutoKick::Type::Serialize(const Serializable *obj, Serialize::Data &data) const
{
const auto *ak = static_cast<const AutoKick *>(obj);
data.Store("ci", ak->ci->name);
if (ak->nc)
data.Store("nc", ak->nc->display);
else
data.Store("mask", ak->mask);
data.Store("reason", ak->reason);
data.Store("creator", ak->creator);
data.Store("addtime", ak->addtime);
data.Store("last_used", ak->last_used);
}
Serializable *AutoKick::Type::Unserialize(Serializable *obj, Serialize::Data &data) const
{
Anope::string sci, snc;
@@ -178,40 +184,47 @@ ChannelInfo::~ChannelInfo()
}
}
void ChannelInfo::Serialize(Serialize::Data &data) const
ChannelInfo::Type::Type()
: Serialize::Type("ChannelInfo")
{
data.Store("name", this->name);
if (this->founder)
data.Store("founder", this->founder->display);
if (this->successor)
data.Store("successor", this->successor->display);
data.Store("description", this->desc);
data.Store("time_registered", this->time_registered);
data.Store("last_used", this->last_used);
data.Store("last_topic", this->last_topic);
data.Store("last_topic_setter", this->last_topic_setter);
data.Store("last_topic_time", this->last_topic_time);
data.Store("bantype", this->bantype);
}
void ChannelInfo::Type::Serialize(const Serializable *obj, Serialize::Data &data) const
{
const auto *ci = static_cast<const ChannelInfo *>(obj);
data.Store("name", ci->name);
if (ci->founder)
data.Store("founder", ci->founder->display);
if (ci->successor)
data.Store("successor", ci->successor->display);
data.Store("description", ci->desc);
data.Store("time_registered", ci->time_registered);
data.Store("last_used", ci->last_used);
data.Store("last_topic", ci->last_topic);
data.Store("last_topic_setter", ci->last_topic_setter);
data.Store("last_topic_time", ci->last_topic_time);
data.Store("bantype", ci->bantype);
{
Anope::string levels_buffer;
for (const auto &[name, level] : this->levels)
for (const auto &[name, level] : ci->levels)
levels_buffer += name + " " + Anope::ToString(level) + " ";
data.Store("levels", levels_buffer);
}
if (this->bi)
data.Store("bi", this->bi->nick);
data.Store("banexpire", this->banexpire);
data.Store("memomax", this->memos.memomax);
if (ci->bi)
data.Store("bi", ci->bi->nick);
data.Store("banexpire", ci->banexpire);
data.Store("memomax", ci->memos.memomax);
std::ostringstream oss;
for (const auto &ignore : this->memos.ignores)
for (const auto &ignore : ci->memos.ignores)
oss << ignore << " ";
data.Store("memoignores", oss.str());
Extensible::ExtensibleSerialize(this, this, data);
Extensible::ExtensibleSerialize(ci, ci, data);
}
Serializable *ChannelInfo::Unserialize(Serializable *obj, Serialize::Data &data)
Serializable *ChannelInfo::Type::Unserialize(Serializable *obj, Serialize::Data &data) const
{
Anope::string sname, sfounder, ssuccessor, slevels, sbi;