mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
cdp.lp: use enum for getSemanticTree format param
Leverages std.json.parse to automatically validate the format param into a type-safe enum.
This commit is contained in:
@@ -44,7 +44,7 @@ pub fn processMessage(cmd: anytype) !void {
|
|||||||
|
|
||||||
fn getSemanticTree(cmd: anytype) !void {
|
fn getSemanticTree(cmd: anytype) !void {
|
||||||
const Params = struct {
|
const Params = struct {
|
||||||
format: ?[]const u8 = null,
|
format: ?enum { text } = null,
|
||||||
prune: ?bool = null,
|
prune: ?bool = null,
|
||||||
};
|
};
|
||||||
const params = (try cmd.params(Params)) orelse Params{};
|
const params = (try cmd.params(Params)) orelse Params{};
|
||||||
@@ -62,8 +62,8 @@ fn getSemanticTree(cmd: anytype) !void {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (params.format) |format| {
|
if (params.format) |format| {
|
||||||
if (std.mem.eql(u8, format, "text")) {
|
if (format == .text) {
|
||||||
st.prune = params.prune orelse true; // text format defaults to pruned
|
st.prune = params.prune orelse true;
|
||||||
var aw: std.Io.Writer.Allocating = .init(cmd.arena);
|
var aw: std.Io.Writer.Allocating = .init(cmd.arena);
|
||||||
defer aw.deinit();
|
defer aw.deinit();
|
||||||
try st.textStringify(&aw.writer);
|
try st.textStringify(&aw.writer);
|
||||||
|
|||||||
Reference in New Issue
Block a user