GetNonDataSize() public method

public GetNonDataSize ( ) : int
return int
Example #1
0
        /// <summary>
        /// Create the DYNVC_DATA PDU
        /// </summary>
        /// <param name="channelId">The channelId</param>
        /// <param name="data">The uncompressed data</param>
        /// <param name="channelChunkLength">The maximum number of uncompressed bytes in a single segment </param>
        /// <returns>Return the first and second PDUs in an array</returns>
        public DataDvcBasePdu[] CreateDataPdu(uint channelId, byte[] data, int channelChunkLength)
        {
            DataFirstDvcPdu first = new DataFirstDvcPdu(channelId, (uint)data.Length, null);
            DataDvcPdu      other = new DataDvcPdu(channelId, null);

            int firstNonDataSize = first.GetNonDataSize();
            int otherNonDataSize = other.GetNonDataSize();

            if (data.Length <= channelChunkLength - otherNonDataSize)
            {
                other.Data = data;
                return(new DataDvcBasePdu[] { other });
            }

            // TODO: need to test for the following code
            byte[]                buf  = new byte[channelChunkLength - firstNonDataSize];
            MemoryStream          ms   = new MemoryStream(data);
            List <DataDvcBasePdu> pdus = new List <DataDvcBasePdu>();

            if (channelChunkLength - firstNonDataSize != ms.Read(buf, 0, channelChunkLength - firstNonDataSize))
            {
                DynamicVCException.Throw("Cannot create correct data PDUs.");
            }
            first.Data = buf;
            pdus.Add(first);

            buf = new byte[channelChunkLength - otherNonDataSize];
            // TODO: Check this logic
            int readLen = 0;

            readLen = ms.Read(buf, 0, channelChunkLength - otherNonDataSize);
            while (readLen == channelChunkLength - otherNonDataSize)
            {
                pdus.Add(new DataDvcPdu(channelId, buf));
                buf     = new byte[channelChunkLength - otherNonDataSize];
                readLen = ms.Read(buf, 0, channelChunkLength - otherNonDataSize);
            }

            if (readLen > 0)
            {
                byte[] newBuf = new byte[readLen];
                Array.Copy(buf, newBuf, readLen);
                pdus.Add(new DataDvcPdu(channelId, newBuf));
            }

            return(pdus.ToArray());
        }
        /// <summary>
        /// Create the DYNVC_DATA PDU
        /// </summary>
        /// <param name="channelId">The channelId</param>
        /// <param name="data">The uncompressed data</param>
        /// <param name="channelChunkLength">The maximum number of uncompressed bytes in a single segment </param>        
        /// <returns>Return the first and second PDUs in an array</returns>
        public DataDvcBasePdu[] CreateDataPdu(uint channelId, byte[] data, int channelChunkLength)
        {
            DataFirstDvcPdu first = new DataFirstDvcPdu(channelId, (uint)data.Length, null);
            DataDvcPdu other = new DataDvcPdu(channelId, null);

            int firstNonDataSize = first.GetNonDataSize();
            int otherNonDataSize = other.GetNonDataSize();

            if (data.Length <= channelChunkLength - otherNonDataSize)
            {
                other.Data = data;
                return new DataDvcBasePdu[] { other };
            }

            // TODO: need to test for the following code
            byte[] buf = new byte[channelChunkLength - firstNonDataSize];
            MemoryStream ms = new MemoryStream(data);
            List<DataDvcBasePdu> pdus = new List<DataDvcBasePdu>();

            if (channelChunkLength - firstNonDataSize != ms.Read(buf, 0, channelChunkLength - firstNonDataSize))
            {
                DynamicVCException.Throw("Cannot create correct data PDUs.");
            }
            first.Data = buf;
            pdus.Add(first);

            buf = new byte[channelChunkLength - otherNonDataSize];
            // TODO: Check this logic
            int readLen = 0;
            readLen = ms.Read(buf, 0, channelChunkLength - otherNonDataSize);
            while (readLen == channelChunkLength - otherNonDataSize)
            {
                pdus.Add(new DataDvcPdu(channelId, buf));
                buf = new byte[channelChunkLength - otherNonDataSize];
                readLen = ms.Read(buf, 0, channelChunkLength - otherNonDataSize);
            }

            if (readLen > 0)
            {
                byte[] newBuf = new byte[readLen];
                Array.Copy(buf, newBuf, readLen);
                pdus.Add(new DataDvcPdu(channelId, newBuf));
            }

            return pdus.ToArray();
        }