| ... | @@ -61,39 +61,51 @@ pub fn addValues(self: *ConfigHeaderStep, values: anytype) void { | ... | @@ -61,39 +61,51 @@ pub fn addValues(self: *ConfigHeaderStep, values: anytype) void { |
| 61 | | 61 | |
| 62 | fn addValuesInner(self: *ConfigHeaderStep, values: anytype) !void { | 62 | fn addValuesInner(self: *ConfigHeaderStep, values: anytype) !void { |
| 63 | inline for (@typeInfo(@TypeOf(values)).Struct.fields) |field| { | 63 | inline for (@typeInfo(@TypeOf(values)).Struct.fields) |field| { |
| 64 | switch (@typeInfo(field.type)) { | 64 | try putValue(self, field.name, field.type, @field(values, field.name)); |
| 65 | .Null => { | 65 | } |
| 66 | try self.values.put(field.name, .undef); | 66 | } |
| 67 | }, | | |
| 68 | .Void => { | | |
| 69 | try self.values.put(field.name, .defined); | | |
| 70 | }, | | |
| 71 | .Bool => { | | |
| 72 | try self.values.put(field.name, .{ .boolean = @field(values, field.name) }); | | |
| 73 | }, | | |
| 74 | .ComptimeInt => { | | |
| 75 | try self.values.put(field.name, .{ .int = @field(values, field.name) }); | | |
| 76 | }, | | |
| 77 | .EnumLiteral => { | | |
| 78 | try self.values.put(field.name, .{ .ident = @tagName(@field(values, field.name)) }); | | |
| 79 | }, | | |
| 80 | .Pointer => |ptr| { | | |
| 81 | switch (@typeInfo(ptr.child)) { | | |
| 82 | .Array => |array| { | | |
| 83 | if (ptr.size == .One and array.child == u8) { | | |
| 84 | try self.values.put(field.name, .{ .string = @field(values, field.name) }); | | |
| 85 | continue; | | |
| 86 | } | | |
| 87 | }, | | |
| 88 | else => {}, | | |
| 89 | } | | |
| 90 | | 67 | |
| 91 | @compileError("unsupported ConfigHeaderStep value type: " ++ | 68 | fn putValue(self: *ConfigHeaderStep, field_name: []const u8, comptime T: type, v: T) !void { |
| 92 | @typeName(field.type)); | 69 | switch (@typeInfo(T)) { |
| 93 | }, | 70 | .Null => { |
| 94 | else => @compileError("unsupported ConfigHeaderStep value type: " ++ | 71 | try self.values.put(field_name, .undef); |
| 95 | @typeName(field.type)), | 72 | }, |
| 96 | } | 73 | .Void => { |
| | 74 | try self.values.put(field_name, .defined); |
| | 75 | }, |
| | 76 | .Bool => { |
| | 77 | try self.values.put(field_name, .{ .boolean = v }); |
| | 78 | }, |
| | 79 | .Int => { |
| | 80 | try self.values.put(field_name, .{ .int = v }); |
| | 81 | }, |
| | 82 | .ComptimeInt => { |
| | 83 | try self.values.put(field_name, .{ .int = v }); |
| | 84 | }, |
| | 85 | .EnumLiteral => { |
| | 86 | try self.values.put(field_name, .{ .ident = @tagName(v) }); |
| | 87 | }, |
| | 88 | .Optional => { |
| | 89 | if (v) |x| { |
| | 90 | return putValue(self, field_name, @TypeOf(x), x); |
| | 91 | } else { |
| | 92 | try self.values.put(field_name, .undef); |
| | 93 | } |
| | 94 | }, |
| | 95 | .Pointer => |ptr| { |
| | 96 | switch (@typeInfo(ptr.child)) { |
| | 97 | .Array => |array| { |
| | 98 | if (ptr.size == .One and array.child == u8) { |
| | 99 | try self.values.put(field_name, .{ .string = v }); |
| | 100 | return; |
| | 101 | } |
| | 102 | }, |
| | 103 | else => {}, |
| | 104 | } |
| | 105 | |
| | 106 | @compileError("unsupported ConfigHeaderStep value type: " ++ @typeName(T)); |
| | 107 | }, |
| | 108 | else => @compileError("unsupported ConfigHeaderStep value type: " ++ @typeName(T)), |
| 97 | } | 109 | } |
| 98 | } | 110 | } |
| 99 | | 111 | |