| ... | ... | @@ -483,7 +483,7 @@ pub fn writeSplatAll(w: *Writer, data: [][]const u8, splat: usize) Error!void { |
| 483 | 483 | |
| 484 | 484 | // Deal with any left over splats |
| 485 | 485 | if (data.len != 0 and truncate < data[index].len * splat) { |
| 486 | | std.debug.assert(index == data.len - 1); |
| 486 | assert(index == data.len - 1); |
| 487 | 487 | var remaining_splat = splat; |
| 488 | 488 | while (true) { |
| 489 | 489 | remaining_splat -= truncate / data[index].len; |
| ... | ... | @@ -840,11 +840,11 @@ pub inline fn writeStruct(w: *Writer, value: anytype, endian: std.builtin.Endian |
| 840 | 840 | .auto => @compileError("ill-defined memory layout"), |
| 841 | 841 | .@"extern" => { |
| 842 | 842 | if (native_endian == endian) { |
| 843 | | return w.writeStruct(value); |
| 843 | return w.writeAll(@ptrCast((&value)[0..1])); |
| 844 | 844 | } else { |
| 845 | 845 | var copy = value; |
| 846 | 846 | std.mem.byteSwapAllFields(@TypeOf(value), &copy); |
| 847 | | return w.writeStruct(copy); |
| 847 | return w.writeAll(@ptrCast((&copy)[0..1])); |
| 848 | 848 | } |
| 849 | 849 | }, |
| 850 | 850 | .@"packed" => { |
| ... | ... | @@ -2594,8 +2594,32 @@ test "allocating sendFile" { |
| 2594 | 2594 | var file_reader = file_writer.moveToReader(); |
| 2595 | 2595 | try file_reader.seekTo(0); |
| 2596 | 2596 | |
| 2597 | | var allocating: std.io.Writer.Allocating = .init(std.testing.allocator); |
| 2597 | var allocating: std.io.Writer.Allocating = .init(testing.allocator); |
| 2598 | 2598 | defer allocating.deinit(); |
| 2599 | 2599 | |
| 2600 | 2600 | _ = try file_reader.interface.streamRemaining(&allocating.writer); |
| 2601 | 2601 | } |
| 2602 | |
| 2603 | test writeStruct { |
| 2604 | var buffer: [16]u8 = undefined; |
| 2605 | const S = extern struct { a: u64, b: u32, c: u32 }; |
| 2606 | const s: S = .{ .a = 1, .b = 2, .c = 3 }; |
| 2607 | { |
| 2608 | var w: Writer = .fixed(&buffer); |
| 2609 | try w.writeStruct(s, .little); |
| 2610 | try testing.expectEqualSlices(u8, &.{ |
| 2611 | 1, 0, 0, 0, 0, 0, 0, 0, // |
| 2612 | 2, 0, 0, 0, // |
| 2613 | 3, 0, 0, 0, // |
| 2614 | }, &buffer); |
| 2615 | } |
| 2616 | { |
| 2617 | var w: Writer = .fixed(&buffer); |
| 2618 | try w.writeStruct(s, .big); |
| 2619 | try testing.expectEqualSlices(u8, &.{ |
| 2620 | 0, 0, 0, 0, 0, 0, 0, 1, // |
| 2621 | 0, 0, 0, 2, // |
| 2622 | 0, 0, 0, 3, // |
| 2623 | }, &buffer); |
| 2624 | } |
| 2625 | } |