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


C# BitWriter类代码示例

本文整理汇总了C#中BitWriter的典型用法代码示例。如果您正苦于以下问题:C# BitWriter类的具体用法?C# BitWriter怎么用?C# BitWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: Decode

        public static byte[] Decode(byte[] data, int from, int to, int bitsInterval)
        {
            var copiedData = new byte[to - from + 1];
            Array.Copy(data, from, copiedData, 0, copiedData.Length);

            byte[] reverseBytes = Convert.ReverseBitsInBytes(copiedData);

            using (var s = new MemoryStream(reverseBytes))
            using (var reader = new BitReader(s))
            {
                using (var decoded = new MemoryStream())
                using (var writer = new BitWriter(decoded))
                {
                    int counter = 0;
                    while (reader.CanRead)
                    {
                        byte bit = reader.ReadBits(1);
                        writer.WriteBit(bit);
                        counter = (bit == 1) ? counter + 1 : 0;
                        if (counter == bitsInterval)
                        {
                            reader.ReadBits(1); // skip next 0 bit
                            counter = 0;
                        }
                    }

                    // !! do not flush last bits
                    return Convert.ReverseBitsInBytes(decoded.ToArray());
                }
            }
        }
开发者ID:anddudek,项目名称:anjlab.fx,代码行数:31,代码来源:Ax25.cs

示例2: GammaCode

        public static void GammaCode(ulong number, BitWriter writer)
        {
            // to allow zero
            number += 1;

            int size = 0;
            ulong tmp = number;

            while (tmp >= 1)
            {
                size++;
                tmp /= 2;
            }

            int zeroes = size - 1;

            for (int i = 0; i < zeroes; i++)
                writer.Write(false);

            for (int i = size - 1; i >= 0; i--)
            {
                bool bit = (number & (1UL << i)) != 0;
                writer.Write(bit);
            }
        }
开发者ID:svick,项目名称:Arithmetic-coding,代码行数:25,代码来源:Elias.cs

示例3: Encode

        public static byte[] Encode(byte[] data, int bitsInterval)
        {
            byte[] reverseBytes = Convert.ReverseBitsInBytes(data);

            using (var s = new MemoryStream(reverseBytes))
            using (var reader = new BitReader(s))
            {
                using (var encoded = new MemoryStream())
                using (var writer = new BitWriter(encoded))
                {
                    int counter = 0;
                    while (reader.CanRead)
                    {
                        byte bit = reader.ReadBits(1);
                        writer.WriteBit(bit);
                        counter = (bit == 1) ? counter + 1 : 0;
                        if (counter == bitsInterval)
                        {
                            writer.WriteBit(0);
                            counter = 0;
                        }
                    }

                    writer.FlushBits();
                    return Convert.ReverseBitsInBytes(encoded.ToArray());
                }
            }
        }
开发者ID:anddudek,项目名称:anjlab.fx,代码行数:28,代码来源:Ax25.cs

示例4: Serialize

        public override void Serialize( Stream stream )
        {
            base.Serialize( stream );

            var bw = new BitWriter();

            bw.WriteInt32( Protocol );
            bw.WriteInt32(AuthProtocol);

            bw.WriteInt32(ServerChallenge);
            bw.WriteInt32(ClientChallenge);

            bw.WriteString( Name );
            bw.WriteString( Password );

            bw.WriteByte( ( byte )Players.Count );

            foreach ( var player in Players )
            {
                bw.WriteByte( ( byte )CLC_Messages.clc_SplitPlayerConnect );
                using ( var ms = new MemoryStream() )
                {
                    Serializer.SerializeWithLengthPrefix( ms, player, PrefixStyle.Base128 );
                    bw.WriteBytes( ms.ToArray() );
                }
            }

            // bLowViolence
            bw.WriteBits( 0, 1 );

            bw.WriteUInt16( ( ushort )Ticket.Length );
            bw.WriteBytes( Ticket );

            stream.Write( bw.Data, 0, bw.Data.Length - 1 );
        }
开发者ID:KimimaroTsukimiya,项目名称:DotaBot,代码行数:35,代码来源:ClientAuthPacket.cs

示例5: Capture

        /*
         * 0 通道ID BYTE >0
        1 拍摄命令 WORD
        0 表示停止拍摄;0xFFFF 表示录像;其它表示拍
        照张数
        3 拍照间隔/录像时间 WORD 秒,0 表示按最小间隔拍照或一直录像
        5 保存标志 BYTE
        1:保存;
        0:实时上传
        6 分辨率a BYTE
        0x01:320*240;
        0x02:640*480;
        0x03:800*600;
        0x04:1024*768;
        0x05:176*144;[Qcif];
        0x06:352*288;[Cif];
        0x07:704*288;[HALF D1];
        0x08:704*576;[D1];
        7 图像/视频质量 BYTE 1-10,1 代表质量损失最小,10 表示压缩比最大
        8 亮度 BYTE 0-255
        9 对比度 BYTE 0-127
        10 饱和度 BYTE 0-127
        11 色度 BYTE 0-255
         *
         * */
        /// <summary>
        /// 中心抓拍图片
        /// </summary>
        /// <param name="ordinal"></param>
        /// <param name="size"></param>
        /// <param name="quality"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public override byte[] Capture(uint ordinal, SizeType size, QualityType quality, byte count)
        {
            var mes = Message.Create(0x8801, this.terminalid + "", 0, null);
            var ms = new MemoryStream();
            BitWriter bw = new BitWriter(ms);
            bw.Write((byte)1);//通道一
            bw.Write((UInt16)count);//拍一张
            bw.Write((UInt16)0);//拍照间隔
            bw.Write((byte)0);//0实时上传 1保存
            byte pixel = 0x01;
            switch (size) //分辨率 图片大小
            {
                case SizeType.Big: pixel = 0x04; break;   //
                case SizeType.Normal: pixel = 0x08; break; //
                case SizeType.Small: pixel = 0x01; break;  //
            }
            bw.Write(pixel);//分辨率

            byte level = 1;
            switch (quality) //图片质量
            {
                case QualityType.Height: level = 1; break;
                case QualityType.Normal: level = 5; break;
                case QualityType.Low: level = 10; break;
            }
            bw.Write(level);//图片质量
            bw.Write((byte)127);//亮度
            bw.Write((byte)64);//对比度
            bw.Write((byte)64);//饱和度
            bw.Write((byte)127);//色度
            mes.BodyBytes = ms.ToArray();
            return mes.ToBytes();
        }
