| ... | ... | @@ -4,6 +4,7 @@ |
| 4 | 4 | // The MIT license requires this copyright notice to be included in all copies |
| 5 | 5 | // and substantial portions of the software. |
| 6 | 6 | const std = @import("../std.zig"); |
| 7 | const assert = std.debug.assert; |
| 7 | 8 | const builtin = std.builtin; |
| 8 | 9 | const mem = std.mem; |
| 9 | 10 | |
| ... | ... | @@ -86,5 +87,11 @@ pub fn Writer( |
| 86 | 87 | mem.writeInt(T, &bytes, value, endian); |
| 87 | 88 | return self.writeAll(&bytes); |
| 88 | 89 | } |
| 90 | |
| 91 | pub fn writeStruct(self: Self, value: anytype) Error!void { |
| 92 | // Only extern and packed structs have defined in-memory layout. |
| 93 | comptime assert(@typeInfo(@TypeOf(value)).Struct.layout != builtin.TypeInfo.ContainerLayout.Auto); |
| 94 | return self.writeAll(mem.asBytes(&value)); |
| 95 | } |
| 89 | 96 | }; |
| 90 | 97 | } |