Exemple #1
0
        //// Reading
        public byte[] ReadHeader()
        {
            if (_mode != Mode.Read)
            {
                Debug.LogError("SessionCaptureFileStream: Cannot call ReadHeader() on write stream.");
                return(null);
            }

            if (_reading)
            {
                Debug.LogError("SessionCaptureFileStream: ReadHeader() has been called on a session that's already reading. Ignoring. This is a bug!");
                return(null);
            }

            // Read local client ID
            uint clientIDUInt;

            if (!ReadVarint32FromStream(_gzipStream, out clientIDUInt))
            {
                PrematurelyReachedEndOfStream();
                return(null);
            }
            _clientID = ReadStream.ConvertUIntToNegativeOneInt(clientIDUInt);

            // Read start timestamp
            _startTimestamp = ReadDoubleFromStream(_gzipStream);

            // Read initial datastore
            uint dataLengthUInt;

            if (!ReadVarint32FromStream(_gzipStream, out dataLengthUInt))
            {
                PrematurelyReachedEndOfStream();
                return(null);
            }
            int dataLength = (int)dataLengthUInt;

            byte[] data      = new byte[dataLength];
            int    bytesRead = _gzipStream.Read(data, 0, dataLength);

            if (bytesRead != dataLength)
            {
                PrematurelyReachedEndOfStream();
                return(null);
            }

            // Start reading
            _reading = true;

            // Read next update timestamp
            ReadNextUpdateDeltaTimestamp();

            if (!_reading)
            {
                Debug.Log("SessionCaptureFileStream: No delta updates found after initial datastore snapshot. Reading stopped.");
            }

            return(data);
        }
Exemple #2
0
        private static void SplitSenderReliableAndIncoming(uint value, out int sender, out bool reliable, out bool incoming)
        {
            uint senderUInt   = (value >> 2);
            uint reliableUInt = (value >> 1) & 0x1;
            uint incomingUInt = (value >> 0) & 0x1;

            sender   = ReadStream.ConvertUIntToNegativeOneInt(senderUInt);
            reliable = reliableUInt != 0 ? true : false;
            incoming = incomingUInt != 0 ? true : false;
        }
Exemple #3
0
        public void Read(ReadStream stream, StreamContext context)
        {
            bool clientIDStreamIDUpdateExistsInCache = _cache.ValueExistsInCache(entry => entry.clientIDSet || entry.streamIDSet);

            // Remove from in-flight
            if (context.deltaUpdatesOnly && context.reliableChannel)
            {
                _cache.RemoveUpdateFromInflight(context.updateID);
            }

            bool receivedClientIDStreamIDUpdate = false;

            // Deserialize
            uint propertyID;

            while (stream.ReadNextPropertyID(out propertyID))
            {
                switch (propertyID)
                {
                case 1:
                    // Deserialize value
                    int clientID = ReadStream.ConvertUIntToNegativeOneInt(stream.ReadVarint32());

                    // Fire off a notification if it changed
                    if (clientID != _clientID)
                    {
                        receivedClientIDStreamIDUpdate = true;
                    }

                    // Store
                    _clientID = clientID;
                    break;

                case 2:
                    // Deserialize value
                    int streamID = ReadStream.ConvertUIntToNegativeOneInt(stream.ReadVarint32());

                    // Fire off a notification if it changed
                    if (streamID != _streamID)
                    {
                        receivedClientIDStreamIDUpdate = true;
                    }

                    // Store
                    _streamID = streamID;
                    break;

                default:
                    stream.SkipProperty();
                    break;
                }
            }

            // If we received a new value, and there's currently nothing in the cache that trumps this change, fire an update.
            if (receivedClientIDStreamIDUpdate && !clientIDStreamIDUpdateExistsInCache)
            {
                if (clientIDStreamIDUpdated != null)
                {
                    clientIDStreamIDUpdated(this);
                }
            }
        }