コード例 #1
0
        /// <summary>
        /// The AnnounceResponse constructor expects a byte array of at least 21 elements,
        /// 4 bytes for RequestID, 8 bytes for EpochTime, 4 bytes for DeviceDescriptionLength, and a
        /// minimum of 5 bytes for the KL (key and length) parts of the StatusResponse KLV.   The
        /// DeviceDescription and StatusMessage (the V in the KLV) are of variable length and will add to the
        /// 21 byte minimum.
        /// </summary>
        /// <param name="inputArray">Byte pack that is decoded in to the Announce Response</param>
        public AcspAnnounceResponse(Byte[] inputArray)
        {
            if (inputArray.Length < 21)
            {
                throw new ArgumentOutOfRangeException("Error: was expecting at least a 21-byte array for AnnounceResponse constructor");
            }

            // Take 4-byte slice and convert to UInt32 for RequestId
            int i = 0;

            Byte[] data = new Byte[4];
            Array.Copy(inputArray, 0, data, 0, data.Length);
            i          = i + data.Length;
            _requestId = new AcspRequestId(data);

            // Take 8 byte slice and convert to Int64 for CurrentTime
            data = new Byte[8];
            Array.Copy(inputArray, i, data, 0, data.Length);
            i = i + data.Length;
            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(data);
            }
            _currentTime = BitConverter.ToInt64(data, 0);

            // Take 4 byte slice and convert to AcspBerLength
            data = new Byte[4];
            Array.Copy(inputArray, i, data, 0, data.Length);
            i = i + data.Length;
            _deviceDescriptionLength = new AcspBerLength(data);

            // Take variable-length byte slice and convert UTF-8 string
            int length = _deviceDescriptionLength.Length;

            if (length > 0)
            {
                data = new Byte[length];
                Array.Copy(inputArray, i, data, 0, data.Length);
                i = i + data.Length;
                _deviceDescription = Encoding.UTF8.GetString(data);
            }

            // Take variable-length (but at least 5 bytes) slice and convert to AcspStatusResponse
            int statusLength = inputArray.Length - i;

            data = new Byte[statusLength];
            Array.Copy(inputArray, i, data, 0, data.Length);
            _statusResponse = new AcspStatusResponse(data);
        }
コード例 #2
0
        private void InitializeData(byte[] inputArray)
        {
            if (inputArray.Length < 9)  // Expect at least a 9-byte array for RequestId + 5 bytes minimum for StatusResponse KLV
            {
                throw new ArgumentOutOfRangeException("Error:  was expecting at least a 9-byte array for UpdateTimelineResponse");
            }

            // take a 4-byte slice and convert UInt32 for RequestId
            int i = 0;  // indexer for inputArray

            Byte[] data = new Byte[4];
            Array.Copy(inputArray, i, data, 0, data.Length);
            i          = i + data.Length;
            _requestId = new AcspRequestId(data);

            // take variable-length (but at least 5 bytes) slice and convert to AcspStatusResponse
            int statusLength = inputArray.Length - i;

            data = new Byte[statusLength];
            Array.Copy(inputArray, i, data, 0, data.Length);
            i = i + data.Length;
            _statusResponse = new AcspStatusResponse(data);
        }