开发者ID:treejames,项目名称:carterminal,代码行数:66,代码来源:Protocol.cs

示例6: Serialize

 public void Serialize(BitWriter bw)
 {
     bw.Write(TeamNumber);
     bw.Write(TeamColorId);
     bw.Write(CustomColorId);
     bw.Write(TeamFinishId);
     bw.Write(CustomFinishId);
 }
开发者ID:jjbott,项目名称:RocketLeagueReplayParser,代码行数:8,代码来源:TeamPaint.cs

示例7: Serialize

 public void Serialize(BitWriter bw)
 {
     bw.Write(Active);
     bw.Write(ActorId);
     Offset.Serialize(bw);
     bw.Write(Mass);
     Rotation.Serialize(bw);
 }
开发者ID:jjbott,项目名称:RocketLeagueReplayParser,代码行数:8,代码来源:WeldedInfo.cs

示例8: Serialize

 public void Serialize(BitWriter bw)
 {
     string.Join(",", Mutators).Serialize(bw);
     bw.Write(Unknown1);
     bw.Write(Unknown2);
     GameName.Serialize();
     Password.Serialize();
     bw.Write(Unknown3);
 }
开发者ID:jjbott,项目名称:RocketLeagueReplayParser,代码行数:9,代码来源:PrivateMatchSettings.cs

示例9: Serialize

 public void Serialize(BitWriter bw)
 {
     bw.Write(Unknown1);
     bw.Write(AttackerActorId);
     bw.Write(Unknown2);
     bw.Write(VictimActorId);
     AttackerVelocity.Serialize(bw);
     VictimVelocity.Serialize(bw);
 }
开发者ID:jjbott,项目名称:RocketLeagueReplayParser,代码行数:9,代码来源:ReplicatedDemolish.cs

示例10: Encode

        public void Encode(Stream reader, BitWriter writer)
        {
            if (!reader.CanRead || !reader.CanSeek)
                throw new InvalidOperationException();

            m_writer = writer;

            Encode(reader);
        }
开发者ID:svick,项目名称:Arithmetic-coding,代码行数:9,代码来源:Coder.cs

示例11: Serialize

 public void Serialize(BitWriter bw)
 {
     bw.Write(FieldOfView);
     bw.Write(Height);
     bw.Write(Pitch);
     bw.Write(Distance);
     bw.Write(Stiffness);
     bw.Write(SwivelSpeed);
 }
开发者ID:jjbott,项目名称:RocketLeagueReplayParser,代码行数:9,代码来源:CameraSettings.cs

示例12: Compress

        public static void Compress(string inputFile, string outputFile)
        {
            var coder = new Coder();

            using (var reader = File.OpenRead(inputFile))
            using (var writer = new BitWriter(outputFile))
            {
                coder.Encode(reader, writer);
            }
        }
开发者ID:svick,项目名称:Arithmetic-coding,代码行数:10,代码来源:ArithmeticCoding.cs

示例13: Serialize

        public void Serialize(BitWriter bw)
        {
            bw.Write(Sleeping);
            Position.Serialize(bw);
            Rotation.SerializeFixed(bw);

            if (!Sleeping)
            {
                LinearVelocity.Serialize(bw);
                AngularVelocity.Serialize(bw);
            }
        }
开发者ID:jjbott,项目名称:RocketLeagueReplayParser,代码行数:12,代码来源:RigidBodyState.cs

示例14: Serialize

 public void Serialize(BitWriter bw)
 {
     bw.Write((byte)ThingLists.Count);
     foreach (var thingList in ThingLists)
     {
         bw.Write((byte)thingList.Count);
         foreach(var thing in thingList)
         {
             thing.Serialize(bw);
             // "i >= 21" logic from Deserialize is handled automatically here. No special serialize logic needed.
         }
     }
 }
开发者ID:jjbott,项目名称:RocketLeagueReplayParser,代码行数:13,代码来源:ClientLoadoutOnline.cs

示例15: BitWriterEmptyTest

 public void BitWriterEmptyTest()
 {
     using (MemoryStream ms = new MemoryStream()) {
     BitWriter bw = new BitWriter()
     {
       Output = ms,
       CodeLength = 4,
     };
     bw.FlushBits();
     bw.FlushBytes();
     byte[] bytes = ms.ToArray();
     Assert.AreEqual(0, bytes.Length);
       }
 }
开发者ID:ewxrjk,项目名称:Defect,代码行数:14,代码来源:BitWriterTests.cs


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