From 3ce0ea884f8a64e1173ab814de10b6c33833b3b8 Mon Sep 17 00:00:00 2001 From: dbandstra Date: Sat, 28 Jul 2018 17:30:05 -0700 Subject: [PATCH 1/2] add int writing functions to OutStream added: writeInt, writeIntLe, and writeIntBe --- std/io.zig | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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); + } }; } From f36faa32c46897a12852da9f382ab10979511d6f Mon Sep 17 00:00:00 2001 From: dbandstra Date: Sat, 28 Jul 2018 17:34:28 -0700 Subject: [PATCH 2/2] add skipBytes function to InStream this reads N bytes, discarding their values --- std/io.zig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/std/io.zig b/std/io.zig index 1b1c56b69b..5d73b4e7d8 100644 --- a/std/io.zig +++ b/std/io.zig @@ -200,6 +200,13 @@ pub fn InStream(comptime ReadError: type) type { try self.readNoEof(input_slice); return mem.readInt(input_slice, T, endian); } + + pub fn skipBytes(self: *Self, num_bytes: usize) !void { + var i: usize = 0; + while (i < num_bytes) : (i += 1) { + _ = try self.readByte(); + } + } }; }