當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。