cdp: refacto message JSON read

This commit is contained in:
Pierre Tachoire
2024-10-29 09:49:36 +01:00
parent 1854074f64
commit 82c37fc71b
11 changed files with 431 additions and 409 deletions

View File

@@ -22,7 +22,7 @@ const server = @import("../server.zig");
const Ctx = server.Ctx;
const cdp = @import("cdp.zig");
const result = cdp.result;
const getMsg = cdp.getMsg;
const IncomingMessage = @import("msg.zig").IncomingMessage;
const stringify = cdp.stringify;
const log_cdp = std.log.scoped(.cdp);
@@ -33,27 +33,25 @@ const Methods = enum {
pub fn log(
alloc: std.mem.Allocator,
id: ?u16,
msg: *IncomingMessage,
action: []const u8,
scanner: *std.json.Scanner,
ctx: *Ctx,
) ![]const u8 {
const method = std.meta.stringToEnum(Methods, action) orelse
return error.UnknownMethod;
return switch (method) {
.enable => enable(alloc, id, scanner, ctx),
.enable => enable(alloc, msg, ctx),
};
}
fn enable(
alloc: std.mem.Allocator,
_id: ?u16,
scanner: *std.json.Scanner,
msg: *IncomingMessage,
_: *Ctx,
) ![]const u8 {
const msg = try getMsg(alloc, _id, void, scanner);
log_cdp.debug("Req > id {d}, method {s}", .{ msg.id, "log.enable" });
const input = try msg.getInput(alloc, void);
log_cdp.debug("Req > id {d}, method {s}", .{ input.id, "log.enable" });
return result(alloc, msg.id, null, null, msg.sessionID);
return result(alloc, input.id, null, null, input.sessionId);
}