C++ event driven json stream reader - c++

I just discovered YAJL project which just does what I need.
Read from stream
Callback on each valid parsed token
Reparse incomplete json when new data arrived
But I prefer C++. Of course I can use this library from C++ project and even write my own wrapper if I really want to but anyway native C++ is preferable.
I looked at JsonCPP but looks like it can't read incomplete json data from stream.
Is there any other C++ libraries for parsing json streams?
Some more requirements:
lightweight. boost or Qt are not suitable
I need something what I may freely use in commercial closed source software (mit, public domain, etc).
Support for not blocking read. or allow to feed data (append_incoming_data).

Recently I search library with similar requirements,
and actually found only 1.5 libraries that support such requirements:
https://github.com/kazuho/picojson
one header library, BSD licence, and have interface like this:
Iter parse(value& out, const Iter& first, const Iter& last, std::string* err);
so you can create append_incoming_data with a couple of lines of code.
https://github.com/dropbox/json11
one file library, licence similar to BSD, c++11 support, but interface
that allow parse partly arrived from network json it require patch:
https://github.com/dropbox/json11/pull/55
P.S.
lightweight. boost or Qt are not suitable
Actually, they are not suitable because of
allow to feed data
At now both Qt5 json and boost property_tree can not parse
half ready json.

Other options are
sjparser - the parsing is based on schema specified
JsonReader - plain event based parser

Related

C++ JSON Serialization, Proto-buf style

I want to serialize several C++ objects into JSON, and deserialize them back. Obviously since C++ is lacking reflection, this can't be done automatically. I will need to somehow tell the serializer which data member goes into which JSON property.
I can do that with C++, but I'd rather use something like Protobuf's message to specify the mapping. Out of the many many JSON C++ libraries out there, is there one that support some sort of metadata that allows me to map the serialization process without implementing it myself?
You can simply use the JSON cpp or C files and use them as API. That is what I have done for my previous project. C++ does not come with inbuilt JSON support like JAVA.
So include the files and use the JSON function as APIs. You can build it separately and link it statically to your program. Go to the JSON home page for language wise files:
http://json.org/
For CPP files:
http://sourceforge.net/projects/jsoncpp/
i think its moved to git repo. The link is present there.
Hope this helps.
The ASN.1 tools from OSS Nokalva support JSON encoding rules for ASN.1 schemae.
You write an ASN.1 schema (protobufs schema are similar but inferior), compile it to whatever language you want (C++ in your case), and you get the bunch of classes that can serialise to/from JSON.
Not free I'm afraid.
ASN.1 is great - there's all sorts of encoding rules to suit all occasions.

Serialize/ Deserialize C++ classes

I'm looking for a way to send C++ class between 2 clients aptication.
I was looking for a way doing so and all i can find is that I need to create for each Class Serialize/ Deserialize (to JSON for example) functions and send it over TCP/IP.
The main problem I'm faceing is that I have ~600 classes (some are classes including instances of others) that I need to pass which mean I need to spent the next writing Serialize/ Deserialize functions.
Is there any generic way writing Serialize/Deserialize functions ?
Is there any other way sending C++ classes ?
Thanks,
Guy Ergas.
Are you using a Framework at all? Qt and MFC for example have built in Serialization that would make your task easier. Otherwise I would guess that you'd need to spend at least some effort on each of the 600 classes.
As recommended above Boost Serialization is probably a good way to go, you can send the serialized class over Tcp using Boost Asio too:
http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio.html
Alternatively, there is a C++ API for Google Protocol Buffers (protobuf):
https://developers.google.com/protocol-buffers/docs/reference/cpp/
Boost Serialization
Although I haven't used it my self, it is very popular around my peers at work.
More info about it can be found in "Boost (1.54.00) Serialization"
Thrift
Thrift have a very limited serialize functionality which I don't think fits your requirements. But it can help you "move" the data from one client to anther even if they are using different languages.
More info about it can be found in "Thrift: The Missing Guide"
try s11n or nosjob
s11n (an abbreviation for serialization) is an Open Source project
focused on the generic serialization of objects (i.e., object
persistence) in the C++ programming language.
nosjob, a C++ library for generating and consuming JSON data.
You may be interested in ASN.1. It's not necessarily the easiest to use and tools/libraries are a little hard to come by (Objective Systems at http://www.obj-sys.com/index.php is worth a look, though not free).
However the big advantage is that it is very heavily standardised (so no trouble with library version incompatibilities) and most languages are supported one way or another. Handy if you need support across multiple platforms. It also does binary encodings, so its way less bloaty than XML (which it also supports). I chose it for these reasons and didn't regret it.
If you are at linux platform , You can directly use json.h library for serialization.
Here is sample code i have come across :)
Json Serializer

