I want to capture an application traffic and save that to a file so I can then load it on another programs.

I need a library that can do partial serialization (don't know the technical name). I mean, I don't want to hold packets on memory until the program closes, I want to write them to disk when they arrive and free memory. Also I want to be able do lazy deserialization latter. I would prefer any with wide language support (or at least Python and c++).

This is at application layer so packets doesn't contain any network data, they are just byte arrays with additional information like timestamps.

I was looking for known libraries and found Google Protobuf but I don't think it's intended for what I want to do. I tried it, but it mantains the data in memory and seems like I have to serialize the entire object at the end. So the program memory usage keeps growing.

Which C++ library is the best for this case?

EDIT: I need to serialize/deserialize something like this (but not necessarily in json, binary data it's ok for me):

     "date": "2018-08-10T17:03:15Z",
     "version": "",
       "buffer": "xxxxxxxx",
       "date": "2018-08-10T17:18:16Z"
       "buffer": "xxxxxxxx",
       "date": "2018-08-10T17:18:16Z"

migrated from stackoverflow.com Aug 10 at 19:09

This question came from our site for professional and enthusiast programmers.

up vote 0 down vote accepted

You can use NDJSON/LDJSON/JSONL format - basically JSON values (without formatting) separated by newlines. You don't need any specific library for this, just basic JSON reader (supplying single lines to it) / writer (appending lines to file).

  • I was looking for a standard so this is what I needed. I also took a look on YAML but seems to be too complex and while it looks powerful, there isn't that much support. Thank you. – Gonzalo Fernandez Oct 14 at 22:30

It seems that you need a kind of json library written in C++. Then, you may take a look at the following link for different json libraries.


Also, I recommend you use the one available at https://github.com/nlohmann/json

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.