diff --git a/include/weaseljson.h b/include/weaseljson.h index 4e01ec7..ce2384b 100644 --- a/include/weaseljson.h +++ b/include/weaseljson.h @@ -9,11 +9,15 @@ struct WeaselJsonCallbacks { void (*on_begin_object)(void *data); void (*on_end_object)(void *data); void (*on_begin_string)(void *data); + /** May be called multiple times per string if not all string data is + * available yet. The string data provided is unescaped. */ void (*on_string_data)(void *data, const char *buf, int len); void (*on_end_string)(void *data); void (*on_begin_array)(void *data); void (*on_end_array)(void *data); void (*on_begin_number)(void *data); + /** May be called multiple times per number if not all number data is + * available yet */ void (*on_number_data)(void *data, const char *buf, int len); void (*on_end_number)(void *data); void (*on_true_literal)(void *data); @@ -25,7 +29,7 @@ enum WeaselJsonStatus { /** Accept input */ WeaselJson_OK, /** Consumed all available input. Call WeaselJsonParser_parse with more data - to provide more input, or call with length 0 to indicate end of data*/ + to provide more input, or call with length 0 to indicate end of data */ WeaselJson_AGAIN, /** Invalid json */ WeaselJson_REJECT, @@ -35,9 +39,12 @@ enum WeaselJsonStatus { typedef struct WeaselJsonParser WeaselJsonParser; -/** Increasing stack size increases memory usage but also increases the depth of - * nested json accepted. */ -WeaselJsonParser *WeaselJsonParser_create(int stackSize); +/** Create a parser. Increasing stack size increases memory usage but also + * increases the depth of nested json accepted. `callbacks` and `data` must + * outlive the returned parser. */ +WeaselJsonParser *WeaselJsonParser_create(int stackSize, + const WeaselJsonCallbacks *callbacks, + void *data); /** Restore the parser to its newly-created state */ void WeaselJsonParser_reset(WeaselJsonParser *parser);