| ... | @@ -46,39 +46,34 @@ pub fn Writer( | ... | @@ -46,39 +46,34 @@ pub fn Writer( |
| 46 | } | 46 | } |
| 47 | | 47 | |
| 48 | /// Write a native-endian integer. | 48 | /// Write a native-endian integer. |
| 49 | /// TODO audit non-power-of-two int sizes | | |
| 50 | pub fn writeIntNative(self: Self, comptime T: type, value: T) Error!void { | 49 | pub fn writeIntNative(self: Self, comptime T: type, value: T) Error!void { |
| 51 | var bytes: [(@typeInfo(T).Int.bits + 7) / 8]u8 = undefined; | 50 | var bytes: [(@typeInfo(T).Int.bits + 7) / 8]u8 = undefined; |
| 52 | mem.writeIntNative(T, &bytes, value); | 51 | mem.writeIntNative(std.math.ByteAlignedInt(@TypeOf(value)), &bytes, value); |
| 53 | return self.writeAll(&bytes); | 52 | return self.writeAll(&bytes); |
| 54 | } | 53 | } |
| 55 | | 54 | |
| 56 | /// Write a foreign-endian integer. | 55 | /// Write a foreign-endian integer. |
| 57 | /// TODO audit non-power-of-two int sizes | | |
| 58 | pub fn writeIntForeign(self: Self, comptime T: type, value: T) Error!void { | 56 | pub fn writeIntForeign(self: Self, comptime T: type, value: T) Error!void { |
| 59 | var bytes: [(@typeInfo(T).Int.bits + 7) / 8]u8 = undefined; | 57 | var bytes: [(@typeInfo(T).Int.bits + 7) / 8]u8 = undefined; |
| 60 | mem.writeIntForeign(T, &bytes, value); | 58 | mem.writeIntForeign(std.math.ByteAlignedInt(@TypeOf(value)), &bytes, value); |
| 61 | return self.writeAll(&bytes); | 59 | return self.writeAll(&bytes); |
| 62 | } | 60 | } |
| 63 | | 61 | |
| 64 | /// TODO audit non-power-of-two int sizes | | |
| 65 | pub fn writeIntLittle(self: Self, comptime T: type, value: T) Error!void { | 62 | pub fn writeIntLittle(self: Self, comptime T: type, value: T) Error!void { |
| 66 | var bytes: [(@typeInfo(T).Int.bits + 7) / 8]u8 = undefined; | 63 | var bytes: [(@typeInfo(T).Int.bits + 7) / 8]u8 = undefined; |
| 67 | mem.writeIntLittle(T, &bytes, value); | 64 | mem.writeIntLittle(std.math.ByteAlignedInt(@TypeOf(value)), &bytes, value); |
| 68 | return self.writeAll(&bytes); | 65 | return self.writeAll(&bytes); |
| 69 | } | 66 | } |
| 70 | | 67 | |
| 71 | /// TODO audit non-power-of-two int sizes | | |
| 72 | pub fn writeIntBig(self: Self, comptime T: type, value: T) Error!void { | 68 | pub fn writeIntBig(self: Self, comptime T: type, value: T) Error!void { |
| 73 | var bytes: [(@typeInfo(T).Int.bits + 7) / 8]u8 = undefined; | 69 | var bytes: [(@typeInfo(T).Int.bits + 7) / 8]u8 = undefined; |
| 74 | mem.writeIntBig(T, &bytes, value); | 70 | mem.writeIntBig(std.math.ByteAlignedInt(@TypeOf(value)), &bytes, value); |
| 75 | return self.writeAll(&bytes); | 71 | return self.writeAll(&bytes); |
| 76 | } | 72 | } |
| 77 | | 73 | |
| 78 | /// TODO audit non-power-of-two int sizes | | |
| 79 | pub fn writeInt(self: Self, comptime T: type, value: T, endian: std.builtin.Endian) Error!void { | 74 | pub fn writeInt(self: Self, comptime T: type, value: T, endian: std.builtin.Endian) Error!void { |
| 80 | var bytes: [(@typeInfo(T).Int.bits + 7) / 8]u8 = undefined; | 75 | var bytes: [(@typeInfo(T).Int.bits + 7) / 8]u8 = undefined; |
| 81 | mem.writeInt(T, &bytes, value, endian); | 76 | mem.writeInt(std.math.ByteAlignedInt(@TypeOf(value)), &bytes, value, endian); |
| 82 | return self.writeAll(&bytes); | 77 | return self.writeAll(&bytes); |
| 83 | } | 78 | } |
| 84 | | 79 | |