authorgravatar for dbandstra@protonmail.comdbandstra <dbandstra@protonmail.com> 2018-07-28 17:30:05-07:00
committergravatar for dbandstra@protonmail.comdbandstra <dbandstra@protonmail.com> 2018-07-28 17:30:05-07:00
log3ce0ea884f8a64e1173ab814de10b6c33833b3b8
treef1ccd6e6639402c1414dc1baa5cd1bdd90caa377
parent2cbad364c1d23b64ae064f8547590c133b4f070a

add int writing functions to OutStream

added: writeInt, writeIntLe, and writeIntBe

1 files changed, 14 insertions(+), 0 deletions(-)

std/io.zig+14
......@@ -230,6 +230,20 @@ pub fn OutStream(comptime WriteError: type) type {
230230 try self.writeFn(self, slice);
231231 }
232232 }
233
234 pub fn writeIntLe(self: *Self, comptime T: type, value: T) !void {
235 return self.writeInt(builtin.Endian.Little, T, value);
236 }
237
238 pub fn writeIntBe(self: *Self, comptime T: type, value: T) !void {
239 return self.writeInt(builtin.Endian.Big, T, value);
240 }
241
242 pub fn writeInt(self: *Self, endian: builtin.Endian, comptime T: type, value: T) !void {
243 var bytes: [@sizeOf(T)]u8 = undefined;
244 mem.writeInt(bytes[0..], value, endian);
245 return self.writeFn(self, bytes);
246 }
233247 };
234248}
235249