Example #1
0
        private static IDictionary <long, long> ReadChildToParentMap([NotNull] UnsafeReader reader)
        {
            var count         = reader.ReadInt32();
            var childToParent = new Dictionary <long, long>(count);

            for (var i = 0; i < count; i++)
            {
                var child  = reader.ReadLong();
                var parent = reader.ReadLong();
                childToParent[child] = parent;
            }

            return(childToParent);
        }
        public static IHierarchyReference ReadReferenceFrom(UnsafeReader reader)
        {
            var id = reader.ReadInt();

            if (id == 0)
            {
                return(new LocalReference(AssetUtils.ReadOWORD(reader), reader.ReadLong()));
            }
            if (id == 1)
            {
                return(new ExternalReference(reader.ReadGuid(), reader.ReadLong()));
            }

            throw new InvalidOperationException($"Unknown reference type, {id}");
        }
Example #3
0
File: RdList.cs Project: epeshk/rd
        public static RdList <V> Read(SerializationCtx ctx, UnsafeReader reader, CtxReadDelegate <V> readValue, CtxWriteDelegate <V> writeValue)
        {
            var nextVersion = reader.ReadLong();
            var id          = reader.ReadRdId();

            return(new RdList <V>(readValue, writeValue, nextVersion).WithId(id));
        }
        public static LocalReference ReadLocalReferenceFrom(UnsafeReader reader)
        {
            var id = reader.ReadInt();

            if (id != 0)
            {
                throw new InvalidOperationException($"Expected local reference, found {id}");
            }
            return(new LocalReference(AssetUtils.ReadOWORD(reader), reader.ReadLong()));
        }
        public static ExternalReference ReadExternalReferenceFrom(UnsafeReader reader)
        {
            var id = reader.ReadInt();

            if (id != 1)
            {
                throw new InvalidOperationException($"Expected external reference, found {id}");
            }
            return(new ExternalReference(reader.ReadGuid(), reader.ReadLong()));
        }
Example #6
0
        private static LocalList <long> ReadAnchors([NotNull] UnsafeReader reader)
        {
            var stateMachineBehavioursAnchorsCount = reader.ReadInt();
            var stateMachineBehavioursAnchors      = new LocalList <long>(stateMachineBehavioursAnchorsCount);

            for (var i = 0; i < stateMachineBehavioursAnchorsCount; i++)
            {
                stateMachineBehavioursAnchors.Add(reader.ReadLong());
            }
            return(stateMachineBehavioursAnchors);
        }
Example #7
0
        private static void ReadGuidToAnchors([NotNull] UnsafeReader reader,
                                              [NotNull] OneToListMap <Guid, long> guidToAnchors)
        {
            var guid        = reader.ReadGuid();
            var usagesCount = reader.ReadInt32();

            for (var i = 0; i < usagesCount; i++)
            {
                guidToAnchors.Add(guid, reader.ReadLong());
            }
        }
Example #8
0
        private static void ReadAnchorToUsagesEntry <T>([NotNull] UnsafeReader reader,
                                                        [NotNull] OneToListMap <long, T> anchorToUsages,
                                                        [NotNull] Func <UnsafeReader, T> read)
            where T : IAnimatorScriptUsage
        {
            var anchor      = reader.ReadLong();
            var usagesCount = reader.ReadInt32();

            for (var i = 0; i < usagesCount; i++)
            {
                anchorToUsages.Add(anchor, read(reader));
            }
        }
Example #9
0
        private static IDictionary <long, AnimatorStateMachineScriptUsage> ReadStateMachineAnchorToUsageMap(
            [NotNull] UnsafeReader reader)
        {
            var count = reader.ReadInt32();
            var stateMachineAnchorToUsage = new Dictionary <long, AnimatorStateMachineScriptUsage>(count);

            for (var i = 0; i < count; i++)
            {
                var anchor = reader.ReadLong();
                var usage  = AnimatorStateMachineScriptUsage.ReadFrom(reader);
                stateMachineAnchorToUsage.Add(anchor, usage);
            }

            return(stateMachineAnchorToUsage);
        }
Example #10
0
        public override void OnWireReceived(UnsafeReader reader)
        {
            var remoteState = (ExtState)reader.ReadInt();

            ReceiveTrace?.Log($"Ext {Location} ({RdId}) : {remoteState}");

            switch (remoteState)
            {
            case ExtState.Ready:
                SendState(myExtWire.RealWire, ExtState.ReceivedCounterPart);
                myExtWire.Connected.Set(true);
                break;

            case ExtState.ReceivedCounterPart:
                myExtWire.Connected.Set(true); //don't set anything if already set
                break;

            case ExtState.Disconnected:
                myExtWire.Connected.Set(false);
                break;

            default:
                throw new ArgumentOutOfRangeException("Unsupported state: " + remoteState);
            }

            var counterpartSerializationHash = reader.ReadLong();

            if (counterpartSerializationHash != SerializationHash)
            {
                base.Proto.Scheduler.Queue(() => { base.Proto.OutOfSyncModels.Add(this); });

                if (base.Proto is Protocol p && p.ThrowErrorOnOutOfSyncModels)
                {
                    Assertion.Fail($"{this} : SerializationHash doesn't match to counterpart: maybe you forgot to generate models?" +
                                   $"Our: `${SerializationHash}` counterpart: {counterpartSerializationHash}");
                }
            }
        }
Example #11
0
 private static object Read(UnsafeReader reader) => new LocalReference(reader.ReadLong(), reader.ReadULong());
