Esempio n. 1
0
            public bool Unmarshal(IBufReader reader)
            {
                //Console.WriteLine("--------------------Unmarshal------------------------");
                var length = reader.ReadInt32();

                this.FrameIndex = reader.ReadUInt32();

                var count = reader.ReadInt32();

                for (var i = 0; i < count; ++i)
                {
                    var      ownerId      = reader.ReadUInt64();
                    var      type         = (SyncType)reader.ReadByte();
                    var      target       = (SyncTarget)reader.ReadByte();
                    var      actorId      = reader.ReadUInt64();
                    var      clsName      = reader.ReadString();
                    var      subTarget    = reader.ReadString();
                    object[] payload      = null;
                    var      payloadCount = (int)reader.ReadByte();
                    if (payloadCount > 0)
                    {
                        payload = new object[payloadCount];
                        for (var j = 0; j < payloadCount; ++j)
                        {
                            payload[j] = ReadObject(reader);
                        }
                    }

                    //Console.WriteLine("< " + ownerId + ", " + type + ", " + target + ", " + actorId + ", " + (clsName ?? string.Empty) + ", " + (subTarget ?? string.Empty));
                    lock (this.Actions)
                    {
                        this.Actions.Enqueue(new SyncAction
                        {
                            OwnerId   = ownerId,
                            Type      = type,
                            Target    = target,
                            ActorId   = actorId,
                            ClsName   = string.IsNullOrEmpty(clsName) ? null : clsName,
                            SubTarget = string.IsNullOrEmpty(subTarget) ? null : subTarget,
                            Payload   = payload,
                        });
                    }
                }

                this.RemoteTimestamp = reader.ReadInt64();

                return(true);
            }
Esempio n. 2
0
        public static object ReadObject(IBufReader reader)
        {
            var flag = reader.ReadByte();

            switch (flag)
            {
            case FALSE:
                return(false);

            case TRUE:
                return(true);

            case FLOAT32:
                return(reader.ReadFloat());

            case FLOAT64:
                return(reader.ReadDouble());

            case UINT16:
                return(reader.ReadUInt16());

            case UINT32:
                return(reader.ReadUInt32());

            case UINT64:
                return(reader.ReadUInt64());

            case INT8:
                return(reader.ReadByte());

            case INT16:
                return(reader.ReadInt16());

            case INT32:
                return(reader.ReadInt32());

            case INT64:
                return(reader.ReadInt64());

            case STR32:
                return(reader.ReadString());

            case ARR32:
            {
                var count = (int)ReadObject(reader);
                var arr   = new object[count];
                for (var i = 0; i < count; ++i)
                {
                    arr[i] = ReadObject(reader);
                }

                return(arr);
            }

            case MAP32:
            {
                var count = (int)ReadObject(reader);
                var map   = new Dictionary <object, object>();
                for (var i = 0; i < count; ++i)
                {
                    var key   = ReadObject(reader);
                    var value = ReadObject(reader);
                    map.Add(key, value);
                }

                return(map);
            }

            default:
                throw new TypeUnloadedException("DO NOT know the value type!");
            }
        }