zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 3ce0ea884f8a64e1173ab814de10b6c33833b3b8 (tree)
parent 2cbad364c1d23b64ae064f8547590c133b4f070a
Author: dbandstra <dbandstra@protonmail.com>
Date:   Sat, 28 Jul 2018 17:30:05 -0700

add int writing functions to OutStream

added: writeInt, writeIntLe, and writeIntBe

Diffstat:
Mstd/io.zig | 14++++++++++++++
1 file changed, 14 insertions(+), 0 deletions(-)

diff --git a/std/io.zig b/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); + } }; }