mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
std: use decl literals to improve endian ergonomics
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user