Skip to content

encode: add function to completely reset generator state #76

wants to merge 1 commit into from

2 participants

rotty commented Mar 22, 2012

AFAICS, with the current codebase, a new generator instance has to be created for each JSON value.
I'm implementing a protocol based on the exchange of JSON objects. For this use-case it is convenient and also more efficient to re-use the existing generator instance for the entire communication instead of re-allocating a new generator instance for each object/message. I hence implemented a new function to reset the generator state, tentatively named yajl_gen_reset().

From the source code comment added for that function:

/** completely reset the generator state. Using this function
 * allows for a single generator instance to be used to generate a
 * series of JSON values.  This the counterpart to the
 * yajl_allow_multiple_values parser option. */
lloyd commented Mar 19, 2014

thanks for the contribution! Sorry it's taken me so long :blush: - but now committed to master is basically this change. The only difference is that calling this will not clear the output buffer. Rationale is that the client may wish to generate multiple entities and to use the output buffer to stream all output. conflating a call to reset and a call to clear is less flexible than making them separate.

Thanks again for the contribution!

@lloyd lloyd closed this Mar 19, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.