public override void ParseBytes(byte[] bytes) { int startIndex = 0; // 消息类型 this.FrameType = (SaiFrameType)bytes[startIndex++]; // 序列号 this.SequenceNo = RsspEncoding.ToHostUInt16(bytes, startIndex); startIndex += 2; // Padding startIndex += SaiFrame.TtsPaddingLength; // 初始值 this.InitialValue = RsspEncoding.ToHostUInt32(bytes, startIndex); startIndex += 4; // 版本 this.Version = RsspEncoding.ToHostUInt32(bytes, startIndex); startIndex += 4; // EC周期 this.Interval = RsspEncoding.ToHostUInt16(bytes, startIndex); }
public override void ParseBytes(byte[] bytes) { int startIndex = 0; // 消息类型 this.FrameType = (SaiFrameType)bytes[startIndex++]; // 序列号 this.SequenceNo = RsspEncoding.ToHostUInt16(bytes, startIndex); startIndex += 2; // sender timestamp this.SenderTimestamp = RsspEncoding.ToHostUInt32(bytes, startIndex); startIndex += 4; // Responsor last timestamp this.ReceiverLastSendTimestamp = RsspEncoding.ToHostUInt32(bytes, startIndex); startIndex += 4; // sender last timestamp this.SenderLastRecvTimestamp = RsspEncoding.ToHostUInt32(bytes, startIndex); startIndex += 4; // user data var len = bytes.Length - startIndex; if (len > 0) { this.UserData = new byte[len]; Array.Copy(bytes, startIndex, this.UserData, 0, len); } }
public override void ParseBytes(byte[] bytes) { int startIndex = 0; // 消息类型 this.FrameType = (SaiFrameType)bytes[startIndex++]; // 序列号 this.SequenceNo = RsspEncoding.ToHostUInt16(bytes, startIndex); startIndex += 2; // Padding startIndex += SaiFrame.TtsPaddingLength; // EC计数 this.EcValue = RsspEncoding.ToHostUInt32(bytes, startIndex); startIndex += 4; // user data var len = bytes.Length - startIndex; if (len > 0) { this.UserData = new byte[len]; Array.Copy(bytes, startIndex, this.UserData, 0, len); } }
public override void ParseBytes(byte[] bytes) { int startIndex = 0; // 消息类型 this.FrameType = (SaiFrameType)bytes[startIndex++]; // 序列号 this.SequenceNo = RsspEncoding.ToHostUInt16(bytes, startIndex); startIndex += 2; // sender timestamp this.SenderTimestamp = RsspEncoding.ToHostUInt32(bytes, startIndex); startIndex += 4; // Responsor last timestamp this.ReceiverLastSendTimestamp = RsspEncoding.ToHostUInt32(bytes, startIndex); startIndex += 4; // sender last timestamp this.SenderLastRecvTimestamp = RsspEncoding.ToHostUInt32(bytes, startIndex); startIndex += 4; // valid this.Valid = (bytes[startIndex++] == 1); }
private ushort GetPacketLength(byte[] buffer, int startIndex) { if ((buffer == null) || (buffer.Length - startIndex < 2)) { return(0); } return(RsspEncoding.ToHostUInt16(buffer, startIndex)); }
/// <summary> /// 解析指定的字节流。 /// </summary> public void ParseBytes(byte[] bytes) { if (bytes == null || bytes.Length < AleFrame.HeadLength) { throw new AleFrameParsingException("无法将指定的字节流解析为AleFrame,长度不够。"); } int startIndex = 0; // 包长度 var pktLen = RsspEncoding.ToHostUInt16(bytes, startIndex); startIndex += AleFrame.SizeofHeadLen; // 版本 this.Version = bytes[startIndex++]; // 应用类型 this.ApplicationType = bytes[startIndex++]; // 传输序列号 this.SequenceNo = RsspEncoding.ToHostUInt16(bytes, startIndex); startIndex += 2; // N/R标志 this.IsNormal = (bytes[startIndex++] == 1); // 包类型 this.FrameType = (AleFrameType)bytes[startIndex++]; // 校验和 if (this.FrameType != AleFrameType.KAA && this.FrameType != AleFrameType.KANA) // 生命信息不需要校验 { //var actualCrcValue = BitConverter.ToUInt16(bytes, startIndex); var actualCrcValue = RsspEncoding.ToHostUInt16(bytes, startIndex); var expectedCrcValue = CrcTool.CaculateCCITT16(bytes, 0, 8); if (actualCrcValue != expectedCrcValue) { throw new AleFrameParsingException(string.Format("解析Ale协议帧时发生异常,CRC检验不一致,期望值是{0},实际值是{1}。", expectedCrcValue, actualCrcValue)); } } startIndex += 2; // 用户数据 var userDataLen = pktLen - (AleFrame.HeadLength - AleFrame.SizeofHeadLen); if (userDataLen < 0) { throw new AleFrameParsingException(string.Format("将字节流解析为ALE帧时发生异常,用户数据长度为负值{0}。", userDataLen)); } this.UserData = AleUserData.Parse(this.FrameType, bytes, startIndex, startIndex + userDataLen - 1); }
public override void ParseBytes(byte[] bytes) { int startIndex = 0; // 消息类型 this.FrameType = (SaiFrameType)bytes[startIndex++]; // 序列号 this.SequenceNo = RsspEncoding.ToHostUInt16(bytes, startIndex); startIndex += 2; // sender timestamp this.SenderTimestamp = RsspEncoding.ToHostUInt32(bytes, startIndex); startIndex += 4; // Responsor last timestamp this.ReceiverLastSendTimestamp = RsspEncoding.ToHostUInt32(bytes, startIndex); startIndex += 4; // sender last timestamp this.SenderLastRecvTimestamp = RsspEncoding.ToHostUInt32(bytes, startIndex); startIndex += 4; // 偏移标志 bool negative = (bytes[startIndex] == 1); startIndex++; // |最小偏移值| this.OffsetMin = RsspEncoding.ToHostUInt32(bytes, startIndex); if (negative) { this.OffsetMin = -this.OffsetMin; } startIndex += 4; // 偏移标志 negative = (bytes[startIndex] == 1); startIndex++; // |最大偏移值| this.OffsetMax = RsspEncoding.ToHostUInt32(bytes, startIndex); if (negative) { this.OffsetMax = -this.OffsetMax; } startIndex += 4; }