当前位置: 首页>>代码示例>>C#>>正文


C# BlobBuilder.WriteCompressedSignedInteger方法代码示例

本文整理汇总了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);
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:51,代码来源:MetadataWriter.DynamicAnalysis.cs

示例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));
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:23,代码来源:BlobTests.cs

示例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);
            }
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:19,代码来源:MetadataWriter.DynamicAnalysis.cs

示例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());
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:10,代码来源:BlobTests.cs


注:本文中的BlobBuilder.WriteCompressedSignedInteger方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。