private void Decode(byte[] data) { Length = data[0]; if (Length > 127) { throw new Exception("Frame length should not exceed 127 bytes."); } if (data.Length - 1 != Length) { throw new Exception("Frame length is inconsistent"); } Type = (FrameType)(data[1] & 0x7); SecurityEnabled = (data[1] & 0x8) != 0; FramePending = (data[1] & 0x10) != 0; AcknowledgeRequest = (data[1] & 0x20) != 0; IntraPAN = (data[1] & 0x40) != 0; DestinationAddressingMode = (AddressingMode)((data[2] >> 2) & 0x3); FrameVersion = (byte)((data[2] >> 4) & 0x3); SourceAddressingMode = (AddressingMode)(data[2] >> 6); DataSequenceNumber = data[3]; AddressInformation = new AddressInformation(DestinationAddressingMode, SourceAddressingMode, IntraPAN, new ArraySegment <byte>(data, 4, GetAddressingFieldsLength())); Payload = new ArraySegment <byte>(data, 3 + AddressInformation.Bytes.Count, Length - (5 + AddressInformation.Bytes.Count)); }
private void Decode(byte[] data) { Length = data[0]; if(Length > 127) { throw new Exception("Frame length should not exceed 127 bytes."); } if(data.Length - 1 != Length) { throw new Exception("Frame length is inconsistent"); } Type = (FrameType)(data[1] & 0x7); SecurityEnabled = (data[1] & 0x8) != 0; FramePending = (data[1] & 0x10) != 0; AcknowledgeRequest = (data[1] & 0x20) != 0; IntraPAN = (data[1] & 0x40) != 0; DestinationAddressingMode = (AddressingMode)((data[2] >> 2) & 0x3); FrameVersion = (byte)((data[2] >> 4) & 0x3); SourceAddressingMode = (AddressingMode)(data[2] >> 6); DataSequenceNumber = data[3]; AddressInformation = new AddressInformation(DestinationAddressingMode, SourceAddressingMode, IntraPAN, new ArraySegment<byte>(data, 4, GetAddressingFieldsLength())); Payload = new ArraySegment<byte>(data, 3 + AddressInformation.Bytes.Count, Length - (5 + AddressInformation.Bytes.Count)); }