Fixed failure using readStruct and gave async readStruct the same sig

This commit is contained in:
Jimmi HC 2018-11-15 21:59:17 +01:00
parent f4606842d2
commit 3090f83800
2 changed files with 5 additions and 4 deletions

View File

@ -53,10 +53,12 @@ pub fn InStream(comptime ReadError: type) type {
return mem.readInt(bytes, T, endian);
}
pub async fn readStruct(self: *Self, comptime T: type, ptr: *T) !void {
pub async fn readStruct(self: *Self, comptime T: type) !T {
// Only extern and packed structs have defined in-memory layout.
comptime assert(@typeInfo(T).Struct.layout != builtin.TypeInfo.ContainerLayout.Auto);
return await (async self.readNoEof(@sliceToBytes((*[1]T)(ptr)[0..])) catch unreachable);
var res: [1]T = undefined;
try await (async self.readNoEof(@sliceToBytes(res[0..])) catch unreachable);
return res[0];
}
};
}

View File

@ -485,8 +485,7 @@ const Msf = struct {
var file_stream = file.inStream();
const in = &file_stream.stream;
var superblock: SuperBlock = undefined;
try in.readStruct(SuperBlock, &superblock);
const superblock = try in.readStruct(SuperBlock);
if (!mem.eql(u8, superblock.FileMagic, SuperBlock.file_magic))
return error.InvalidDebugInfo;