Add support for parsing standalone enum fields

dev
LeRoyce Pearson 2023-08-10 19:24:32 -06:00
parent 8878108c6f
commit 6bdc230417
3 changed files with 14 additions and 7 deletions

View File

@ -196,6 +196,11 @@ pub fn main() !void {
std.debug.print("<- xdg_toplevel@{} {s} {}\n", .{ header.object_id, @tagName(@as(std.meta.Tag(wayland.xdg.Toplevel.Event), @enumFromInt(header.size_and_opcode.opcode))), std.zig.fmtEscapes(std.mem.sliceAsBytes(message_buffer.items)) }); std.debug.print("<- xdg_toplevel@{} {s} {}\n", .{ header.object_id, @tagName(@as(std.meta.Tag(wayland.xdg.Toplevel.Event), @enumFromInt(header.size_and_opcode.opcode))), std.zig.fmtEscapes(std.mem.sliceAsBytes(message_buffer.items)) });
} else if (header.object_id == registry_done_id) { } else if (header.object_id == registry_done_id) {
done = true; done = true;
} else if (header.object_id == shm_id) {
const event = try wayland.deserialize(wayland.core.Shm.Event, header, message_buffer.items);
switch (event) {
.format => |format| std.debug.print("<- format {} {}\n", .{ format.format, std.zig.fmtEscapes(std.mem.asBytes(&format.format)) }),
}
} else if (header.object_id == 1) { } else if (header.object_id == 1) {
const event = try wayland.deserialize(wayland.core.Display.Event, header, message_buffer.items); const event = try wayland.deserialize(wayland.core.Display.Event, header, message_buffer.items);
switch (event) { switch (event) {

View File

@ -144,13 +144,10 @@ pub const Shm = struct {
}; };
}; };
pub const Event = union(Event.Tag) { pub const Event = union(enum) {
format: struct {
format: Format, format: Format,
},
pub const Tag = enum(u16) {
@"error",
delete_id,
};
}; };
pub const Format = enum(u32) { pub const Format = enum(u32) {

View File

@ -113,6 +113,11 @@ pub fn deserializeArguments(comptime Signature: type, buffer: []const u32) !Sign
.signed => @field(result, field.name) = try readInt(buffer, &pos), .signed => @field(result, field.name) = try readInt(buffer, &pos),
.unsigned => @field(result, field.name) = try readUInt(buffer, &pos), .unsigned => @field(result, field.name) = try readUInt(buffer, &pos),
}, },
.Enum => |enum_info| if (@sizeOf(enum_info.tag_type) == @sizeOf(u32)) {
@field(result, field.name) = @enumFromInt(try readInt(buffer, &pos));
} else {
@compileError("Unsupported type " ++ @typeName(field.type));
},
.Pointer => |ptr| switch (ptr.size) { .Pointer => |ptr| switch (ptr.size) {
.Slice => if (ptr.child == u8) { .Slice => if (ptr.child == u8) {
@field(result, field.name) = try readString(buffer, &pos); @field(result, field.name) = try readString(buffer, &pos);