Handle CDP messages with different order

The 'method' still needs to be the first or the second key
(in this case after the 'id').

Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
Francis Bouvier
2024-06-07 15:59:57 +02:00
parent 3ad19dffa1
commit dc1456f4e8
8 changed files with 255 additions and 211 deletions

View File

@@ -4,7 +4,7 @@ const server = @import("../server.zig");
const Ctx = server.Cmd;
const cdp = @import("cdp.zig");
const result = cdp.result;
const getParams = cdp.getParams;
const getMsg = cdp.getMsg;
const stringify = cdp.stringify;
const LogMethods = enum {
@@ -13,24 +13,26 @@ const LogMethods = enum {
pub fn log(
alloc: std.mem.Allocator,
id: u64,
id: ?u16,
action: []const u8,
scanner: *std.json.Scanner,
ctx: *Ctx,
) ![]const u8 {
const method = std.meta.stringToEnum(LogMethods, action) orelse
return error.UnknownMethod;
return switch (method) {
.enable => enable(alloc, id, scanner, ctx),
.enable => logEnable(alloc, id, scanner, ctx),
};
}
fn enable(
fn logEnable(
alloc: std.mem.Allocator,
id: u64,
id: ?u16,
scanner: *std.json.Scanner,
_: *Ctx,
) ![]const u8 {
const sessionID = try cdp.getSessionID(scanner);
return result(alloc, id, null, null, sessionID);
const msg = try getMsg(alloc, void, scanner);
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID);
}