Last active
August 27, 2020 15:42
-
-
Save vinniefalco/0a23d999ae06ea18e70d0bbd9cdbf1ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Construct the builder using a local buffer | |
char temp[4096]; | |
value_builder vb( storage_ptr(), temp, sizeof(temp) ); | |
// Create a monotonic resource with a local initial buffer | |
char buf[4096]; | |
monotonic_resource mr( buf, sizeof(buf) ); | |
// The builder will create a value using `mr` | |
vb.reset(&mr); | |
// Iteratively create the elements | |
vb.begin_object(); | |
vb.insert_key("a"); | |
vb.insert_int64(1); | |
vb.insert_key("b"); | |
vb.insert_null(); | |
vb.insert_key("c"); | |
vb.insert_string("hello"); | |
vb.end_object(); | |
// Take ownership of the value | |
value jv = vb.release(); | |
assert( to_string(jv) == "{\"a\":1,\"b\":null,\"c\":\"hello\"}" ); | |
// At this point we could re-use the builder by calling reset |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment