當前位置: 首頁>>代碼示例>>C#>>正文


C# BitReader.ReadBytes方法代碼示例

本文整理匯總了C#中BitReader.ReadBytes方法的典型用法代碼示例。如果您正苦於以下問題:C# BitReader.ReadBytes方法的具體用法?C# BitReader.ReadBytes怎麽用?C# BitReader.ReadBytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在BitReader的用法示例。


在下文中一共展示了BitReader.ReadBytes方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ToMes

        public static Message ToMes(byte[] bt)
        {
            if (bt.Length < 2)
            {
                return null;
            }
            MemoryStream ms = new MemoryStream();
            //轉義
            for (var i = 1; i < bt.Length; i++)//收尾0x7e 不處理
            {
                if (bt[i] == 0x7d && (i + 1) < bt.Length)
                {
                    var isAnd = false;
                    if (bt[i + 1] == 0x02)
                    {
                        ms.WriteByte(0x7e);
                        isAnd = true;
                    }
                    else if (bt[i + 1] == 0x01)
                    {
                        ms.WriteByte(0x7d);
                        isAnd = true;
                    }
                    if (isAnd)
                    {
                        i += 1;
                    }
                }
                else
                {
                    ms.WriteByte(bt[i]);
                }

            }
            ms.Seek(0, SeekOrigin.Begin);
            BitReader br=new BitReader(ms);
            var mes = new Message();
            mes.Head.MessageId = br.ReadUInt16();
            mes.Head.BodyProp = br.ReadBytes(2);
            mes.Head.Tel = br.ReadBCD();

            mes.Head.NumSeq = br.ReadUInt16();

            if (mes.Head.isLong)
            {
                mes.Head.MesPackNum = br.ReadBytes(4);
            }
            var content = br.ReadBytes(mes.Head.contentLength);
            mes.BodyBytes=content;
            return mes;
        }
開發者ID:treejames,項目名稱:carterminal,代碼行數:51,代碼來源:Message.cs

示例2: GpsAppend

 /// <summary>
 /// GPS補錄
 /// </summary>
 /// <param name="from"></param>
 private void GpsAppend(Message from)
 {
     var ms = new MemoryStream(from.BodyBytes);
     var read = new BitReader(ms);
     var count = read.ReadUInt16();//位置信息個數
     var type = read.ReadByte();//0:正常位置批量匯報,1:盲區補報
     for (var i = 0; i < count; i++)
     {
         var gpsLength = read.ReadUInt16();
         var bytes = read.ReadBytes(gpsLength);
         this.ReadGPS(bytes);
     }
     this.NormalMes(from, 0);
 }
開發者ID:treejames,項目名稱:carterminal,代碼行數:18,代碼來源:Protocol.cs

