diff --git a/src/cdp/cdp.zig b/src/cdp/cdp.zig index def8e2ff..2d2ae708 100644 --- a/src/cdp/cdp.zig +++ b/src/cdp/cdp.zig @@ -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,