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


C# BlobBuilder.ReserveBytes方法代码示例

本文整理汇总了C#中Microsoft.Cci.BlobBuilder.ReserveBytes方法的典型用法代码示例。如果您正苦于以下问题:C# BlobBuilder.ReserveBytes方法的具体用法?C# BlobBuilder.ReserveBytes怎么用?C# BlobBuilder.ReserveBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Cci.BlobBuilder的用法示例。


在下文中一共展示了BlobBuilder.ReserveBytes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReserveBytes2

        public void ReserveBytes2()
        {
            var builder = new BlobBuilder(16);
            var writer = 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].GetUnderlyingBuffer().ToArray());
        }
开发者ID:rgani,项目名称:roslyn,代码行数:15,代码来源:BlobTests.cs

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

示例3: ReserveBytes1

        public void ReserveBytes1()
        {
            var builder = new BlobBuilder(16);
            var writer0 = builder.ReserveBytes(0);
            var writer1 = builder.ReserveBytes(1);
            var writer2 = 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);
        }
开发者ID:rgani,项目名称:roslyn,代码行数:20,代码来源:BlobTests.cs

示例4: SerializeRecord

        private static BlobBuilder SerializeRecord(byte kind, Action<BlobBuilder> data)
        {
            var cmw = new BlobBuilder();
            cmw.WriteByte(CDI.CdiVersion);
            cmw.WriteByte(kind);
            cmw.WriteByte(0);

            // alignment size and length (will be patched)
            var alignmentSizeAndLengthWriter = cmw.ReserveBytes(sizeof(byte) + sizeof(uint));

            data(cmw);

            int length = cmw.Position;
            int alignedLength = 4 * ((length + 3) / 4);
            byte alignmentSize = (byte)(alignedLength - length);
            cmw.WriteBytes(0, alignmentSize);

            // fill in alignment size and length:
            alignmentSizeAndLengthWriter.WriteByte(alignmentSize);
            alignmentSizeAndLengthWriter.WriteUInt32((uint)alignedLength);

            return cmw;
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:23,代码来源:CustomDebugInfoWriter.cs


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