| ... | @@ -2179,22 +2179,8 @@ pub fn byteSwapAllFields(comptime S: type, ptr: *S) void { | ... | @@ -2179,22 +2179,8 @@ pub fn byteSwapAllFields(comptime S: type, ptr: *S) void { |
| 2179 | const BackingInt = std.meta.Int(.unsigned, @bitSizeOf(S)); | 2179 | const BackingInt = std.meta.Int(.unsigned, @bitSizeOf(S)); |
| 2180 | ptr.* = @bitCast(@byteSwap(@as(BackingInt, @bitCast(ptr.*)))); | 2180 | ptr.* = @bitCast(@byteSwap(@as(BackingInt, @bitCast(ptr.*)))); |
| 2181 | }, | 2181 | }, |
| 2182 | .array => { | 2182 | .array => |info| { |
| 2183 | for (ptr) |*item| { | 2183 | byteSwapAllElements(info.child, ptr); |
| 2184 | switch (@typeInfo(@TypeOf(item.*))) { | | |
| 2185 | .@"struct", .@"union", .array => byteSwapAllFields(@TypeOf(item.*), item), | | |
| 2186 | .@"enum" => { | | |
| 2187 | item.* = @enumFromInt(@byteSwap(@intFromEnum(item.*))); | | |
| 2188 | }, | | |
| 2189 | .bool => {}, | | |
| 2190 | .float => |float_info| { | | |
| 2191 | item.* = @bitCast(@byteSwap(@as(std.meta.Int(.unsigned, float_info.bits), @bitCast(item.*)))); | | |
| 2192 | }, | | |
| 2193 | else => { | | |
| 2194 | item.* = @byteSwap(item.*); | | |
| 2195 | }, | | |
| 2196 | } | | |
| 2197 | } | | |
| 2198 | }, | 2184 | }, |
| 2199 | else => { | 2185 | else => { |
| 2200 | ptr.* = @byteSwap(ptr.*); | 2186 | ptr.* = @byteSwap(ptr.*); |
| ... | @@ -2258,6 +2244,24 @@ test byteSwapAllFields { | ... | @@ -2258,6 +2244,24 @@ test byteSwapAllFields { |
| 2258 | }, k); | 2244 | }, k); |
| 2259 | } | 2245 | } |
| 2260 | | 2246 | |
| | 2247 | pub fn byteSwapAllElements(comptime Elem: type, slice: []Elem) void { |
| | 2248 | for (slice) |*elem| { |
| | 2249 | switch (@typeInfo(@TypeOf(elem.*))) { |
| | 2250 | .@"struct", .@"union", .array => byteSwapAllFields(@TypeOf(elem.*), elem), |
| | 2251 | .@"enum" => { |
| | 2252 | elem.* = @enumFromInt(@byteSwap(@intFromEnum(elem.*))); |
| | 2253 | }, |
| | 2254 | .bool => {}, |
| | 2255 | .float => |float_info| { |
| | 2256 | elem.* = @bitCast(@byteSwap(@as(std.meta.Int(.unsigned, float_info.bits), @bitCast(elem.*)))); |
| | 2257 | }, |
| | 2258 | else => { |
| | 2259 | elem.* = @byteSwap(elem.*); |
| | 2260 | }, |
| | 2261 | } |
| | 2262 | } |
| | 2263 | } |
| | 2264 | |
| 2261 | /// Returns an iterator that iterates over the slices of `buffer` that are not | 2265 | /// Returns an iterator that iterates over the slices of `buffer` that are not |
| 2262 | /// any of the items in `delimiters`. | 2266 | /// any of the items in `delimiters`. |
| 2263 | /// | 2267 | /// |