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