diff options
| author | dbandstra <dbandstra@protonmail.com> | 2018-07-28 17:30:05 -0700 |
|---|---|---|
| committer | dbandstra <dbandstra@protonmail.com> | 2018-07-28 17:30:05 -0700 |
| commit | 3ce0ea884f8a64e1173ab814de10b6c33833b3b8 (patch) | |
| tree | f1ccd6e6639402c1414dc1baa5cd1bdd90caa377 /std/io.zig | |
| parent | 2cbad364c1d23b64ae064f8547590c133b4f070a (diff) | |
| download | zig-3ce0ea884f8a64e1173ab814de10b6c33833b3b8.tar.gz zig-3ce0ea884f8a64e1173ab814de10b6c33833b3b8.zip | |
add int writing functions to OutStream
added: writeInt, writeIntLe, and writeIntBe
Diffstat (limited to 'std/io.zig')
| -rw-r--r-- | std/io.zig | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/std/io.zig b/std/io.zig index 71a9822399..1b1c56b69b 100644 --- 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); + } }; } |
