Add method cdp function

Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
Francis Bouvier
2024-04-18 13:18:16 +02:00
parent 43a558f5ae
commit 490eb40028

View File

@@ -52,11 +52,11 @@ pub fn do(
const id = try std.fmt.parseUnsigned(u64, (try scanner.next()).number, 10);
try checkKey("method", (try scanner.next()).string);
const method = (try scanner.next()).string;
const method_name = (try scanner.next()).string;
std.log.debug("cmd: id {any}, method {s}", .{ id, method });
std.log.debug("cmd: id {any}, method {s}", .{ id, method_name });
var iter = std.mem.splitScalar(u8, method, '.');
var iter = std.mem.splitScalar(u8, method_name, '.');
const domain = std.meta.stringToEnum(Domains, iter.first()) orelse
return error.UnknonwDomain;
@@ -121,6 +121,24 @@ pub fn result(
return stringify(alloc, resp);
}
// caller owns the slice returned
pub fn method(
alloc: std.mem.Allocator,
name: []const u8,
comptime T: type,
params: T,
sessionID: ?[]const u8,
) ![]const u8 {
const Resp = struct {
method: []const u8,
params: T,
sessionId: ?[]const u8,
};
const resp = Resp{ .method = name, .params = params, .sessionId = sessionID };
return stringify(alloc, resp);
}
pub fn getParams(
alloc: std.mem.Allocator,
comptime T: type,