Esempio n. 1
0
        /// <summary>
        /// Parse the message.
        /// </summary>
        /// <param name="byteData">The MPEG2 section containing the message.</param>
        /// <param name="index">Index of the first byte of the message in the MPEG2 section.</param>
        public virtual void Process(byte[] byteData, int index)
        {
            lastIndex = index;

            try
            {
                magic      = Utils.GetBytes(byteData, lastIndex, 4);
                lastIndex += 4;

                majorVersion = (int)byteData[lastIndex];
                lastIndex++;

                minorVersion = (int)byteData[lastIndex];
                lastIndex++;

                byteOrder = (int)byteData[lastIndex];
                lastIndex++;

                messageType = (int)byteData[lastIndex];
                lastIndex++;

                messageSize = Utils.Convert4BytesToInt(byteData, lastIndex);
                lastIndex  += 4;

                objectKeyLength = (int)byteData[lastIndex];
                lastIndex++;

                if (objectKeyLength != 0)
                {
                    objectKeyData = Utils.GetBytes(byteData, lastIndex, objectKeyLength);
                    lastIndex    += objectKeyLength;
                }

                objectKindLength = Utils.Convert4BytesToInt(byteData, lastIndex);
                lastIndex       += 4;

                if (objectKindLength != 0)
                {
                    objectKindData = Utils.GetBytes(byteData, lastIndex, objectKindLength);
                    lastIndex     += objectKindLength;
                }

                objectInfoLength = Utils.Convert2BytesToInt(byteData, lastIndex);
                lastIndex       += 2;

                if (objectKindLength != 4)
                {
                    return;
                }

                if (Utils.CompareBytes(objectKindData, biopFile))
                {
                    messageDetail = new BIOPFileMessage();
                    messageDetail.Process(byteData, lastIndex, objectInfoLength);
                    return;
                }

                if (Utils.CompareBytes(objectKindData, biopDirectory))
                {
                    messageDetail = new BIOPDirectoryMessage();
                    messageDetail.Process(byteData, lastIndex, objectInfoLength);
                    return;
                }

                if (Utils.CompareBytes(objectKindData, biopSRG))
                {
                    messageDetail = new BIOPServiceGatewayMessage();
                    messageDetail.Process(byteData, lastIndex, objectInfoLength);
                    return;
                }

                Validate();
            }
            catch (IndexOutOfRangeException)
            {
                throw (new ArgumentOutOfRangeException("The BIOP message is short"));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Parse the message.
        /// </summary>
        /// <param name="byteData">The MPEG2 section containing the message.</param>
        /// <param name="index">Index of the first byte of the message in the MPEG2 section.</param>
        public virtual void Process(byte[] byteData, int index)
        {
            lastIndex = index;

            try
            {
                magic = Utils.GetBytes(byteData, lastIndex, 4);
                lastIndex += 4;

                majorVersion = (int)byteData[lastIndex];
                lastIndex++;

                minorVersion = (int)byteData[lastIndex];
                lastIndex++;

                byteOrder = (int)byteData[lastIndex];
                lastIndex++;

                messageType = (int)byteData[lastIndex];
                lastIndex++;

                messageSize = Utils.Convert4BytesToInt(byteData, lastIndex);
                lastIndex += 4;

                objectKeyLength = (int)byteData[lastIndex];
                lastIndex++;

                if (objectKeyLength != 0)
                {
                    objectKeyData = Utils.GetBytes(byteData, lastIndex, objectKeyLength);
                    lastIndex += objectKeyLength;
                }

                objectKindLength = Utils.Convert4BytesToInt(byteData, lastIndex);
                lastIndex += 4;

                if (objectKindLength != 0)
                {
                    objectKindData = Utils.GetBytes(byteData, lastIndex, objectKindLength);
                    lastIndex += objectKindLength;
                }

                objectInfoLength = Utils.Convert2BytesToInt(byteData, lastIndex);
                lastIndex += 2;

                if (objectKindLength != 4)
                    return;

                if (Utils.CompareBytes(objectKindData, biopFile))
                {
                    messageDetail = new BIOPFileMessage();
                    messageDetail.Process(byteData, lastIndex, objectInfoLength);
                    return;
                }

                if (Utils.CompareBytes(objectKindData, biopDirectory))
                {
                    messageDetail = new BIOPDirectoryMessage();
                    messageDetail.Process(byteData, lastIndex, objectInfoLength);
                    return;
                }

                if (Utils.CompareBytes(objectKindData, biopSRG))
                {
                    messageDetail = new BIOPServiceGatewayMessage();
                    messageDetail.Process(byteData, lastIndex, objectInfoLength);
                    return;
                }

                Validate();
            }
            catch (IndexOutOfRangeException)
            {
                throw (new ArgumentOutOfRangeException("The BIOP message is short"));
            }
        }