本文整理汇总了C#中BlobBuilder.ReserveBytes方法的典型用法代码示例。如果您正苦于以下问题:C# BlobBuilder.ReserveBytes方法的具体用法?C# BlobBuilder.ReserveBytes怎么用?C# BlobBuilder.ReserveBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BlobBuilder
的用法示例。
在下文中一共展示了BlobBuilder.ReserveBytes方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SerializeStandalonePdbStream
/// <summary>
/// Serialized #Pdb stream.
/// </summary>
protected override void SerializeStandalonePdbStream(BlobBuilder builder)
{
int startPosition = builder.Count;
// the id will be filled in later
_pdbIdBlob = builder.ReserveBytes(MetadataSizes.PdbIdSize);
builder.WriteInt32(_entryPoint.IsNil ? 0 : MetadataTokens.GetToken(_entryPoint));
builder.WriteUInt64(MetadataSizes.ExternalTablesMask);
MetadataWriterUtilities.SerializeRowCounts(builder, MetadataSizes.ExternalRowCounts);
int endPosition = builder.Count;
Debug.Assert(MetadataSizes.CalculateStandalonePdbStreamSize() == endPosition - startPosition);
}
示例2: WriteCoffHeader
private void WriteCoffHeader(BlobBuilder builder, ImmutableArray<SerializedSection> sections, out Blob stampFixup)
{
// Machine
builder.WriteUInt16((ushort)(Machine == 0 ? Machine.I386 : Machine));
// NumberOfSections
builder.WriteUInt16((ushort)sections.Length);
// TimeDateStamp:
stampFixup = builder.ReserveBytes(sizeof(uint));
// PointerToSymbolTable (TODO: not supported):
// The file pointer to the COFF symbol table, or zero if no COFF symbol table is present.
// This value should be zero for a PE image.
builder.WriteUInt32(0);
// NumberOfSymbols (TODO: not supported):
// The number of entries in the symbol table. This data can be used to locate the string table,
// which immediately follows the symbol table. This value should be zero for a PE image.
builder.WriteUInt32(0);
// SizeOfOptionalHeader:
// The size of the optional header, which is required for executable files but not for object files.
// This value should be zero for an object file (TODO).
builder.WriteUInt16((ushort)(Is32Bit ? 224 : 240));
// Characteristics
builder.WriteUInt16((ushort)ImageCharacteristics);
}
示例3: SerializeWin32Resources
public static void SerializeWin32Resources(BlobBuilder builder, ResourceSection resourceSections, int resourcesRva)
{
var sectionWriter = new BlobWriter(builder.ReserveBytes(resourceSections.SectionBytes.Length));
sectionWriter.WriteBytes(resourceSections.SectionBytes);
var readStream = new MemoryStream(resourceSections.SectionBytes);
var reader = new BinaryReader(readStream);
foreach (int addressToFixup in resourceSections.Relocations)
{
sectionWriter.Offset = addressToFixup;
reader.BaseStream.Position = addressToFixup;
sectionWriter.WriteUInt32(reader.ReadUInt32() + (uint)resourcesRva);
}
}
示例4: WriteBlobHeap
private void WriteBlobHeap(BlobBuilder builder)
{
var writer = new BlobWriter(builder.ReserveBytes(_blobHeapSize));
// Perf consideration: With large heap the following loop may cause a lot of cache misses
// since the order of entries in _blobs dictionary depends on the hash of the array values,
// which is not correlated to the heap index. If we observe such issue we should order
// the entries by heap position before running this loop.
foreach (var entry in _blobs)
{
int heapOffset = MetadataTokens.GetHeapOffset(entry.Value);
var blob = entry.Key;
writer.Offset = heapOffset;
writer.WriteCompressedInteger(blob.Length);
writer.WriteBytes(blob);
}
}
示例5: ReserveBytes2
public void ReserveBytes2()
{
var builder = new BlobBuilder(16);
var writer = new BlobWriter(builder.ReserveBytes(17));
writer.WriteBytes(1, 17);
var blobs = builder.GetBlobs().ToArray();
Assert.Equal(1, blobs.Length);
AssertEx.Equal(new byte[]
{
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01
}, blobs[0].GetBytes().ToArray());
}
示例6: ReserveBytes1
public void ReserveBytes1()
{
var builder = new BlobBuilder(16);
var writer0 = new BlobWriter(builder.ReserveBytes(0));
var writer1 = new BlobWriter(builder.ReserveBytes(1));
var writer2 = new BlobWriter(builder.ReserveBytes(2));
Assert.Equal(3, builder.Count);
AssertEx.Equal(new byte[] { 0, 0, 0 }, builder.ToArray());
Assert.Equal(0, writer0.Length);
Assert.Equal(0, writer0.RemainingBytes);
writer1.WriteBoolean(true);
Assert.Equal(1, writer1.Length);
Assert.Equal(0, writer1.RemainingBytes);
writer2.WriteByte(1);
Assert.Equal(2, writer2.Length);
Assert.Equal(1, writer2.RemainingBytes);
}
示例7: Link
public void Link()
{
var builder1 = new BlobBuilder(16);
builder1.WriteByte(1);
var builder2 = new BlobBuilder(16);
builder2.WriteByte(2);
var builder3 = new BlobBuilder(16);
builder3.WriteByte(3);
var builder4 = new BlobBuilder(16);
builder4.WriteByte(4);
var builder5 = new BlobBuilder(16);
builder5.WriteByte(5);
builder2.LinkPrefix(builder1);
AssertEx.Equal(new byte[] { 1, 2 }, builder2.ToArray());
Assert.Throws<InvalidOperationException>(() => builder1.ToArray());
Assert.Throws<InvalidOperationException>(() => builder2.LinkPrefix(builder1));
Assert.Throws<InvalidOperationException>(() => builder1.WriteByte(0xff));
Assert.Throws<InvalidOperationException>(() => builder1.WriteBytes(1, 10));
Assert.Throws<InvalidOperationException>(() => builder1.WriteBytes(new byte[] { 1 }));
Assert.Throws<InvalidOperationException>(() => builder1.ReserveBytes(1));
Assert.Throws<InvalidOperationException>(() => builder1.GetBlobs());
Assert.Throws<InvalidOperationException>(() => builder1.ContentEquals(builder1));
Assert.Throws<InvalidOperationException>(() => builder1.WriteUTF16("str"));
Assert.Throws<InvalidOperationException>(() => builder1.WriteUTF8("str", allowUnpairedSurrogates: false));
builder2.LinkSuffix(builder3);
AssertEx.Equal(new byte[] { 1, 2, 3 }, builder2.ToArray());
Assert.Throws<InvalidOperationException>(() => builder3.LinkPrefix(builder5));
builder2.LinkPrefix(builder4);
AssertEx.Equal(new byte[] { 4, 1, 2, 3 }, builder2.ToArray());
Assert.Throws<InvalidOperationException>(() => builder4.LinkPrefix(builder5));
builder2.LinkSuffix(builder5);
AssertEx.Equal(new byte[] { 4, 1, 2, 3, 5 }, builder2.ToArray());
}
示例8: LinkSuffix_Empty3
public void LinkSuffix_Empty3()
{
var builder1 = new BlobBuilder(16);
builder1.ReserveBytes(16);
builder1.ReserveBytes(0);
var builder2 = new BlobBuilder(16);
builder2.ReserveBytes(16);
builder2.ReserveBytes(0);
builder1.LinkSuffix(builder2);
AssertEx.Equal(new byte[]
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}, builder1.ToArray());
Assert.Equal(32, builder1.Count);
Assert.Equal(16, builder2.Count);
}