Esempio n. 1
0
 /// <summary>
 /// Initializes a new <see cref="TlvBlock"/> from received data
 /// </summary>
 /// <param name="data">A received data buffer</param>
 /// <param name="startIndex">The start of the TLV block in the data buffer</param>
 /// <param name="readLength">The length of the TLV block in the data buffer</param>
 public TlvBlock(byte[] data, int startIndex, int readLength)
 {
     wasReceived = true;
     int endIndex = startIndex + readLength;
     while (startIndex < endIndex)
     {
         Tlv tlv = new Tlv();
         tlv.TypeNumber = (ushort)((data[startIndex] << 8) | data[startIndex + 1]);
         startIndex += 2;
         tlv.DataSize = (ushort)((data[startIndex] << 8) | data[startIndex + 1]);
         startIndex += 2;
         tlv.Data = new byte[tlv.DataSize];
         Array.Copy(data, startIndex, tlv.Data, 0, tlv.DataSize);
         startIndex += tlv.DataSize;
         tlvList.Add(tlv);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new <see cref="TlvBlock"/> from received data
        /// </summary>
        /// <param name="data">A received data buffer</param>
        /// <param name="startIndex">The start of the TLV block in the data buffer</param>
        /// <param name="readLength">The length of the TLV block in the data buffer</param>
        public TlvBlock(byte[] data, int startIndex, int readLength)
        {
            wasReceived = true;
            int endIndex = startIndex + readLength;

            while (startIndex < endIndex)
            {
                Tlv tlv = new Tlv();
                tlv.TypeNumber = (ushort)((data[startIndex] << 8) | data[startIndex + 1]);
                startIndex    += 2;
                tlv.DataSize   = (ushort)((data[startIndex] << 8) | data[startIndex + 1]);
                startIndex    += 2;
                tlv.Data       = new byte[tlv.DataSize];
                Array.Copy(data, startIndex, tlv.Data, 0, tlv.DataSize);
                startIndex += tlv.DataSize;
                tlvList.Add(tlv);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Reads one tlv in a tlv block
        /// </summary>
        /// <param name="typeCode">the typecode of the tlv</param>
        /// <returns>the tlv object</returns>
        public Tlv ReadTlv(int typeCode)
        {
            int counter = 0;
            Tlv retVal  = null;

            foreach (Tlv tlv in tlvList)
            {
                if (tlv.TypeNumber == typeCode)
                {
                    retVal = tlv;
                    counter++;
                }
            }
            if (counter != 1)
            {
                throw new ApplicationException(
                          "Invalid method call 'TlvBlock.ReadTlv(int)'. There are '" + counter +
                          "' tlvs with the typecode '" + typeCode +
                          ". But only one tlv with this code was expected");
            }
            return(retVal);
        }