Beispiel #1
0
        //功能函数
        //插入数据
        public bool AddPacket(byte[] pData, ushort wDataType)
        {
            if ((pData.Length + Marshal.SizeOf(m_ttagDataDescribe) + m_wDataSize) > m_wMaxBytes)
            {
                return(false);
            }

            //插入数据
            tagDataDescribe pDataDescribe = new tagDataDescribe();

            pDataDescribe.wDataSize     = (ushort)pData.Length;
            pDataDescribe.wDataDescribe = wDataType;
            var buf = StructConverterByteArray.StructToBytes(pDataDescribe);

            Buffer.BlockCopy(buf, 0, m_pcbBuffer, m_wDataSize, buf.Length);
            //tagDataDescribe* pDataDescribe = (tagDataDescribe*)(m_pcbBuffer + m_wDataSize);
            //pDataDescribe->wDataSize = wDataSize;
            //pDataDescribe->wDataDescribe = wDataType;

            //插入数据
            if (pData.Length > 0)
            {
                Buffer.BlockCopy(pData, 0, m_pcbBuffer, m_wDataSize + buf.Length, pData.Length);
                //memcpy(pDataDescribe + 1, pData, wDataSize);
            }

            //设置数据
            m_wDataSize += (ushort)(buf.Length + pData.Length);

            return(true);
        }
Beispiel #2
0
        //构造函数

        //功能函数
        public byte[] GetData(ref tagDataDescribe DataDescribe)
        {
            //效验数据
            if (m_wDataPos >= m_wDataSize)
            {
                DataDescribe.wDataSize     = 0;
                DataDescribe.wDataDescribe = DTP_NULL;//无效数据
                return(null);
            }

            //获取数据
            var structSize = Marshal.SizeOf(m_ttagDataDescribe);

            byte[] buf = new byte[structSize];
            Buffer.BlockCopy(m_pcbBuffer, m_wDataPos, buf, 0, structSize);
            DataDescribe = (tagDataDescribe)StructConverterByteArray.BytesToStruct(buf, m_ttagDataDescribe);

            //memcpy(&DataDescribe, m_pcbBuffer + m_wDataPos, sizeof(tagDataDescribe));
            //ASSERT((m_wDataPos + sizeof(tagDataDescribe) + DataDescribe.wDataSize) <= m_wDataSize);

            //效验数据
            if ((m_wDataPos + structSize + DataDescribe.wDataSize) > m_wDataSize)
            {
                DataDescribe.wDataSize     = 0;
                DataDescribe.wDataDescribe = DTP_NULL;
                return(null);
            }

            //设置数据
            byte[] pData = null;
            if (DataDescribe.wDataSize > 0)
            {
                pData = new byte[DataDescribe.wDataSize];
                Buffer.BlockCopy(m_pcbBuffer, m_wDataPos + structSize, pData, 0, DataDescribe.wDataSize);
                //pData = m_pcbBuffer + m_wDataPos + structSize;
            }
            m_wDataPos += (ushort)(structSize + DataDescribe.wDataSize);

            return(pData);
        }