Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ziglang/zig
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2cbad364c1d2
Choose a base ref
...
head repository: ziglang/zig
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f884381c608f
Choose a head ref
  • 3 commits
  • 1 file changed
  • 2 contributors

Commits on Jul 29, 2018

  1. add int writing functions to OutStream

    added: writeInt, writeIntLe, and writeIntBe
    dbandstra committed Jul 29, 2018
    Copy the full SHA
    3ce0ea8 View commit details
  2. add skipBytes function to InStream

    this reads N bytes, discarding their values
    dbandstra committed Jul 29, 2018
    Copy the full SHA
    f36faa3 View commit details
  3. Merge pull request #1300 from dbandstra/more-stream-functions

    A few new functions in InStream/OutStream
    andrewrk authored Jul 29, 2018
    Copy the full SHA
    f884381 View commit details
Showing with 21 additions and 0 deletions.
  1. +21 −0 std/io.zig
21 changes: 21 additions & 0 deletions std/io.zig
Original file line number Diff line number Diff line change
@@ -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);
}
};
}