hello,
i want to send/receive packet using eNet and boost.serialization
i'm using enetpp wrapper for eNet and i'm using boost.serialization to serialize the struct
first, this is the first time that i'm working with boost.serialization
but my serialization code is as follows:
//the structure that represents the game data to be sent
typedef struct gamedata
{
const char *username;
const char *password;
int rank;
bool userpass_incorrect;
bool account_not_exist;
const char *mac_address;
const char *hdd_serial;
const char *ip_address;
int x;
int y;
int z;
int health;
bool is_banned;
bool notify;
const char *pm_user;
const char *chat_user;
const char *message;
const char *server_message;
const char *motd;
bool came_online;
bool went_offline;
private:
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar&username;
ar&password;
ar&userpass_incorrect;
ar&account_not_exist;
ar&mac_address;
ar&hdd_serial;
ar&ip_address;
ar&x;
ar&y;
ar&z;
ar&health;
ar&is_banned;
ar¬ify;
ar&pm_user;
ar&chat_user;
ar&message;
ar&server_message;
ar&motd;
ar&came_online;
ar&went_offline;
}
}gamedata;
here is another serialize function that i've wrote in order to make it work but it didn't work:
//serialization/deserialization ruteens
template <class Archive>
void serialize(Archive& ar, gamedata *g, const unsigned int version)
{
ar&g->username;
ar&g->password;
ar&g->rank;
ar&g->userpass_incorrect;
ar&g->account_not_exist;
ar&g->mac_address;
ar&g->hdd_serial;
ar&g->ip_address;
ar&g->x;
ar&g->y;
ar&g->z;
ar&g->health;
ar&g->is_banned;
ar&g->notify;
ar&g->pm_user;
ar&g->chat_user;
ar&g->message;
ar&g->server_message;
ar&g->motd;
ar&g->came_online;
ar&g->went_offline;
}
and, this is the overload of operator <<:
//<<operator for our gamedata struct
ostream& operator << (ostream& os, gamedata *g)
{
os<<g->username;
os<<g->password;
os<<g->rank;
os<<g->userpass_incorrect;
os<<g->account_not_exist;
os<<g->mac_address;
os<<g->hdd_serial;
os<<g->ip_address;
os<<g->x;
os<<g->y;
os<<g->z;
os<<g->health;
os<<g->is_banned;
os<<g->notify;
os<<g->pm_user;
os<<g->chat_user;
os<<g->message;
os<<g->server_message;
os<<g->motd;
os<<g->came_online;
os<<g->went_offline;
}
and, i want to load it into stringstream:
(data is the packet data, cl.gd is a pointer to my gamedata struct)
stringstream ss((char *)data);
text_iarchive ia(ss);
ia>>cl.gd;
and this is the code to save it into ostringstream for sending:
ostringstream s;
text_oarchive oa(s);
oa<<cl.gd;
and, these are 2 errors that i've got:
In file included from C:/Dev-Cpp/i686-w64-mingw32/include/boost/serialization/extended_type_info_typeid.hpp:37:0,
from C:/Dev-Cpp/i686-w64-mingw32/include/boost/archive/detail/oserializer.hpp:38,
from C:/Dev-Cpp/i686-w64-mingw32/include/boost/archive/detail/interface_oarchive.hpp:23,
from C:/Dev-Cpp/i686-w64-mingw32/include/boost/archive/detail/common_oarchive.hpp:22,
from C:/Dev-Cpp/i686-w64-mingw32/include/boost/archive/basic_text_oarchive.hpp:29,
from C:/Dev-Cpp/i686-w64-mingw32/include/boost/archive/text_oarchive.hpp:31,
from F:\projects\cpp\missiontime-server\src\main.cpp:7:
C:/Dev-Cpp/i686-w64-mingw32/include/boost/serialization/access.hpp: In instantiation of 'static void boost::serialization::access::serialize(Archive&,
T&, unsigned int) [with Archive = boost::archive::text_iarchive; T = char]':
C:/Dev-Cpp/i686-w64-mingw32/include/boost/serialization/serialization.hpp:68:22: required from 'void boost::serialization::serialize(Archive&, T&, unsigned
int) [with Archive = boost::archive::text_iarchive; T = char]'
C:/Dev-Cpp/i686-w64-mingw32/include/boost/serialization/serialization.hpp:126:14: required from 'void boost::serialization::serialize_adl(Archive&, T&,
unsigned int) [with Archive = boost::archive::text_iarchive; T = char]'
C:/Dev-Cpp/i686-w64-mingw32/include/boost/archive/detail/iserializer.hpp:189:40: required from 'void boost::archive::detail::iserializer<Archive, T>::load_object_data(boost::archive::detail::basic_iarchive&,
void*, unsigned int) const [with Archive = boost::archive::text_iarchive; T = char]'
F:\projects\cpp\missiontime-server\src\main.cpp:335:1: required from here
C:/Dev-Cpp/i686-w64-mingw32/include/boost/serialization/access.hpp:116:9: error: request for member 'serialize' in 't', which is of non-class type 'char'
t.serialize(ar, file_version);
^
C:/Dev-Cpp/i686-w64-mingw32/include/boost/serialization/access.hpp: In instantiation of 'static void boost::serialization::access::serialize(Archive&,
T&, unsigned int) [with Archive = boost::archive::text_oarchive; T = char]':
C:/Dev-Cpp/i686-w64-mingw32/include/boost/serialization/serialization.hpp:68:22: required from 'void boost::serialization::serialize(Archive&, T&, unsigned
int) [with Archive = boost::archive::text_oarchive; T = char]'
C:/Dev-Cpp/i686-w64-mingw32/include/boost/serialization/serialization.hpp:126:14: required from 'void boost::serialization::serialize_adl(Archive&, T&,
unsigned int) [with Archive = boost::archive::text_oarchive; T = char]'
C:/Dev-Cpp/i686-w64-mingw32/include/boost/archive/detail/oserializer.hpp:148:40: required from 'void boost::archive::detail::oserializer<Archive, T>::save_object_data(boost::archive::detail::basic_oarchive&,
const void*) const [with Archive = boost::archive::text_oarchive; T = char]'
F:\projects\cpp\missiontime-server\src\main.cpp:335:1: required from here
C:/Dev-Cpp/i686-w64-mingw32/include/boost/serialization/access.hpp:116:9: error: request for member 'serialize' in 't', which is of non-class type 'char'
now:
compiler: gcc (mingw-w64) 5.3.0 with gnu++14 enabled
boost: 1.60.0
thanks in advance