Beispiel #1
0
            public List <DataBlob> PrepToSendRawData(byte[] rawData, int size)
            {
                List <DataBlob> blobs  = new List <DataBlob>();
                int             offset = 0;
                int             index  = 0;

                while (offset < size)
                {
                    DataBlob blob = (DataBlob)IntrepidSerialize.CreatePacket(PacketType.DataBlob);
                    blob.totalRawDataPacketCount = 1;
                    blob.packetIndex             = (short)index++;
                    int currentSize = size - offset;
                    if (currentSize > NetworkConstants.DataBlobMaxPacketSize)
                    {
                        currentSize = NetworkConstants.DataBlobMaxPacketSize;
                    }
                    //if(currentSize > size - offset)

                    blob.Prep(rawData, currentSize, offset);
                    offset += currentSize;
                    blobs.Add(blob);
                }
                foreach (var blob in blobs)
                {
                    blob.totalRawDataPacketCount = (short)index;
                }
                return(blobs);
            }
Beispiel #2
0
        // Not thread-safe: ensure you have a lock on the pool,
        // or that the pool can only be accessed from one thread
        // before calling this.
        private void CreateAndEnqueuePacket()
        {
            BasePacket packet;

            // Stop the BasePacket constructor from erroring
            BasePacket.AllowConstruction = true;
            try
            {
                packet = IntrepidSerialize.CreatePacket(type);
            }
            finally
            {
                BasePacket.AllowConstruction = false;
            }
            packet.IsInPool = true;
            pool.Enqueue(packet);
        }