From b45a3266352be0da51c532c8dc462e67e5830877 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 14 Sep 2020 15:00:55 +0930 Subject: [PATCH] json_out: make json_out_finished finish buffer. For JSON RPC, we can actually write multiple JSON objects back to back, and we don't want a comma between them. Signed-off-by: Rusty Russell --- ccan/json_out/json_out.c | 3 ++- ccan/json_out/json_out.h | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ccan/json_out/json_out.c b/ccan/json_out/json_out.c index 87deaca8..53837e67 100644 --- a/ccan/json_out/json_out.c +++ b/ccan/json_out/json_out.c @@ -337,11 +337,12 @@ char *json_out_direct(struct json_out *jout, size_t len) return p; } -void json_out_finished(const struct json_out *jout) +void json_out_finished(struct json_out *jout) { #ifdef CCAN_JSON_OUT_DEBUG assert(tal_count(jout->wrapping) == 0); #endif + jout->empty = true; } const char *json_out_contents(const struct json_out *jout, size_t *len) diff --git a/ccan/json_out/json_out.h b/ccan/json_out/json_out.h index 2911ff24..da8b4ffa 100644 --- a/ccan/json_out/json_out.h +++ b/ccan/json_out/json_out.h @@ -177,9 +177,12 @@ bool json_out_add_splice(struct json_out *jout, * @jout: the json_out object written to. * * This simply causes internal assertions that all arrays and objects are - * finished. It needs CCAN_JSON_OUT_DEBUG defined to have any effect. + * finished. If CCAN_JSON_OUT_DEBUG is defined, it does sanity checks. + * + * This also resets the empty flag, so there will be no comma added if + * another JSON object is written. */ -void json_out_finished(const struct json_out *jout); +void json_out_finished(struct json_out *jout); /** * json_out_contents - read contents from json_out stream. -- 2.39.2