| ... | ... | @@ -2256,20 +2256,20 @@ test writeVarPackedInt { |
| 2256 | 2256 | /// Swap the byte order of all the members of the fields of a struct |
| 2257 | 2257 | /// (Changing their endianness) |
| 2258 | 2258 | pub fn byteSwapAllFields(comptime S: type, ptr: *S) void { |
| 2259 | | byteSwapAllFieldsAligned(S, @alignOf(S), ptr); |
| 2259 | byteSwapAllFieldsAligned(S, .of(S), ptr); |
| 2260 | 2260 | } |
| 2261 | 2261 | |
| 2262 | 2262 | /// Swap the byte order of all the members of the fields of a struct |
| 2263 | 2263 | /// (Changing their endianness) |
| 2264 | | pub fn byteSwapAllFieldsAligned(comptime S: type, comptime A: comptime_int, ptr: *align(A) S) void { |
| 2264 | pub fn byteSwapAllFieldsAligned(comptime S: type, comptime a: Alignment, ptr: *align(a.toByteUnits()) S) void { |
| 2265 | 2265 | switch (@typeInfo(S)) { |
| 2266 | 2266 | .@"struct" => |struct_info| { |
| 2267 | 2267 | if (struct_info.backing_integer) |Int| { |
| 2268 | 2268 | ptr.* = @bitCast(@byteSwap(@as(Int, @bitCast(ptr.*)))); |
| 2269 | 2269 | } else inline for (std.meta.fields(S)) |f| { |
| 2270 | 2270 | switch (@typeInfo(f.type)) { |
| 2271 | | .@"struct" => byteSwapAllFieldsAligned(f.type, f.alignment, &@field(ptr, f.name)), |
| 2272 | | .@"union", .array => byteSwapAllFieldsAligned(f.type, f.alignment, &@field(ptr, f.name)), |
| 2271 | .@"struct" => byteSwapAllFieldsAligned(f.type, .fromByteUnits(f.alignment), &@field(ptr, f.name)), |
| 2272 | .@"union", .array => byteSwapAllFieldsAligned(f.type, .fromByteUnits(f.alignment), &@field(ptr, f.name)), |
| 2273 | 2273 | .@"enum" => { |
| 2274 | 2274 | @field(ptr, f.name) = @enumFromInt(@byteSwap(@intFromEnum(@field(ptr, f.name)))); |
| 2275 | 2275 | }, |