Example #12
0
File: RdMap.cs Project: yvvan/rd
        public override void OnWireReceived(UnsafeReader stream)
        {
            var header       = stream.ReadInt();
            var msgVersioned = (header >> versionedFlagShift) != 0;
            var opType       = header & ((1 << versionedFlagShift) - 1);

            var version = msgVersioned ? stream.ReadLong() : 0L;

            var key = ReadKeyDelegate(SerializationContext, stream);

            if (opType == Ack)
            {
                string error = null;

                if (!msgVersioned)
                {
                    error = "Received ACK while msg hasn't versioned flag set";
                }
                else if (!IsMaster)
                {
                    error = "Received ACK when not a Master";
                }
                else if (!myPendingForAck.TryGetValue(key, out var pendingVersion))
                {
                    error = "No pending for ACK";
                }
                else if (pendingVersion < version)
                {
                    error = $"Pending version `{pendingVersion}` < ACK version `{version}`";
                }
                // Good scenario
                else if (pendingVersion == version)
                {
                    myPendingForAck.Remove(key);
                }
                //else do nothing, silently drop

                var isError = !string.IsNullOrEmpty(error);
                if (ourLogReceived.IsTraceEnabled() || isError)
                {
                    ourLogReceived.LogFormat(isError ? LoggingLevel.ERROR : LoggingLevel.TRACE,
                                             "{0}  :: ACK :: key = {1} :: version = {2}{3}", this, key.PrintToString(), version,
                                             isError ? " >> " + error : "");
                }
            }
            else
            {
                using (UsingDebugInfo())
                {
                    var kind = (AddUpdateRemove)opType;
                    switch (kind)
                    {
                    case AddUpdateRemove.Add:
                    case AddUpdateRemove.Update:
                        var value = ReadValueDelegate(SerializationContext, stream);

                        ReceiveTrace?.Log($"{this} :: {kind} :: key = {key.PrintToString()}" +
                                          (msgVersioned ? " :: version = " + version : "") +
                                          $" :: value = {value.PrintToString()}"
                                          );


                        if (msgVersioned || !IsMaster || !myPendingForAck.ContainsKey(key))
                        {
                            myMap[key] = value;
                        }
                        else
                        {
                            ReceiveTrace?.Log(">> CHANGE IGNORED");
                        }

                        break;

                    case AddUpdateRemove.Remove:

                        ReceiveTrace?.Log($"{this} :: {kind} :: key = {key.PrintToString()}"
                                          + (msgVersioned ? " :: version = " + version : "")
                                          );


                        if (msgVersioned || !IsMaster || !myPendingForAck.ContainsKey(key))
                        {
                            myMap.Remove(key);
                        }
                        else
                        {
                            ReceiveTrace?.Log(">> CHANGE IGNORED");
                        }

                        break;

                    default:
                        throw new ArgumentOutOfRangeException(kind.ToString());
                    }
                }

                if (msgVersioned)
                {
                    Wire.Send(RdId, (innerWriter) =>
                    {
                        innerWriter.Write((1 << versionedFlagShift) | Ack);
                        innerWriter.Write(version);
                        WriteKeyDelegate.Invoke(SerializationContext, innerWriter, key);

                        SendTrace?.Log($"{this} :: ACK :: key = {key.PrintToString()} :: version = {version}");
                    });

                    if (IsMaster)
                    {
                        ourLogReceived.Error("Both ends are masters: {0}", Location);
                    }
                }
            }
        }
Example #13
0
File: RdList.cs Project: epeshk/rd
        public override void OnWireReceived(UnsafeReader stream)
        {
            var header  = stream.ReadLong();
            var opType  = header & ((1 << versionedFlagShift) - 1);
            var version = header >> versionedFlagShift;

            var index = stream.ReadInt();


            var kind  = (AddUpdateRemove)opType;
            V   value = default(V);
            var isPut = kind == AddUpdateRemove.Add || kind == AddUpdateRemove.Update;

            if (isPut)
            {
                value = ReadValueDelegate(SerializationContext, stream);
            }

            LogReceived.Trace("list `{0}` ({1}) :: {2} :: index={3} :: version = {4}{5}", Location, RdId, kind, index
                              , version
                              , isPut  ? " :: value = " + value.PrintToString() : "");

            if (version != myNextVersion)
            {
                Assertion.Fail("Version conflict for {0} Expected version {1} received {2}. Are you modifying a list from two sides?",
                               Location,
                               myNextVersion,
                               version);
            }


            myNextVersion++;

            using (UsingDebugInfo())
            {
                switch (kind)
                {
                case AddUpdateRemove.Add:
                    if (index < 0)
                    {
                        myList.Add(value);
                    }
                    else
                    {
                        myList.Insert(index, value);
                    }
                    break;

                case AddUpdateRemove.Update:
                    // ReSharper disable once AssignNullToNotNullAttribute
                    myList[index] = value;
                    break;

                case AddUpdateRemove.Remove:
                    myList.RemoveAt(index);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(kind.ToString());
                }
            }
        }
Example #14
0
 public static AssetMethodUsages ReadFrom(UnsafeReader reader)
 {
     return(new AssetMethodUsages(reader.ReadString(), reader.ReadString(),
                                  new TextRange(reader.ReadInt32(), reader.ReadInt32()), reader.ReadLong(),
                                  (EventHandlerArgumentMode)reader.ReadInt32(), reader.ReadString(), HierarchyReferenceUtil.ReadReferenceFrom(reader)));
 }