0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-18 16:00:57 +01:00
construct/include/ircd/json
2020-12-10 08:34:22 -08:00
..
tuple ircd::json::tuple: Optimize at() runtime reference template approach. 2020-11-18 11:51:43 -08:00
array.h ircd::json: Inline trivial array::empty(); label branch expect. 2020-12-10 08:34:22 -08:00
array_iterator.h ircd::json: Split array::const_iterator from array header; inline comparison suite. 2020-04-03 11:02:49 -07:00
iov.h ircd::json::iov: Fix declarations. 2019-06-21 04:31:38 -07:00
json.h ircd::json: Remerge tool header with index header; use value argument. 2020-10-27 01:17:06 -07:00
member.h ircd::json: Fix member constructor template. 2020-02-10 14:35:17 -08:00
object.h ircd::json: Add integrated type-checking overloads to reduce call count. 2020-11-11 22:49:39 -08:00
object_iterator.h ircd::json: Inline object::const_iterator comparison suite. 2020-04-03 11:02:49 -07:00
object_member.h ircd::json: Inline object::const_iterator comparison suite. 2020-04-03 11:02:49 -07:00
README.md ircd::json: Fix README formatting. 2018-01-22 00:54:52 -08:00
stack.h ircd::json::stack: Simplify checkpoint interface controls. 2020-04-14 15:31:41 -07:00
string.h ircd::json: Optimize poor composition from inlining unquote(). 2020-11-18 11:05:41 -08:00
strung.h ircd::json: Inline strung template ctor. 2020-08-05 02:18:56 -07:00
type.h ircd::json: Add suite for type optimized type query; refactor grammars. 2020-05-24 19:03:00 -07:00
util.h ircd::json: Add stats items counting calls and cycles on input and output. 2020-06-24 11:00:11 -07:00
value.h ircd::json::value: Inline trivial indirections. 2020-08-05 17:27:54 -07:00
vector.h ircd::json: Inline vector::const_iterator related. 2020-05-18 18:12:34 -07:00
vector_iterator.h ircd::json: Inline vector::const_iterator related. 2020-05-18 18:12:34 -07:00

JavaScript Object Notation

formal grammars & tools

The IRCd JSON subsystem is meant to be a fast, safe, and extremely lightweight interface. We have taken a somewhat non-traditional approach and it's important for the developer to understand a few things.

Most JSON interfaces are functions to convert some JSON input to and from text into native-machine state like JSON.parse() for JS, boost::ptree, etc. For a parsing operation, they make a pass recursing over the entire text, allocating native structures, copying data into them, indexing their keys, and perhaps performing native-type conversions and checks to present the user with a final tree of machine-state usable in their language. The original input is then discarded.

Instead, we are interested in having the ability to compute directly over JSON text itself, and perform the allocating, indexing, copying and converting entirely at the time and place of our discretion -- if ever.

The core of this system is a robust and efficient abstract formal grammar built with boost::spirit. The formal grammar provides a proof of robustness: security vulnerabilities are more easily spotted by vetting this grammar rather than laboriously tracing the program flow of an informal handwritten parser.

Next we have taught boost::spirit how to parse into std::string_view rather than std::string. Parsing is now a composition of pointers into the original string of JSON. No dynamic allocation ever takes place. No copying of data ever takes place. IRCd can service an entire request from the original network input with absolutely minimal requisite cost.

The output side is also ambitious but probably a little more friendly to the developer. We leverage boost::spirit here also providing formally proven output safety. In other words, the grammar prevents exploits like injecting and terminating JSON as it composes the output.