Skip to content

Commit

Permalink
refact(archive): expect correct mode for <</>> operators
Browse files Browse the repository at this point in the history
  • Loading branch information
Insineer committed Oct 8, 2019
1 parent cfd4950 commit 6fa30d9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 7 additions & 5 deletions SharedLibrary/Sources/Shared/Network/Archive.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ class Archive : public ICopyable {
template<class T>
Archive &operator&(T &ser) {
if constexpr (std::is_base_of_v<ISerializable, T>) {
sf::Int32 id; *this >> id; // we know type, so drop excess id
if (mode == Mode::Output) {
sf::Int32 id; *this >> id; // we know type, so drop excess id
}
reinterpret_cast<uf::ISerializable&>(ser).Serialize(*this);
} else {
serializeSimple(ser);
Expand All @@ -41,14 +43,14 @@ class Archive : public ICopyable {

template<class T>
Archive &operator>>(T &ser) {
if (mode == Mode::Output) *this & ser;
return *this;
EXPECT(mode == Mode::Output);
return *this & ser;
}

template<class T>
Archive &operator<<(const T &ser) {
if (mode == Mode::Input) *this & const_cast<T&>(ser);
return *this;
EXPECT(mode == Mode::Input);
return *this & const_cast<T&>(ser);
}

protected:
Expand Down
3 changes: 2 additions & 1 deletion SharedLibrary/Sources/Shared/Network/ISerializable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ using namespace network::protocol;
namespace uf {

void ISerializable::Serialize(Archive &archive) {
archive << sf::Int32(SerID());
if (archive.GetMode() == Archive::Mode::Input)
archive << sf::Int32(SerID());
}

#define DECLARE_SER(name) \
Expand Down

0 comments on commit 6fa30d9

Please sign in to comment.