本文整理汇总了C#中BlobBuilder.WriteCompressedSignedInteger方法的典型用法代码示例。如果您正苦于以下问题:C# BlobBuilder.WriteCompressedSignedInteger方法的具体用法?C# BlobBuilder.WriteCompressedSignedInteger怎么用?C# BlobBuilder.WriteCompressedSignedInteger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BlobBuilder
的用法示例。
在下文中一共展示了BlobBuilder.WriteCompressedSignedInteger方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SerializeSpans
private BlobHandle SerializeSpans(
ImmutableArray<SourceSpan> spans,
Dictionary<DebugSourceDocument, int> documentIndex)
{
if (spans.Length == 0)
{
return default(BlobHandle);
}
// 4 bytes per span plus a header, the builder expands by the same amount.
var writer = new BlobBuilder(4 + spans.Length * 4);
int previousStartLine = -1;
int previousStartColumn = -1;
DebugSourceDocument previousDocument = spans[0].Document;
// header:
writer.WriteCompressedInteger(GetOrAddDocument(previousDocument, documentIndex));
for (int i = 0; i < spans.Length; i++)
{
var currentDocument = spans[i].Document;
if (previousDocument != currentDocument)
{
writer.WriteInt16(0);
writer.WriteCompressedInteger(GetOrAddDocument(currentDocument, documentIndex));
previousDocument = currentDocument;
}
// Delta Lines & Columns:
SerializeDeltaLinesAndColumns(writer, spans[i]);
// delta Start Lines & Columns:
if (previousStartLine < 0)
{
Debug.Assert(previousStartColumn < 0);
writer.WriteCompressedInteger(spans[i].StartLine);
writer.WriteCompressedInteger(spans[i].StartColumn);
}
else
{
writer.WriteCompressedSignedInteger(spans[i].StartLine - previousStartLine);
writer.WriteCompressedSignedInteger(spans[i].StartColumn - previousStartColumn);
}
previousStartLine = spans[i].StartLine;
previousStartColumn = spans[i].StartColumn;
}
return GetOrAddBlob(writer);
}
示例2: CompressSignedIntegersFromSpecExamples
public void CompressSignedIntegersFromSpecExamples()
{
// These examples are straight from the CLI spec.
TestCompressedSignedInteger(new byte[] { 0x00 }, 0);
TestCompressedSignedInteger(new byte[] { 0x02 }, 1);
TestCompressedSignedInteger(new byte[] { 0x06 }, 3);
TestCompressedSignedInteger(new byte[] { 0x7f }, -1);
TestCompressedSignedInteger(new byte[] { 0x7b }, -3);
TestCompressedSignedInteger(new byte[] { 0x80, 0x80 }, 64);
TestCompressedSignedInteger(new byte[] { 0x01 }, -64);
TestCompressedSignedInteger(new byte[] { 0xC0, 0x00, 0x40, 0x00 }, 8192);
TestCompressedSignedInteger(new byte[] { 0x80, 0x01 }, -8192);
TestCompressedSignedInteger(new byte[] { 0xDF, 0xFF, 0xFF, 0xFE }, 268435455);
TestCompressedSignedInteger(new byte[] { 0xC0, 0x00, 0x00, 0x01 }, -268435456);
var writer = new BlobWriter(4);
var builder = new BlobBuilder();
Assert.Throws<ArgumentOutOfRangeException>(() => writer.WriteCompressedSignedInteger(BlobWriterImpl.MinSignedCompressedIntegerValue - 1));
Assert.Throws<ArgumentOutOfRangeException>(() => writer.WriteCompressedSignedInteger(BlobWriterImpl.MaxSignedCompressedIntegerValue + 1));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.WriteCompressedSignedInteger(BlobWriterImpl.MinSignedCompressedIntegerValue - 1));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.WriteCompressedSignedInteger(BlobWriterImpl.MaxSignedCompressedIntegerValue + 1));
}
示例3: SerializeDeltaLinesAndColumns
private void SerializeDeltaLinesAndColumns(BlobBuilder writer, SourceSpan span)
{
int deltaLines = span.EndLine - span.StartLine;
int deltaColumns = span.EndColumn - span.StartColumn;
// spans can't have zero width
Debug.Assert(deltaLines != 0 || deltaColumns != 0);
writer.WriteCompressedInteger(deltaLines);
if (deltaLines == 0)
{
writer.WriteCompressedInteger(deltaColumns);
}
else
{
writer.WriteCompressedSignedInteger(deltaColumns);
}
}
示例4: TestCompressedSignedInteger
private static void TestCompressedSignedInteger(byte[] expected, int value)
{
var writer = new BlobWriter(4);
writer.WriteCompressedSignedInteger(value);
AssertEx.Equal(expected, writer.ToArray());
var builder = new BlobBuilder();
builder.WriteCompressedSignedInteger(value);
AssertEx.Equal(expected, builder.ToArray());
}