C/C++ FLAC tagging library

Is there any C/C++ FLAC tagging library that work on streams? Wherever I look I only find ones that work on files. It's kinda weird to me - why use something limited like file instead of more abstract stream. Well, maybe I'm just spoiled by managed languages neatness (I'm more of a Java guy, but this time I need unmanaged code solution).
I'm not familiar with any FLAC libraries, but the reference FLAC library supports an interface for custom I/O. This allows you to write a small stub that will convert I/O calls to a custom data source, which needn't be a file.
It seems to require capacity to seek, though. If that is the case, then you might not be able to wrap a socket without a high-level protocol that allows you to seek.

Light weight C++ SAX XML parser

I know of at least three light weight C++ XML parsers: RapidXML, TinyXML and PugiXML. However, all three use a DOM based interface (ie, they build their own in-memory representation of the XML document and then provide an interface to traverse and manipulate it). For most situations that I have to deal with, I much prefer the SAX interface (where the parser just spits out a stream of events like start-of-tag, and the application code is responsible for doing whatever it wants based on those events).
Can anyone recommend a light weight C++ XML library with a SAX interface?
Edit: I should also note the Microsoft XmlLite library, which does use a SAX interface (well, actually a "pull" interface which is possibly even better). Unfortunately, it's ruled out for me at the moment since as far as I know it's closed source and Windows only (please correct me if I'm wrong on this).
I've used expat when I needed to parse XML. It's very light-weight (well, it used to be; it's a while since I've done XML stuff) and does the job.
you can try https://github.com/thinlizzy/die-xml . it seems to be very small and easy to use
this is a recently made C++0x XML SAX parser open source and the author is willing feedbacks
it parses an input stream and generates events on callbacks compatible to std::function
the stack machine uses finite automata as a backend and some events (start tag and text nodes) use iterators in order to minimize buffering, making it pretty lightweight
PugiXML and RapidXML do not have DOM conforming interfaces.. those API came with severe limitations on functionalities and conformance. You might want to investigate VTD-XML that is signifiantly more advanced than either DOM or SAX/Pull

apple's property list (plist) implementation in c++

I'm tasked with reading Apple's property list files within a c++ application. Focusing primarily on the xml-type plist files specified in OS X, which mimic a xml-type implementation.. Apple's implementation of their property list is described here:
http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man5/plist.5.html
I'm wondering if there are classes or libraries available that already can read this type of implementation within standard c++ (not Objective-C); hoping to find something rather than rolling our own. Are there any open-source implementations of this available?
PList files are not only mimicing XML, they are XML, including valid XML headers.
Any XML reader should be able to parse these files as a result. If you're looking for a logical class that abstracts the files, I'm not aware of any existing ones. Given Apple's documentation, you should be able to write one yourself with an XML reader, although it would take some work for full compatibility.
For topic starter it is too late, I know, but maybe it helps somebody
https://github.com/animetrics/PlistCpp
This is a C++ Property List (plist) serialization library (MIT license).
It supports both XML and binary versions of the plist format and is designed to
be cross platform with minimal dependencies.
Is that target-specific?
For Windows, there is a crude solution which consists of using the functions of iTunes dynamic libraries to parse plist files (either binary or plain text format work).
That's a code originally written to interface an iPod, but you can easily extract the few functions you are interested in.
The repository is on this project page: http://code.google.com/p/t-pot/
Look for the file iPoTApi.h and iPoTApi.cpp, the function TranslatePLIST of the class CiPoTApi.
I wish there were a better solution, at the time I tried to compile it from Apple's sources targeted at Windows but it is a real nightmare, and files are missing. So using their libraries was a considerable shortcut.