mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 07:03:29 +00:00
Add stringify function in cdp
Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
@@ -49,6 +49,18 @@ fn checkKey(key: []const u8, token: []const u8) !void {
|
|||||||
|
|
||||||
const resultNull = "{{\"id\": {d}, \"result\": {{}}}}";
|
const resultNull = "{{\"id\": {d}, \"result\": {{}}}}";
|
||||||
|
|
||||||
|
// caller owns the slice returned
|
||||||
|
pub fn stringify(alloc: std.mem.Allocator, res: anytype) ![]const u8 {
|
||||||
|
var out = std.ArrayList(u8).init(alloc);
|
||||||
|
defer out.deinit();
|
||||||
|
|
||||||
|
try std.json.stringify(res, .{}, out.writer());
|
||||||
|
const ret = try alloc.alloc(u8, out.items.len);
|
||||||
|
@memcpy(ret, out.items);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// caller owns the slice returned
|
||||||
pub fn result(
|
pub fn result(
|
||||||
alloc: std.mem.Allocator,
|
alloc: std.mem.Allocator,
|
||||||
id: u64,
|
id: u64,
|
||||||
@@ -63,13 +75,7 @@ pub fn result(
|
|||||||
};
|
};
|
||||||
const resp = Resp{ .id = id, .result = res };
|
const resp = Resp{ .id = id, .result = res };
|
||||||
|
|
||||||
var out = std.ArrayList(u8).init(alloc);
|
return stringify(alloc, resp);
|
||||||
defer out.deinit();
|
|
||||||
|
|
||||||
try std.json.stringify(resp, .{}, out.writer());
|
|
||||||
const ret = try alloc.alloc(u8, out.items.len);
|
|
||||||
@memcpy(ret, out.items);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getParams(
|
pub fn getParams(
|
||||||
|
|||||||
Reference in New Issue
Block a user