mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
parent
f657767b60
commit
e4abdf5a13
1 changed files with 23 additions and 2 deletions
|
|
@ -1148,7 +1148,7 @@ pub inline fn takeStruct(r: *Reader, comptime T: type, endian: std.builtin.Endia
|
||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
.@"packed" => {
|
.@"packed" => {
|
||||||
return takeInt(r, info.backing_integer.?, endian);
|
return @bitCast(try takeInt(r, info.backing_integer.?, endian));
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
else => @compileError("not a struct"),
|
else => @compileError("not a struct"),
|
||||||
|
|
@ -1173,7 +1173,7 @@ pub inline fn peekStruct(r: *Reader, comptime T: type, endian: std.builtin.Endia
|
||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
.@"packed" => {
|
.@"packed" => {
|
||||||
return peekInt(r, info.backing_integer.?, endian);
|
return @bitCast(try peekInt(r, info.backing_integer.?, endian));
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
else => @compileError("not a struct"),
|
else => @compileError("not a struct"),
|
||||||
|
|
@ -1724,6 +1724,27 @@ test "takeDelimiterInclusive when it rebases" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "takeStruct and peekStruct packed" {
|
||||||
|
var r: Reader = .fixed(&.{ 0b11110000, 0b00110011 });
|
||||||
|
const S = packed struct(u16) { a: u2, b: u6, c: u7, d: u1 };
|
||||||
|
|
||||||
|
try testing.expectEqual(@as(S, .{
|
||||||
|
.a = 0b11,
|
||||||
|
.b = 0b001100,
|
||||||
|
.c = 0b1110000,
|
||||||
|
.d = 0b1,
|
||||||
|
}), try r.peekStruct(S, .big));
|
||||||
|
|
||||||
|
try testing.expectEqual(@as(S, .{
|
||||||
|
.a = 0b11,
|
||||||
|
.b = 0b001100,
|
||||||
|
.c = 0b1110000,
|
||||||
|
.d = 0b1,
|
||||||
|
}), try r.takeStruct(S, .big));
|
||||||
|
|
||||||
|
try testing.expectError(error.EndOfStream, r.takeStruct(S, .little));
|
||||||
|
}
|
||||||
|
|
||||||
/// Provides a `Reader` implementation by passing data from an underlying
|
/// Provides a `Reader` implementation by passing data from an underlying
|
||||||
/// reader through `Hasher.update`.
|
/// reader through `Hasher.update`.
|
||||||
///
|
///
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue