Compress with quickjson

I am using socket.io-clientpp, https://github.com/ebshimizu/socket.io-clientpp , which uses quickjson.

When an event is received, my function is called:

void data_published(socketio::socketio_events&, const Value& v) { 

Value is the quickjson value. My problem is that the only way I build it is with the Document class. But to put a value in a document, all functions accept a non-constant reference, for example:

 GenericValue& AddMember(const Ch* name, GenericValue& value, Allocator& allocator) { 

I'm used to jsonpp, I'm missing out on something stupid, I think. The question is simple: how to align const rapidjson value?

+4
source share
1 answer

I am the author of rapidjson. Thank you for your question. I wrote this down for publication at http://code.google.com/p/rapidjson/issues/detail?id=45

This is because GenericValue :: Accept () is not a constant.

As GenericValue :: Accept () only generates events for the handler, it does not need to change the value and its decents. Therefore, it should change:

 template <typename Handler> GenericValue& Accept(Handler& handler) 

to

 template <typename Handler> const GenericValue& Accept(Handler& handler) const 

You can fix this on your quickjson / document.h or download the latest version (trunk or branch 0.1x).

After this change, you can stringfy the value of const as in the tutorial:

 const Value& v = ...; FileStream f(stdout); PrettyWriter<FileStream> writer(f); v.Accept(writer); 

Or to the string buffer:

 const Value& v = ...; StringBuffer buffer; PrettyWriter<StringBuffer> writer(buffer); v.Accept(writer); const char* json = buffer.GetString(); 
+13
source

Source: https://habr.com/ru/post/1443703/


All Articles