happyponyland.net / C serialization library

Introduction

This is a library for serializing structures in C. It will convert a memory range (usually a struct or array) to a human-readable representation. It can later parse the serialized data to recreate the original structure in memory.

It works by substituting pointers for hardware-independent identifiers, essentially collapsing a complex structure to a flat list. Several pointers can address the same memory without creating duplicates in the serialized data. Structures can point at each other or at themselves; for this reason the library is well suited for linked lists, trees and even cyclic graphs.

It can also work with arrays (fixed size, dynamic and/or null-terminated) and provides a shortcut notation ("syntactic sugar") for strings. See the readme and function reference for more information.

The library is provided under the zlib license (i.e. with very few restrictions).

Note: This is a work in progress. It is mostly stable but not "production quality". There are still a couple of bugs and a few loose ends and the API is likely to change a bit. Please send me bug reports! I'm most interested to hear about platforms other than 64-bit Linux + GCC.

Download

Source for version 0.4 (released 2012-01-13)

FAQ

Q: Why did you write this?
A: I like the power and simplicity of C, but there are also aspects of low-level drudgery I don't enjoy; file I/O can be one of them. I had implemented something very similar for saving/loading in another project and wanted to rewrite it for general purpose use. It was mostly a learning experience, but I've been using it since for a number of different projects.

Q: Why not just use JSON?
A: Please see this section in the readme.