本文整理汇总了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;
}
示例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);
}
示例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
//.........这里部分代码省略.........
示例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);
}