| ... | ... | @@ -443,8 +443,7 @@ pub fn readIntNative(comptime T: type, bytes: *const [@sizeOf(T)]u8) T { |
| 443 | 443 | /// This function cannot fail and cannot cause undefined behavior. |
| 444 | 444 | /// Assumes the endianness of memory is foreign, so it must byte-swap. |
| 445 | 445 | pub fn readIntForeign(comptime T: type, bytes: *const [@sizeOf(T)]u8) T { |
| 446 | | comptime assert(T.bit_count % 8 == 0); |
| 447 | | return @bswap(T, @ptrCast(*align(1) const T, bytes).*); |
| 446 | return @bswap(T, readIntNative(T, bytes)); |
| 448 | 447 | } |
| 449 | 448 | |
| 450 | 449 | pub const readIntLittle = switch (builtin.endian) { |
| ... | ... | @@ -476,10 +475,7 @@ pub fn readIntSliceNative(comptime T: type, bytes: []const u8) T { |
| 476 | 475 | /// The bit count of T must be evenly divisible by 8. |
| 477 | 476 | /// Assumes the endianness of memory is foreign, so it must byte-swap. |
| 478 | 477 | pub fn readIntSliceForeign(comptime T: type, bytes: []const u8) T { |
| 479 | | assert(@sizeOf(u24) == 3); |
| 480 | | assert(bytes.len >= @sizeOf(T)); |
| 481 | | // TODO https://github.com/ziglang/zig/issues/863 |
| 482 | | return readIntForeign(T, @ptrCast(*const [@sizeOf(T)]u8, bytes.ptr)); |
| 478 | return @bswap(T, readIntSliceNative(T, bytes)); |
| 483 | 479 | } |
| 484 | 480 | |
| 485 | 481 | pub const readIntSliceLittle = switch (builtin.endian) { |
| ... | ... | @@ -548,7 +544,7 @@ pub fn writeIntNative(comptime T: type, buf: *[@sizeOf(T)]u8, value: T) void { |
| 548 | 544 | /// the integer bit width must be divisible by 8. |
| 549 | 545 | /// This function stores in foreign endian, which means it does a @bswap first. |
| 550 | 546 | pub fn writeIntForeign(comptime T: type, buf: *[@sizeOf(T)]u8, value: T) void { |
| 551 | | @ptrCast(*align(1) T, buf).* = @bswap(T, value); |
| 547 | writeIntNative(T, buf, @bswap(T, value)); |
| 552 | 548 | } |
| 553 | 549 | |
| 554 | 550 | pub const writeIntLittle = switch (builtin.endian) { |