Hi,

I have a struct that looks like this

struct Info
{
  char **field_names;
  double **data;
  int *cindex;
}

I have to serialize an object of this struct and send it over a socket and deserialize at the other end. What is the best option for this?

That has two two-dimensional arrays of unknown sizes, and a one-dimensional array of unknown size. How does the program that uses that structure know their dimensions? Without knowing the dimensions it will be impossible to serialize it anywhere, much less actually use it for anything.

I define them dynamically inside the program before I have to send

Each of those arrays have to be serialized individually as if they were not part of a structure. Serializing just the structure is useless. You need to preceed each string with its length so that the receiving computer program knows how much data to expect and how to reconstruct the arrays and structure.

Serializing to a serial port is exactly identical to writing it to a text file. I'd serialize it to a text file first to get the algorithms down then change the stream to a serial port.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.