| ... | ... | @@ -794,12 +794,23 @@ pub fn writeStruct(w: *Writer, value: anytype) Error!void { |
| 794 | 794 | /// comptime-known and matches host endianness. |
| 795 | 795 | /// TODO: make sure this value is not a reference type |
| 796 | 796 | pub inline fn writeStructEndian(w: *Writer, value: anytype, endian: std.builtin.Endian) Error!void { |
| 797 | | if (native_endian == endian) { |
| 798 | | return w.writeStruct(value); |
| 799 | | } else { |
| 800 | | var copy = value; |
| 801 | | std.mem.byteSwapAllFields(@TypeOf(value), &copy); |
| 802 | | return w.writeStruct(copy); |
| 797 | switch (@typeInfo(@TypeOf(value))) { |
| 798 | .@"struct" => |info| switch (info.layout) { |
| 799 | .auto => @compileError("ill-defined memory layout"), |
| 800 | .@"extern" => { |
| 801 | if (native_endian == endian) { |
| 802 | return w.writeStruct(value); |
| 803 | } else { |
| 804 | var copy = value; |
| 805 | std.mem.byteSwapAllFields(@TypeOf(value), &copy); |
| 806 | return w.writeStruct(copy); |
| 807 | } |
| 808 | }, |
| 809 | .@"packed" => { |
| 810 | return writeInt(w, info.backing_integer.?, @bitCast(value), endian); |
| 811 | }, |
| 812 | }, |
| 813 | else => @compileError("not a struct"), |
| 803 | 814 | } |
| 804 | 815 | } |
| 805 | 816 | |