title: Serialization/Deserialization of a struct to a char* in C
body: <p>I have a struct</p>
  
  <pre><code>struct Packet {
      int senderId;
      int sequenceNumber;
      char data[MaxDataSize];
  
      char* Serialize() {
          char *message = new char[MaxMailSize];
          message[0] = senderId;
          message[1] = sequenceNumber;
          for (unsigned i=0;i&lt;MaxDataSize;i++)
              message[i+2] = data[i];
          return message;
      }
  
      void Deserialize(char *message) {
          senderId = message[0];
          sequenceNumber = message[1];
          for (unsigned i=0;i&lt;MaxDataSize;i++)
              data[i] = message[i+2];
      }
  
  };
  </code></pre>
  
  <p>I need to convert this to a char* , maximum length MaxMailSize > MaxDataSize for sending over network and then deserialize it at the other end</p>
  
  <p><strong>I can't use tpl or any other library.</strong></p>
  
  <p>Is there any way to make this better I am not that comfortable with this, or is this the best we can do.</p>