Merge pull request #1300 from dbandstra/more-stream-functions

A few new functions in InStream/OutStream
This commit is contained in:
Andrew Kelley 2018-07-29 14:51:25 -04:00 committed by GitHub
commit f884381c60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();
}
}
};
}
@ -230,6 +237,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);
}
};
}