You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a C++ application with JSON web API (cpp-httplib and nlohmann/json libraries) where I need to send each second approximately 8 KB long array of data. My idea is to encode the array of bytes with base64 encoding and then put it to the JSON data as a normal string.
Since the application is running on a resource constrained embedded computer, I am thinking about efficiency - mainly, I would like to prevent the application from useless buffer copying. I have two questions:
The cpp-httplib offers DataSink object, which has a very similar API to the output adapters used in the JSON library. If I understand it correctly, it should be possible to create my own output adapter and then serialize JSON data directly to the DataSink instead of using a temporary string variable. I tried to implement my own adapter by inheriting the output_adapter_protocol struct, but I cannot figure out how to use it. Are there any examples?
I would like to create a custom serializer for my array of bytes. Of course, I could convert the array to string first and then use the standard serializer, but I think the most elegant solution would be to make the conversion directly. I found some information about custom serializers, but it seems they all convert custom data types to JSON string objects, which adds the unwanted extra step during the conversion. Any ideas?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello guys,
I have a C++ application with JSON web API (cpp-httplib and nlohmann/json libraries) where I need to send each second approximately 8 KB long array of data. My idea is to encode the array of bytes with base64 encoding and then put it to the JSON data as a normal string.
Since the application is running on a resource constrained embedded computer, I am thinking about efficiency - mainly, I would like to prevent the application from useless buffer copying. I have two questions:
The cpp-httplib offers
DataSink
object, which has a very similar API to the output adapters used in the JSON library. If I understand it correctly, it should be possible to create my own output adapter and then serialize JSON data directly to theDataSink
instead of using a temporary string variable. I tried to implement my own adapter by inheriting theoutput_adapter_protocol
struct, but I cannot figure out how to use it. Are there any examples?I would like to create a custom serializer for my array of bytes. Of course, I could convert the array to string first and then use the standard serializer, but I think the most elegant solution would be to make the conversion directly. I found some information about custom serializers, but it seems they all convert custom data types to JSON string objects, which adds the unwanted extra step during the conversion. Any ideas?
Thank you in Advance!
Klasyc
Beta Was this translation helpful? Give feedback.
All reactions