Serialize and send a data structure using Boost?

后端 未结 7 1403
半阙折子戏
半阙折子戏 2020-12-02 10:45

I have a data structure that looks like this:

typedef struct
{
  unsigned short m_short1;
  unsigned short m_short2;
  unsigned char m_character;
} MyDataType;
         


        
7条回答
  •  心在旅途
    2020-12-02 11:24

    I thought I'd share this with anyone who was trying to serialize a C++ struct using Boost. For the example given above, to make the struct serializable you would add a serialize function:

    typedef struct
    {
      unsigned short m_short1;
      unsigned short m_short2;
      unsigned char m_character;
    
      template 
      void serialize(Archive& ar, const unsigned int version)
      {
        ar & m_short1;
        ar & m_short2;
        ar & m_character;
      }
    } MyDataType;
    

提交回复
热议问题