We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 891c93c + 899e364 commit 465e75bCopy full SHA for 465e75b
std/endian.zig
@@ -2,11 +2,11 @@ const mem = @import("mem.zig");
2
const builtin = @import("builtin");
3
4
pub fn swapIfLe(comptime T: type, x: T) -> T {
5
- return swapIf(false, T, x);
+ return swapIf(builtin.Endian.Little, T, x);
6
}
7
8
pub fn swapIfBe(comptime T: type, x: T) -> T {
9
- return swapIf(true, T, x);
+ return swapIf(builtin.Endian.Big, T, x);
10
11
12
pub fn swapIf(endian: builtin.Endian, comptime T: type, x: T) -> T {
@@ -15,6 +15,11 @@ pub fn swapIf(endian: builtin.Endian, comptime T: type, x: T) -> T {
15
16
pub fn swap(comptime T: type, x: T) -> T {
17
var buf: [@sizeOf(T)]u8 = undefined;
18
- mem.writeInt(buf[0..], x, false);
+ mem.writeInt(buf[0..], x, builtin.Endian.Little);
19
return mem.readInt(buf, T, builtin.Endian.Big);
20
21
+
22
+test "swap" {
23
+ const debug = @import("debug/index.zig");
24
+ debug.assert(swap(u32, 0xDEADBEEF) == 0xEFBEADDE);
25
+}
0 commit comments