toBytes method
Serializes all metadata structures into a portable executable (PE) format,
as specified by the Windows Metadata (.winmd
) specification.
Returns a Uint8List containing the serialized binary representation of
of the metadata, ready for use in creating .winmd
files.
Implementation
Uint8List toBytes() {
_removeRedundantAssemblyRefsAndFixTypeRefs();
_finalizeAndValidateSortedTables();
final blobHeapBytes = _blobHeap.toBytes();
final guidHeapBytes = _guidHeap.toBytes();
final stringHeapBytes = _stringHeap.toBytes();
final userStringHeapBytes = _userStringHeap.toBytes();
_tableStream.setHeapSizes(
blobHeapSize: blobHeapBytes.length,
guidHeapSize: guidHeapBytes.length,
stringHeapSize: stringHeapBytes.length,
userStringHeapSize: userStringHeapBytes.length,
);
final tableStreamBytes = _tableStream.toBytes();
_ensureHeapSizesFit32Bit([
blobHeapBytes,
guidHeapBytes,
stringHeapBytes,
userStringHeapBytes,
tableStreamBytes,
]);
return _composePEFile(
blobHeap: blobHeapBytes,
guidHeap: guidHeapBytes,
stringHeap: stringHeapBytes,
userStringHeap: userStringHeapBytes,
tableStream: tableStreamBytes,
);
}