iodcpp / metajson Goto Github PK
View Code? Open in Web Editor NEWNon-intrusive, high performance C++17 lightweight JSON de/serializer
Non-intrusive, high performance C++17 lightweight JSON de/serializer
Now:
std::string HostHandler::sessionEncode(const std::map<std::string, Variant> &session) {
using iod::json_encode;
std::vector<std::pair<std::string, Variant>> test;
for (const auto &it : session)
test.emplace_back(it.first, it.second);
return json_vector(s::_first, s::_second).encode(test);
}
See if a implementation of miloyip's benchmark is possible for metajson.
Is it feasible to decode json strings as std::string_view instead of std::string? It can save memory allocation from heap + memcpy on every string if you'd manage to just wrap characters in input buffer into std::string_view.
/mnt/json/metajson/build> cmake ..
/mnt/json/metajson/build> make
[10%] Building CXX object CMakeFiles/json_unicode.dir/tests/unicode.cc.o
/mnt/json/metajson/tests/unicode.cc:6:35: fatal error: iod/metajson/unicode.hh: No such file or directory
compilation terminated.
CMakeFiles/json_unicode.dir/build.make:62: recipe for target 'CMakeFiles/json_unicode.dir/tests/unicode.cc.o' failed
make[2]: *** [CMakeFiles/json_unicode.dir/tests/unicode.cc.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/json_unicode.dir/all' failed
make[1]: *** [CMakeFiles/json_unicode.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
To be fair: nlohmann/json has 14478 LOC, but only 2867 "relevant" (i.e., no whitespace or comments), see https://coveralls.io/builds/11822477.
everything works nicely without -O3 but once -O3 enabled it just hangs. would be great if you could check it out.
#include <iod/metajson/metajson.hh>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <cstdio>
namespace s
{
IOD_SYMBOL(e)
IOD_SYMBOL(E)
IOD_SYMBOL(s)
IOD_SYMBOL(U)
IOD_SYMBOL(u)
IOD_SYMBOL(b)
IOD_SYMBOL(a)
}
using bina_side = std::vector<std::tuple<std::string, std::string, std::vector<int>>>;
struct bina_depth
{
std::string e;
uint64_t E;
std::string s;
uint32_t U;
uint32_t u;
bina_side b;
bina_side a;
};
using iod_json_side = iod::json_vector_<iod::json_tuple_<std::string, std::string, iod::json_vector_<int>>>;
int main(int argc, char **argv)
{
[[maybe_unused]] const std::string input = R"json({"e":"depthUpdate","E":1530337676555,"s":"KEYBTC","U":1851892,"u":1851927,"b":[["0.00000375","970825.00000000",[]],["0.00000374","1314068.00000000",[]],["0.00000373","698996.00000000",[]],["0.00000370","801472.00000000",[]],["0.00000368","742657.00000000",[]],["0.00000367","557610.00000000",[]],["0.00000364","303787.00000000",[]],["0.00000363","144797.00000000",[]],["0.00000362","473956.00000000",[]],["0.00000358","207030.00000000",[]],["0.00000353","142593.00000000",[]],["0.00000344","579446.00000000",[]],["0.00000334","301832.00000000",[]]],"a":[["0.00000375","0.00000000",[]],["0.00000379","176609.00000000",[]],["0.00000381","368148.00000000",[]],["0.00000383","108264.00000000",[]],["0.00000384","156233.00000000",[]],["0.00000385","213546.00000000",[]],["0.00000387","296058.00000000",[]],["0.00000392","506788.00000000",[]],["0.00000393","196718.00000000",[]]]})json";
[[maybe_unused]] const std::string input2 = R"json({"e":"depthUpdate","E":1530337676555,"s":"KEYBTC","U":1851892,"u":1851927,"b":[["0.00000375","970825.00000000",[]],["0.00000374","1314068.00000000",[]]]})json";
bina_depth depth;
auto err = iod::json_object(s::_e, s::_E, s::_s, s::_U, s::_u, s::_b = iod::json_vector_<iod::json_tuple_<std::string, std::string, iod::json_vector_<int>>> {}, s::_a = iod::json_vector_<iod::json_tuple_<std::string, std::string, iod::json_vector_<int>>> {}).decode(input, depth);
assert(!err);
for (const auto &price : depth.b)
{
fprintf(stderr, "[%s] [%s]\n", std::get<0>(price).c_str(), std::get<1>(price).c_str());
}
return EXIT_SUCCESS;
}
/usr/bin/c++ -Wall -g -std=c++17 -O3 CMakeFiles/binance-json-test.dir/binance_json_test.cc.o -o binance-json-test
[denis@mjr poc]$ valgrind ./binance-json-test
==13002== Memcheck, a memory error detector
==13002== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==13002== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==13002== Command: ./binance-json-test
==13002==
^C==13002==
==13002== Process terminating with default action of signal 2 (SIGINT)
==13002== at 0x10AC10: _ZZN3iod4impl12json_decode2INS0_11json_parserINS_19decode_stringstreamEEEJNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESA_St6vectorIiSaIiEEEJSA_SA_NS_12json_vector_IiEEEEENS_15json_error_codeERT_RSt5tupleIJDpT0_EENS_11json_tuple_IJDpT1_EEEENKUlSI_T0_E_clISA_SA_EEDaSI_SS_.part.157 (metajson.hh:848)
==13002== by 0x110A7F: operator()<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> > (new_allocator.h:86)
==13002== by 0x110A7F: json_decode_tuple_elements<iod::impl::json_decode2(P&, std::tuple<_Elements ...>&, iod::json_tuple_<S ...>) [with P = iod::impl::json_parser<iod::decode_stringstream>; O = {std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<int, std::allocator<int> >}; S = {std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, iod::json_vector_<int>}]::<lambda(auto:15&, auto:16)>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, iod::json_vector_<int>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<int, std::allocator<int> >, 0, 1, 2> (metajson.hh:1461)
Hi Matt, I found your nice project and it looks so cool so I would like to try it myself.
But there's no license attached which falls back to all rights reserved.
So I was wondering if you could kindly add a license for people to play with it?
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.