mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 22:35:24 +00:00
add int writing functions to OutStream
added: writeInt, writeIntLe, and writeIntBe
This commit is contained in:
parent
2cbad364c1
commit
3ce0ea884f
14
std/io.zig
14
std/io.zig
@ -230,6 +230,20 @@ pub fn OutStream(comptime WriteError: type) type {
|
||||
try self.writeFn(self, slice);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn writeIntLe(self: *Self, comptime T: type, value: T) !void {
|
||||
return self.writeInt(builtin.Endian.Little, T, value);
|
||||
}
|
||||
|
||||
pub fn writeIntBe(self: *Self, comptime T: type, value: T) !void {
|
||||
return self.writeInt(builtin.Endian.Big, T, value);
|
||||
}
|
||||
|
||||
pub fn writeInt(self: *Self, endian: builtin.Endian, comptime T: type, value: T) !void {
|
||||
var bytes: [@sizeOf(T)]u8 = undefined;
|
||||
mem.writeInt(bytes[0..], value, endian);
|
||||
return self.writeFn(self, bytes);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user