4

I have read through Beej's guide, as well as many other resources I've been able to find on the internet, but I feel like I'm missing something in terms of serialization and de-serialization. I can sort of hash it out by hard-coding in a definite structure for the server and client to send/receive, but I wonder if there are any resources that I could look at which might help me to serialize more efficiently or generally, something that would help me to possibly re-use some of my serialization code in other programs instead of having to write custom-made serialization functions for every data structure that I want to pass around?

ciphermagi
  • 747
  • 3
  • 14
  • 2
    *The Practice of Programming* has a nice, general purpose binary serialization function for C. That's a paper book, but the code may be floating around the web. – Fred Foo Mar 03 '14 at 08:28
  • The book is not expensive, so I will order it and read it. I will also look in to this Google Protobuf. Thanks for the pointers (snicker). ;) – ciphermagi Mar 03 '14 at 09:20
  • I made some good experience with [nanopb](http://koti.kapsi.fi/jpa/nanopb/) for using protobuf in C-code. We're using this in production. – πάντα ῥεῖ Mar 23 '14 at 12:52
  • Check the [Binn](https://github.com/liteserver/binn) format. It's the easier to use in C from those I've tested. – Bernardo Ramos Nov 13 '15 at 04:15

1 Answers1

1

Google Protobuf might be useful to you, specially if you might want to consider a cross platform application implemented in multiple programming languages.

Protobuf has the serialization implemented already, so you would have that going for you.

As the above link is for c++, this is the c pendant. But there are also implementations for many other languages, like Python, PHP, Java and many other! Another C Protobuf library is nanoPB, thanks to πάντα ῥεῖ for pointing this out. It seems that this one is stable.

Another way would be to use another serialisation library to serialize and deserialize your data.

The last possible way would be to implement the serialosation by yourself, like it is described on this SO question.

Community
  • 1
  • 1
Theolodis
  • 4,977
  • 3
  • 34
  • 53
  • After looking into this, the language is very specifically for C++, and completely off-topic. – ciphermagi Mar 14 '14 at 22:20
  • @ciphermagi that's surprising, because when you google "protobuf for c" the first link is: code.google.com/p/protobuf-c/ Hope that helps you. – Theolodis Mar 15 '14 at 07:06
  • 1
    You mean that project that says specifically on the page that it's not stable, not compatible with most of Protobuf, and has no extensions, and in fact in most part doesn't even implement the processes that protobuf is designed for? – ciphermagi Mar 17 '14 at 01:26
  • @ciphermagi I do not see where you took your information. Let me cite: Status: ***Most*** of the code ***is stable***, Groups are not implemented - they probably never will be (***since they are deprecated***. So from what I can say this is totally usable. Concerning the extensions, if you would really need them, you can implement them by yourself as the code is open source. – Theolodis Mar 17 '14 at 11:06
  • 1
    I made some good experience with [nanopb](http://koti.kapsi.fi/jpa/nanopb/) for using protobuf in C-code. We're using this in production. – πάντα ῥεῖ Mar 23 '14 at 12:51