/// <summary> /// Deletes any details currently stored in the record /// and re-initializes them by parsing the contents of the payload. /// </summary> private void ParsePayloadToData(byte[] payload) { if (payload == null || payload.Length < 2) { //throw new NdefException(NdefExceptionMessages.ExHandoverErrorInvalidSourceData); } var m = new MemoryStream(payload); // Reset values _carrierDataReference = null; _auxiliaryDataReferenceList = null; // Byte 0: Carrier power state (last two bits) var cps = (byte)(m.ReadByte() & 0x03); _carrierPowerState = Enum.IsDefined(typeof(CarrierPowerStates), cps) ? (CarrierPowerStates)cps : CarrierPowerStates.Unknown; // Carrier data reference // Byte 1: Carrier Data Reference Length var cdrLength = m.ReadByte(); // Bytes 2+: Carrier Data Reference var cdrBytes = new byte[cdrLength]; m.Read(cdrBytes, 0, cdrLength); _carrierDataReference = cdrBytes; // Auxiliary Data Reference(s) // Byte 1: Number of auxiliary data references var numAdr = m.ReadByte(); if (numAdr > 0) { _auxiliaryDataReferenceList = new List <byte[]>(numAdr); // Bytes 2+: the auxiliary data references for (int i = 0; i < numAdr; i++) { // Length of this data reference (1 byte) var curAdrLength = m.ReadByte(); // Data reference var curAdrBytes = new byte[curAdrLength]; m.Read(curAdrBytes, 0, curAdrLength); _auxiliaryDataReferenceList.Add(curAdrBytes); } } }
/// <summary> /// Deletes any details currently stored in the record /// and re-initializes them by parsing the contents of the payload. /// </summary> private void ParsePayloadToData(byte[] payload) { if (payload == null || payload.Length < 2) { //throw new NdefException(NdefExceptionMessages.ExHandoverErrorInvalidSourceData); } var m = new MemoryStream(payload); // Reset values _carrierDataReference = null; _auxiliaryDataReferenceList = null; // Byte 0: Carrier power state (last two bits) var cps = (byte)(m.ReadByte() & 0x03); _carrierPowerState = Enum.IsDefined(typeof(CarrierPowerStates), cps) ? (CarrierPowerStates)cps : CarrierPowerStates.Unknown; // Carrier data reference // Byte 1: Carrier Data Reference Length var cdrLength = m.ReadByte(); // Bytes 2+: Carrier Data Reference var cdrBytes = new byte[cdrLength]; m.Read(cdrBytes, 0, cdrLength); _carrierDataReference = cdrBytes; // Auxiliary Data Reference(s) // Byte 1: Number of auxiliary data references var numAdr = m.ReadByte(); if (numAdr > 0) { _auxiliaryDataReferenceList = new List<byte[]>(numAdr); // Bytes 2+: the auxiliary data references for (int i = 0; i < numAdr; i++) { // Length of this data reference (1 byte) var curAdrLength = m.ReadByte(); // Data reference var curAdrBytes = new byte[curAdrLength]; m.Read(curAdrBytes, 0, curAdrLength); _auxiliaryDataReferenceList.Add(curAdrBytes); } } }