| author | |
| committer | |
| log | 11c32c756f70540250139d6825937da53d74740a |
| tree | 81a2688fcbcc989384677192faccc264d5f07818 |
| parent | 5804f3f75716ee77382880954cf73cd4005f33f7 |
See also #155374 files changed, 13 insertions(+), 13 deletions(-)
lib/std/io/reader.zig+5-5| ... | ... | @@ -280,28 +280,28 @@ pub fn Reader( |
| 280 | 280 | |
| 281 | 281 | /// Reads a native-endian integer |
| 282 | 282 | pub fn readIntNative(self: Self, comptime T: type) (Error || error{EndOfStream})!T { |
| 283 | const bytes = try self.readBytesNoEof((@typeInfo(T).Int.bits + 7) / 8); | |
| 283 | const bytes = try self.readBytesNoEof(@as(u16, @intCast((@as(u17, @typeInfo(T).Int.bits) + 7) / 8))); | |
| 284 | 284 | return mem.readIntNative(T, &bytes); |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | /// Reads a foreign-endian integer |
| 288 | 288 | pub fn readIntForeign(self: Self, comptime T: type) (Error || error{EndOfStream})!T { |
| 289 | const bytes = try self.readBytesNoEof((@typeInfo(T).Int.bits + 7) / 8); | |
| 289 | const bytes = try self.readBytesNoEof(@as(u16, @intCast((@as(u17, @typeInfo(T).Int.bits) + 7) / 8))); | |
| 290 | 290 | return mem.readIntForeign(T, &bytes); |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | pub fn readIntLittle(self: Self, comptime T: type) !T { |
| 294 | const bytes = try self.readBytesNoEof((@typeInfo(T).Int.bits + 7) / 8); | |
| 294 | const bytes = try self.readBytesNoEof(@as(u16, @intCast((@as(u17, @typeInfo(T).Int.bits) + 7) / 8))); | |
| 295 | 295 | return mem.readIntLittle(T, &bytes); |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | pub fn readIntBig(self: Self, comptime T: type) !T { |
| 299 | const bytes = try self.readBytesNoEof((@typeInfo(T).Int.bits + 7) / 8); | |
| 299 | const bytes = try self.readBytesNoEof(@as(u16, @intCast((@as(u17, @typeInfo(T).Int.bits) + 7) / 8))); | |
| 300 | 300 | return mem.readIntBig(T, &bytes); |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | pub fn readInt(self: Self, comptime T: type, endian: std.builtin.Endian) !T { |
| 304 | const bytes = try self.readBytesNoEof((@typeInfo(T).Int.bits + 7) / 8); | |
| 304 | const bytes = try self.readBytesNoEof(@as(u16, @intCast((@as(u17, @typeInfo(T).Int.bits) + 7) / 8))); | |
| 305 | 305 | return mem.readInt(T, &bytes, endian); |
| 306 | 306 | } |
| 307 | 307 |
lib/std/io/writer.zig+5-5| ... | ... | @@ -47,32 +47,32 @@ pub fn Writer( |
| 47 | 47 | |
| 48 | 48 | /// Write a native-endian integer. |
| 49 | 49 | pub fn writeIntNative(self: Self, comptime T: type, value: T) Error!void { |
| 50 | var bytes: [(@typeInfo(T).Int.bits + 7) / 8]u8 = undefined; | |
| 50 | var bytes: [@as(u16, @intCast((@as(u17, @typeInfo(T).Int.bits) + 7) / 8))]u8 = undefined; | |
| 51 | 51 | mem.writeIntNative(std.math.ByteAlignedInt(@TypeOf(value)), &bytes, value); |
| 52 | 52 | return self.writeAll(&bytes); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /// Write a foreign-endian integer. |
| 56 | 56 | pub fn writeIntForeign(self: Self, comptime T: type, value: T) Error!void { |
| 57 | var bytes: [(@typeInfo(T).Int.bits + 7) / 8]u8 = undefined; | |
| 57 | var bytes: [@as(u16, @intCast((@as(u17, @typeInfo(T).Int.bits) + 7) / 8))]u8 = undefined; | |
| 58 | 58 | mem.writeIntForeign(std.math.ByteAlignedInt(@TypeOf(value)), &bytes, value); |
| 59 | 59 | return self.writeAll(&bytes); |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | pub fn writeIntLittle(self: Self, comptime T: type, value: T) Error!void { |
| 63 | var bytes: [(@typeInfo(T).Int.bits + 7) / 8]u8 = undefined; | |
| 63 | var bytes: [@as(u16, @intCast((@as(u17, @typeInfo(T).Int.bits) + 7) / 8))]u8 = undefined; | |
| 64 | 64 | mem.writeIntLittle(std.math.ByteAlignedInt(@TypeOf(value)), &bytes, value); |
| 65 | 65 | return self.writeAll(&bytes); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | pub fn writeIntBig(self: Self, comptime T: type, value: T) Error!void { |
| 69 | var bytes: [(@typeInfo(T).Int.bits + 7) / 8]u8 = undefined; | |
| 69 | var bytes: [@as(u16, @intCast((@as(u17, @typeInfo(T).Int.bits) + 7) / 8))]u8 = undefined; | |
| 70 | 70 | mem.writeIntBig(std.math.ByteAlignedInt(@TypeOf(value)), &bytes, value); |
| 71 | 71 | return self.writeAll(&bytes); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | pub fn writeInt(self: Self, comptime T: type, value: T, endian: std.builtin.Endian) Error!void { |
| 75 | var bytes: [(@typeInfo(T).Int.bits + 7) / 8]u8 = undefined; | |
| 75 | var bytes: [@as(u16, @intCast((@as(u17, @typeInfo(T).Int.bits) + 7) / 8))]u8 = undefined; | |
| 76 | 76 | mem.writeInt(std.math.ByteAlignedInt(@TypeOf(value)), &bytes, value, endian); |
| 77 | 77 | return self.writeAll(&bytes); |
| 78 | 78 | } |
lib/std/mem.zig+1-1| ... | ... | @@ -1616,7 +1616,7 @@ test "readIntBig and readIntLittle" { |
| 1616 | 1616 | /// accepts any integer bit width. |
| 1617 | 1617 | /// This function stores in native endian, which means it is implemented as a simple |
| 1618 | 1618 | /// memory store. |
| 1619 | pub fn writeIntNative(comptime T: type, buf: *[(@typeInfo(T).Int.bits + 7) / 8]u8, value: T) void { | |
| 1619 | pub fn writeIntNative(comptime T: type, buf: *[@as(u16, @intCast((@as(u17, @typeInfo(T).Int.bits) + 7) / 8))]u8, value: T) void { | |
| 1620 | 1620 | @as(*align(1) T, @ptrCast(buf)).* = value; |
| 1621 | 1621 | } |
| 1622 | 1622 |
src/value.zig+2-2| ... | ... | @@ -616,7 +616,7 @@ pub const Value = struct { |
| 616 | 616 | .Int, .Enum => { |
| 617 | 617 | const int_info = ty.intInfo(mod); |
| 618 | 618 | const bits = int_info.bits; |
| 619 | const byte_count = (bits + 7) / 8; | |
| 619 | const byte_count: u16 = @intCast((@as(u17, bits) + 7) / 8); | |
| 620 | 620 | |
| 621 | 621 | var bigint_buffer: BigIntSpace = undefined; |
| 622 | 622 | const bigint = val.toBigInt(&bigint_buffer, mod); |
| ... | ... | @@ -859,7 +859,7 @@ pub const Value = struct { |
| 859 | 859 | }; |
| 860 | 860 | const int_info = int_ty.intInfo(mod); |
| 861 | 861 | const bits = int_info.bits; |
| 862 | const byte_count = (bits + 7) / 8; | |
| 862 | const byte_count: u16 = @intCast((@as(u17, bits) + 7) / 8); | |
| 863 | 863 | if (bits == 0 or buffer.len == 0) return mod.getCoerced(try mod.intValue(int_ty, 0), ty); |
| 864 | 864 | |
| 865 | 865 | if (bits <= 64) switch (int_info.signedness) { // Fast path for integers <= u64 |