示例3: Deserialize

        public static ActorState Deserialize(int maxChannels, List<ActorState> existingActorStates, List<ActorState> frameActorStates, string[] objectIndexToName, IDictionary<string, ClassNetCache> classNetCacheByName, UInt32 versionMajor, UInt32 versionMinor, BitReader br)
        {
            var startPosition = br.Position;
            ActorState a = new ActorState();

            try
            {
                var actorId = br.ReadUInt32Max(maxChannels);

                a.Id = actorId;

                if (br.ReadBit())
                {
                    if (br.ReadBit())
                    {
                        a.State = ActorStateState.New;

                        if (versionMajor > 868 || (versionMajor == 868 && versionMinor >= 14))
                        {
                            a.NameId = br.ReadUInt32();
                        }

                        a.Unknown1 = br.ReadBit();
                        a.TypeId = br.ReadUInt32();

                        a.TypeName = objectIndexToName[(int)a.TypeId.Value];
                        a._classNetCache = ObjectNameToClassNetCache(a.TypeName, classNetCacheByName);
                        a.ClassName = objectIndexToName[a._classNetCache.ObjectIndex];

                        if ( !ClassHasInitialPosition(a.ClassName))
                        {
            #if DEBUG
                            a.KnownBits = br.GetBits(startPosition, br.Position - startPosition);
                            a.Complete = true;
            #endif
                            return a;
                        }

                        a.Position = Vector3D.Deserialize(br);

                        if (ClassHasRotation(a.ClassName))
                        {
                            a.Rotation = Rotator.Deserialize(br);
                        }
            #if DEBUG
                        a.Complete = true;
            #endif
                    }
                    else
                    {
                        a.State = ActorStateState.Existing;
                        var oldState = existingActorStates.Where(x => x.Id == a.Id).Single();

                        a.TypeId = oldState.TypeId;

                        a.Properties = new List<ActorStateProperty>();
                        ActorStateProperty lastProp = null;
                        while (br.ReadBit())
                        {
                            lastProp = ActorStateProperty.Deserialize(oldState._classNetCache, oldState.TypeName, objectIndexToName, versionMajor, versionMinor, br);
                            a.Properties.Add(lastProp);

            #if DEBUG
                            if (!lastProp.IsComplete)
                            {
                                break;
                            }
            #endif
                        }

            #if DEBUG
                        a.Complete = lastProp.IsComplete;
                        if (lastProp.Data.Count > 0 && lastProp.Data.Last().ToString() == "FAILED")
                        {
                            a.Failed = true;
                        }
            #endif
                        var endPosition = br.Position;
                    }
                }
                else
                {
                    a.State = ActorStateState.Deleted;

                    var actor = existingActorStates.Where(x => x.Id == a.Id).SingleOrDefault();
            #if DEBUG
                    a.Complete = true;
            #endif
                    var endPosition = br.Position;
                }
            #if DEBUG
                if (!a.Complete)
                {
                    // Read a bunch of data so we have something to look at in the logs
                    // Otherwise the logs may not show any data bits for whatever is broken, which is hard to interpret
                    br.ReadBytes(16);
                }

                a.KnownBits = br.GetBits(startPosition, br.Position - startPosition);
            #endif
//.........這裏部分代碼省略.........
開發者ID:jjbott,項目名稱:RocketLeagueReplayParser,代碼行數:101,代碼來源:ActorState.cs

示例4: Driver

        /*
                *
                * 0x00:IC 卡讀卡成功;
            0x01:讀卡失敗,原因為卡片密鑰認證未通過;
            0x02:讀卡失敗,原因為卡片已被鎖定;
            0x03:讀卡失敗,原因為卡片被拔出;
            0x04:讀卡失敗,原因為數據校驗錯誤。

                *
                *
                * */
        private void Driver(Message from)
        {
            var body = from.BodyBytes;
            MemoryStream ms = new MemoryStream(body);
            BitReader br = new BitReader(ms);
            var state=br.ReadByte();
            var driver = new Driver();
            var time = br.ReadDateTime();//讀取打卡時間
            driver.state = 0;
            if (state == 0x01)//終端時間未校準 使用服務器時間
            {
                time = DateTime.Now;
            }

                var ic = br.ReadByte();

                if (ic.Equals(0x00))//讀卡成功
                {
                    //隻有certificate  序列號讀到
                    var driverNameLength = br.ReadByte();
                    var driverName = br.ReadString(driverNameLength);
                    var certBytes = br.ReadBytes(20);//從業資格證
                    var nBytes=new byte[4];
                    Array.Copy(certBytes,16,nBytes,0,4);
                    var certificate = BitConverter.ToUInt32(nBytes,0)+"";
                    //certificate
                    var licenceLength = br.ReadByte();//發證機關名稱長度
                    var licenceName = br.ReadString(licenceLength);//發證機關名稱
                    var certificateVaDate = DateTime.Now; //br.ReadDate();//證件有效期 讀不到

                    driver.driverName=driverName;
                    driver.certificate = certificate;
                    driver.licenceName=licenceName;
                    driver.certificateVaDate=certificateVaDate;

                }

            driver.time = time;
            this.EventDriver(driver);
        }
開發者ID:treejames,項目名稱:carterminal,代碼行數:51,代碼來源:Protocol.cs


注:本文中的BitReader.ReadBytes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。