Samuele Calugi
Samuele Calugi

Reputation: 29

How to serialize data in C to send in a socket

I have to serialize some data and after send it using socket AF_UNIX. I have read (here) that I can't create a struct and just send it using a cast (void *). So, I would like to know which is the best method to handle this problem. Thank you!

Upvotes: 0

Views: 753

Answers (1)

Jon Reeves
Jon Reeves

Reputation: 2586

You basically have two options:

  1. Roll your own exactly as in the question you referenced.
  2. Use an off-the-shelf serialization/deserialization system. If you go this route, Google's Protocol Buffers are pretty much industry standard. For constrained projects (embedded, etc.) nanopb is a good choice for the implementation.

Upvotes: 1

Related Questions