Hi, this function fails with the error error: operand of switch loop has comptime-only type 'lang.Type':
fn msgLen(msg: anytype) u16 {
const T = @TypeOf(msg);
var size: usize = 0;
sw: switch (@typeInfo(T)) {
.@"struct" => |info| for (info.field_types, info.field_names) |ty, name| {
switch (ty) {
i32, u32, ObjectId => size += @sizeOf(ty),
[]const u8 => size += @sizeOf(u32) + roundUp(4, @field(msg, name).len),
else => unreachable,
}
},
.@"union" => continue :sw @field(msg, @tagName(msg)),
else => unreachable,
}
return @intCast(size);
}
Is there a way around this, or do I have to pass the type as an argument?