json_stream: disentangle JSON handling from command.

We promote 'struct json_stream' to contain the membuf; we only attach
the json_stream to the command when we actually call
json_stream_success / json_stream_fail.

This means we are closer to 'struct json_stream' being an independent
layer; the tests are already modified to use it directly to create
JSON.

This is also the first step toward re-enabling non-serial command
execution.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2018-11-20 12:16:32 +10:30
committed by Christian Decker
parent db3f0ba965
commit e17f69ce2d
12 changed files with 499 additions and 356 deletions

View File

@@ -159,17 +159,6 @@ bool json_tok_tok(struct command *cmd, const char *name,
const jsmntok_t **out);
/* Creating JSON output */
/* '"fieldname" : [ ' or '[ ' if fieldname is NULL */
void json_array_start(struct json_stream *ptr, const char *fieldname);
/* '"fieldname" : { ' or '{ ' if fieldname is NULL */
void json_object_start(struct json_stream *ptr, const char *fieldname);
/* ' ], ' */
void json_array_end(struct json_stream *ptr);
/* ' }, ' */
void json_object_end(struct json_stream *ptr);
/**
* json_stream_success - start streaming a successful json result.
* @cmd: the command we're running.