std: use decl literals to improve endian ergonomics

This commit is contained in:
Meghan Denny
2026-01-01 20:34:55 -08:00
parent 0c5f879b98
commit 53ebfde6b4
2 changed files with 7 additions and 0 deletions
+3
View File
@@ -841,6 +841,9 @@ pub const FloatMode = enum {
pub const Endian = enum {
big,
little,
pub const native = builtin.target.cpu.arch.endian();
pub const foreign: Endian = @enumFromInt(1 - @intFromEnum(native));
};
/// This data structure is used by the Zig language code generation and
+4
View File
@@ -2006,11 +2006,13 @@ fn readPackedIntBig(comptime T: type, bytes: []const u8, bit_offset: usize) T {
} else return @as(T, @bitCast(val));
}
/// Deprecated: use readPackedInt(T, bytes, bit_offset, value, .native)
pub const readPackedIntNative = switch (native_endian) {
.little => readPackedIntLittle,
.big => readPackedIntBig,
};
/// Deprecated: use readPackedInt(T, bytes, bit_offset, value, .foreign)
pub const readPackedIntForeign = switch (native_endian) {
.little => readPackedIntBig,
.big => readPackedIntLittle,
@@ -2159,11 +2161,13 @@ fn writePackedIntBig(comptime T: type, bytes: []u8, bit_offset: usize, value: T)
writeInt(StoreInt, write_bytes[(byte_count - store_size)..][0..store_size], write_value, .big);
}
/// Deprecated: use writePackedInt(T, bytes, bit_offset, value, .native)
pub const writePackedIntNative = switch (native_endian) {
.little => writePackedIntLittle,
.big => writePackedIntBig,
};
/// Deprecated: use writePackedInt(T, bytes, bit_offset, value, .foreign)
pub const writePackedIntForeign = switch (native_endian) {
.little => writePackedIntBig,
.big => writePackedIntLittle,