mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-24 09:34:24 +01:00
json: Add function to duplicate a json_stream
Will be used in the next commit to fan out notifications to multiple subscribing plugins. We can't just use `tal_dup` from outside since the definition is hidden outside the compilation unit. Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
@@ -59,6 +59,17 @@ struct json_stream *new_json_stream(const tal_t *ctx, struct command *writer)
|
||||
return js;
|
||||
}
|
||||
|
||||
struct json_stream *json_stream_dup(const tal_t *ctx, struct json_stream *original)
|
||||
{
|
||||
size_t num_elems = membuf_num_elems(&original->outbuf);
|
||||
char *elems = membuf_elems(&original->outbuf);
|
||||
struct json_stream *js = tal_dup(ctx, struct json_stream, original);
|
||||
membuf_init(&js->outbuf, tal_dup_arr(js, char, elems, num_elems, 0),
|
||||
num_elems, membuf_tal_realloc);
|
||||
membuf_added(&js->outbuf, num_elems);
|
||||
return js;
|
||||
}
|
||||
|
||||
bool json_stream_still_writing(const struct json_stream *js)
|
||||
{
|
||||
return js->writer != NULL;
|
||||
|
||||
Reference in New Issue
Block a user