public void MergeFrom(CodedInputStream input)
        {
            uint num;

            while ((num = input.ReadTag()) != 0)
            {
                switch (num)
                {
                default:
                    _unknownFields = UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                    break;

                case 8u:
                    Id = input.ReadInt32();
                    break;

                case 16u:
                    Success = input.ReadBool();
                    break;

                case 26u:
                    Result = input.ReadString();
                    break;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Read value from <see cref="System.Protobuf.Object"/>
        /// </summary>
        /// <param name="obj"><see cref="System.Protobuf.Object"/> to read from</param>
        /// <returns>Value in the correct type - null if not capable of converting</returns>
        public static object ToCLR(this System.Protobuf.Object obj)
        {
            var    type  = (Types)obj.Type;
            object value = null;

            using (var stream = new CodedInputStream(obj.Content.ToByteArray()))
            {
                switch (type)
                {
                case Types.String: value = stream.ReadString(); break;

                case Types.Int32: value = stream.ReadInt32(); break;

                case Types.Int64: value = stream.ReadInt64(); break;

                case Types.UInt32: value = stream.ReadUInt32(); break;

                case Types.UInt64: value = stream.ReadUInt64(); break;

                case Types.Float: value = stream.ReadFloat(); break;

                case Types.Double: value = stream.ReadDouble(); break;

                case Types.Boolean: value = stream.ReadBool(); break;

                case Types.DateTime: value = stream.ReadInt64().ToDateTime(); break;

                case Types.DateTimeOffset: value = stream.ReadInt64().ToDateTimeOffset(); break;

                case Types.Guid: value = new Guid(stream.ReadBytes().ToByteArray()); break;
                }
            }
            return(value);
        }
예제 #3
0
파일: EntityFSM.cs 프로젝트: niuniuzhu/KOW
        public void DecodeSnapshot(CodedInputStream reader)
        {
            reader.ReadBytes();

            if (reader.ReadBool())
            {
                this.currentState = this.GetState(reader.ReadInt32());
            }

            if (reader.ReadBool())
            {
                this.previousState = this.GetState(reader.ReadInt32());
            }

            this.context.DecodeSnapshot(reader);
        }
예제 #4
0
        public override void DecodeSnapshot(ulong rid, bool isNew, CodedInputStream reader)
        {
            base.DecodeSnapshot(rid, isNew, reader);
            this.team             = reader.ReadInt32();
            this.name             = reader.ReadString();
            this.hp               = reader.ReadInt32();
            this.mhp              = reader.ReadInt32();
            this.mp               = ( Fix64 )reader.ReadDouble();
            this.mmp              = reader.ReadInt32();
            this.mpRecover        = reader.ReadInt32();
            this.atk              = reader.ReadInt32();
            this.def              = reader.ReadInt32();
            this.disableMove      = reader.ReadInt32();
            this.disableTurn      = reader.ReadInt32();
            this.disableSkill     = reader.ReadInt32();
            this.disableCollision = reader.ReadInt32();
            this.supperArmor      = reader.ReadInt32();
            this.invulnerAbility  = reader.ReadInt32();
            this.moveDirection    = new FVec2(( Fix64 )reader.ReadDouble(), ( Fix64 )reader.ReadDouble());
            this.intersectVector  = new FVec2(( Fix64 )reader.ReadDouble(), ( Fix64 )reader.ReadDouble());
            this.phyxSpeed        = new FVec2(( Fix64 )reader.ReadDouble(), ( Fix64 )reader.ReadDouble());
            this.velocity         = ( Fix64 )reader.ReadDouble();
            this.isDead           = reader.ReadBool();
            this.t_hp_add         = reader.ReadInt32();
            this.t_mp_add         = reader.ReadInt32();
            this.t_atk_add        = reader.ReadInt32();
            this.t_def_add        = reader.ReadInt32();
            this.t_speed_add      = reader.ReadInt32();

            this.fsm.DecodeSnapshot(reader);
            reader.ReadBytes();
        }
        object ReadValue(CodedInputStream inputStream, object value, Type type, Type targetType, IValueConverter converter)
        {
            if (type == typeof(Guid))
            {
                _ = inputStream.ReadLength();
                var guidAsBytes = inputStream.ReadBytes();
                value = new Guid(guidAsBytes.ToByteArray());
            }
            else if (type == typeof(string))
            {
                _     = inputStream.ReadLength();
                value = inputStream.ReadString();
            }
            else if (type == typeof(int))
            {
                value = inputStream.ReadInt32();
            }
            else if (type == typeof(long))
            {
                value = inputStream.ReadInt64();
            }
            else if (type == typeof(uint))
            {
                value = inputStream.ReadUInt32();
            }
            else if (type == typeof(ulong))
            {
                value = inputStream.ReadUInt64();
            }
            else if (type == typeof(float))
            {
                value = inputStream.ReadFloat();
            }
            else if (type == typeof(double))
            {
                value = inputStream.ReadDouble();
            }
            else if (type == typeof(bool))
            {
                value = inputStream.ReadBool();
            }
            else if (type == typeof(DateTimeOffset) || type == typeof(DateTime))
            {
                value = DateTimeOffset.FromUnixTimeMilliseconds(inputStream.ReadInt64());
                if (type == typeof(DateTime))
                {
                    value = ((DateTimeOffset)value).UtcDateTime;
                }
            }

            if (converter != null)
            {
                value = converter.ConvertFrom(targetType, value);
            }
            return(value);
        }
예제 #6
0
 /// <summary>
 /// 解码快照
 /// </summary>
 public virtual void DecodeSnapshot(ulong rid, bool isNew, CodedInputStream reader)
 {
     this.rid = rid;
     this.id  = reader.ReadInt32();
     if (isNew)
     {
         this.LoadDefs();
         this.OnInit();
     }
     this.markToDestroy = reader.ReadBool();
     this.position      = new FVec2(( Fix64 )reader.ReadDouble(), ( Fix64 )reader.ReadDouble());
     this.direction     = new FVec2(( Fix64 )reader.ReadDouble(), ( Fix64 )reader.ReadDouble());
 }
예제 #7
0
                public void MergeFrom(CodedInputStream input)
                {
                    while (true)
                    {
IL_EE:
                        uint num;
                        uint arg_AE_0 = ((num = input.ReadTag()) == 0u) ? 2315126112u : 2343597663u;
                        while (true)
                        {
                            uint num2;
                            switch ((num2 = (arg_AE_0 ^ 2222133674u)) % 9u)
                            {
                            case 0u:
                                arg_AE_0 = (((num == 16u) ? 2243065476u : 2494122898u) ^ num2 * 2151440464u);
                                continue;

                            case 1u:
                                this.NamePart_ = input.ReadString();
                                arg_AE_0       = 2991866976u;
                                continue;

                            case 2u:
                                arg_AE_0 = 2343597663u;
                                continue;

                            case 3u:
                                arg_AE_0 = ((num == 10u) ? 3702260229u : 2436237105u);
                                continue;

                            case 5u:
                                arg_AE_0 = (num2 * 2126258113u ^ 2965097581u);
                                continue;

                            case 6u:
                                goto IL_EE;

                            case 7u:
                                this.IsExtension = input.ReadBool();
                                arg_AE_0         = 3017338663u;
                                continue;

                            case 8u:
                                input.SkipLastField();
                                arg_AE_0 = (num2 * 1762041467u ^ 2694344639u);
                                continue;
                            }
                            return;
                        }
                    }
                }
예제 #8
0
    public bool ReadBool(out bool value)
    {
        try
        {
            value = _stream.ReadBool();
        }
        catch (Exception)
        {
            value = false;
            return(false);
        }

        return(true);
    }
예제 #9
0
        internal static TransportMessage ReadTransportMessage(this CodedInputStream input)
        {
            var transportMessage = new TransportMessage {
                Content = Stream.Null
            };

            uint     number;
            WireType wireType;

            while (!input.IsAtEnd && input.TryReadTag(out number, out wireType))
            {
                switch (number)
                {
                case 1:
                    transportMessage.Id = ReadMessageId(input);
                    break;

                case 2:
                    transportMessage.MessageTypeId = ReadMessageTypeId(input);
                    break;

                case 3:
                    transportMessage.Content = ReadStream(input);
                    break;

                case 4:
                    transportMessage.Originator = ReadOriginatorInfo(input);
                    break;

                case 5:
                    transportMessage.Environment = input.ReadString();
                    break;

                case 6:
                    transportMessage.WasPersisted = input.ReadBool();
                    break;

                case 7:
                    transportMessage.PersistentPeerIds = ReadPeerIds(input, transportMessage.PersistentPeerIds);
                    break;

                default:
                    SkipUnknown(input, wireType);
                    break;
                }
            }

            return(transportMessage);
        }
예제 #10
0
    public Dictionary <Type, object> ReadParam()
    {
        Dictionary <Type, object> pairs = new Dictionary <Type, object>();

        foreach (var item in Params)
        {
            object o = null;
            Type   t = Type.GetType(item.Name);

            if (t != null)
            {
                CodedInputStream cis = new CodedInputStream(item.Data.ToByteArray());
                if (t == typeof(int))
                {
                    o = cis.ReadInt32();
                }
                else if (t == typeof(long))
                {
                    o = cis.ReadInt64();
                }
                else if (t == typeof(float))
                {
                    o = cis.ReadFloat();
                }
                else if (t == typeof(double))
                {
                    o = cis.ReadDouble();
                }
                else if (t == typeof(bool))
                {
                    o = cis.ReadBool();
                }
                else if (t == typeof(string))
                {
                    o = cis.ReadString();
                }
                else if (typeof(IMessage).IsAssignableFrom(t))
                {
                    o = Activator.CreateInstance(t);
                    cis.ReadMessage((IMessage)o);
                }

                pairs.Add(t, o);
            }
        }

        return(pairs);
    }
예제 #11
0
        /// <summary>
        /// Convert a Protocol Buffer value type, encoded as a byte string, to a C# value.
        /// </summary>
        public static object ReadValue(ByteString value, Type type)
        {
            if (value.Length == 0)
            {
                throw new ArgumentException("Value is empty");
            }
            var stream = new CodedInputStream(value.ToByteArray());

            if (type == typeof(double))
            {
                return(stream.ReadDouble());
            }
            else if (type == typeof(float))
            {
                return(stream.ReadFloat());
            }
            else if (type == typeof(int))
            {
                return(stream.ReadInt32());
            }
            else if (type == typeof(long))
            {
                return(stream.ReadInt64());
            }
            else if (type == typeof(uint))
            {
                return(stream.ReadUInt32());
            }
            else if (type == typeof(ulong))
            {
                return(stream.ReadUInt64());
            }
            else if (type == typeof(bool))
            {
                return(stream.ReadBool());
            }
            else if (type == typeof(string))
            {
                return(stream.ReadString());
            }
            else if (type == typeof(byte[]))
            {
                return(stream.ReadBytes().ToByteArray());
            }
            throw new ArgumentException(type + " is not a Protocol Buffer value type");
        }
        public void MergeFrom(CodedInputStream input)
        {
            uint num;

            while ((num = input.ReadTag()) != 0)
            {
                switch (num)
                {
                default:
                    _unknownFields = UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                    break;

                case 8u:
                    GroupRemoved = input.ReadBool();
                    break;

                case 18u:
                    members_.AddEntriesFrom(input, _repeated_members_codec);
                    break;
                }
            }
        }
예제 #13
0
        public void MergeFrom(CodedInputStream input)
        {
            uint num;

            while ((num = input.ReadTag()) != 0)
            {
                switch (num)
                {
                default:
                    _unknownFields = UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                    break;

                case 8u:
                    AccountData = input.ReadBool();
                    break;

                case 16u:
                    Occupation = input.ReadBool();
                    break;

                case 24u:
                    HeroData = input.ReadBool();
                    break;

                case 32u:
                    Decks = input.ReadBool();
                    break;

                case 40u:
                    Companions = input.ReadBool();
                    break;

                case 48u:
                    Weapons = input.ReadBool();
                    break;
                }
            }
        }
예제 #14
0
 public override bool Read(CodedInputStream stream)
 {
     return(stream.ReadBool());
 }
예제 #15
0
파일: Encoder.cs 프로젝트: pipi1226/krpc
        /// <summary>
        /// Decode a value of the given type.
        /// Should not be called directly. This interface is used by service client stubs.
        /// </summary>
        public static object Decode(ByteString value, Type type, Connection client)
        {
            var stream = new CodedInputStream(value.ToByteArray());

            if (type == typeof(double))
            {
                return(stream.ReadDouble());
            }
            else if (type == typeof(float))
            {
                return(stream.ReadFloat());
            }
            else if (type == typeof(int))
            {
                return(stream.ReadInt32());
            }
            else if (type == typeof(long))
            {
                return(stream.ReadInt64());
            }
            else if (type == typeof(uint))
            {
                return(stream.ReadUInt32());
            }
            else if (type == typeof(ulong))
            {
                return(stream.ReadUInt64());
            }
            else if (type == typeof(bool))
            {
                return(stream.ReadBool());
            }
            else if (type == typeof(string))
            {
                return(stream.ReadString());
            }
            else if (type == typeof(byte[]))
            {
                return(stream.ReadBytes().ToByteArray());
            }
            else if (type.IsEnum)
            {
                return(stream.ReadInt32());
            }
            else if (typeof(RemoteObject).IsAssignableFrom(type))
            {
                if (client == null)
                {
                    throw new ArgumentException("Client not passed when decoding remote object");
                }
                var id = stream.ReadUInt64();
                if (id == 0)
                {
                    return(null);
                }
                return((RemoteObject)Activator.CreateInstance(type, client, id));
            }
            else if (typeof(IMessage).IsAssignableFrom(type))
            {
                IMessage message = (IMessage)Activator.CreateInstance(type);
                message.MergeFrom(stream);
                return(message);
            }
            else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IList <>))
            {
                return(DecodeList(value, type, client));
            }
            else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IDictionary <,>))
            {
                return(DecodeDictionary(value, type, client));
            }
            else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(ISet <>))
            {
                return(DecodeSet(value, type, client));
            }
            else if (type.IsGenericType &&
                     (type.GetGenericTypeDefinition() == typeof(Tuple <>) ||
                      type.GetGenericTypeDefinition() == typeof(Tuple <,>) ||
                      type.GetGenericTypeDefinition() == typeof(Tuple <, ,>) ||
                      type.GetGenericTypeDefinition() == typeof(Tuple <, , ,>) ||
                      type.GetGenericTypeDefinition() == typeof(Tuple <, , , ,>) ||
                      type.GetGenericTypeDefinition() == typeof(Tuple <, , , , ,>)))
            {
                return(DecodeTuple(value, type, client)); // TODO: ugly handing of tuple types
            }
            throw new ArgumentException(type + " is not a serializable type");
        }
예제 #16
0
        public void MergeFrom(CodedInputStream input)
        {
            uint num;

            while ((num = input.ReadTag()) != 0)
            {
                switch (num)
                {
                default:
                    _unknownFields = UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                    break;

                case 8u:
                    eventType_ = (Types.EventType)input.ReadEnum();
                    break;

                case 16u:
                    EventId = input.ReadSInt32();
                    break;

                case 26u:
                {
                    int?num6 = _single_parentEventId_codec.Read(input);
                    if (!parentEventId_.HasValue || num6 != 0)
                    {
                        ParentEventId = num6;
                    }
                    break;
                }

                case 32u:
                    Int1 = input.ReadInt32();
                    break;

                case 40u:
                    Int2 = input.ReadInt32();
                    break;

                case 48u:
                    Int3 = input.ReadInt32();
                    break;

                case 56u:
                    Int4 = input.ReadInt32();
                    break;

                case 64u:
                    Int5 = input.ReadInt32();
                    break;

                case 72u:
                    Int6 = input.ReadInt32();
                    break;

                case 80u:
                    Int7 = input.ReadInt32();
                    break;

                case 90u:
                    String1 = input.ReadString();
                    break;

                case 96u:
                    Bool1 = input.ReadBool();
                    break;

                case 106u:
                    if (cellCoord1_ == null)
                    {
                        cellCoord1_ = new CellCoord();
                    }
                    input.ReadMessage(cellCoord1_);
                    break;

                case 114u:
                    if (cellCoord2_ == null)
                    {
                        cellCoord2_ = new CellCoord();
                    }
                    input.ReadMessage(cellCoord2_);
                    break;

                case 120u:
                    companionReserveState1_ = (CompanionReserveState)input.ReadEnum();
                    break;

                case 128u:
                    companionReserveState2_ = (CompanionReserveState)input.ReadEnum();
                    break;

                case 136u:
                    damageReductionType1_ = (DamageReductionType)input.ReadEnum();
                    break;

                case 144u:
                    fightResult1_ = (FightResult)input.ReadEnum();
                    break;

                case 154u:
                    if (gameStatistics1_ == null)
                    {
                        gameStatistics1_ = new GameStatistics();
                    }
                    input.ReadMessage(gameStatistics1_);
                    break;

                case 160u:
                    teamsScoreModificationReason1_ = (TeamsScoreModificationReason)input.ReadEnum();
                    break;

                case 170u:
                {
                    int?num5 = _single_optInt1_codec.Read(input);
                    if (!optInt1_.HasValue || num5 != 0)
                    {
                        OptInt1 = num5;
                    }
                    break;
                }

                case 178u:
                {
                    int?num4 = _single_optInt2_codec.Read(input);
                    if (!optInt2_.HasValue || num4 != 0)
                    {
                        OptInt2 = num4;
                    }
                    break;
                }

                case 186u:
                {
                    int?num3 = _single_optInt3_codec.Read(input);
                    if (!optInt3_.HasValue || num3 != 0)
                    {
                        OptInt3 = num3;
                    }
                    break;
                }

                case 194u:
                {
                    int?num2 = _single_optInt4_codec.Read(input);
                    if (!optInt4_.HasValue || num2 != 0)
                    {
                        OptInt4 = num2;
                    }
                    break;
                }

                case 202u:
                    cellCoordList1_.AddEntriesFrom(input, _repeated_cellCoordList1_codec);
                    break;

                case 210u:
                    spellMovementList1_.AddEntriesFrom(input, _repeated_spellMovementList1_codec);
                    break;

                case 218u:
                    castTargetList1_.AddEntriesFrom(input, _repeated_castTargetList1_codec);
                    break;

                case 224u:
                case 226u:
                    intList1_.AddEntriesFrom(input, _repeated_intList1_codec);
                    break;

                case 232u:
                case 234u:
                    intList2_.AddEntriesFrom(input, _repeated_intList2_codec);
                    break;
                }
            }
        }
예제 #17
0
        public void MergeFrom(CodedInputStream input)
        {
            uint num;

            while ((num = input.ReadTag()) != 0)
            {
                switch (num)
                {
                default:
                    _unknownFields = UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                    break;

                case 8u:
                    Id = input.ReadInt32();
                    break;

                case 16u:
                    GiveAllCompanions = input.ReadBool();
                    break;

                case 24u:
                    GiveAllWeapons = input.ReadBool();
                    break;

                case 34u:
                {
                    Types.SetLevel setLevel = new Types.SetLevel();
                    if (cmdCase_ == CmdOneofCase.SetWeaponLevel)
                    {
                        setLevel.MergeFrom(SetWeaponLevel);
                    }
                    input.ReadMessage(setLevel);
                    SetWeaponLevel = setLevel;
                    break;
                }

                case 42u:
                {
                    Types.SetAllLevels setAllLevels = new Types.SetAllLevels();
                    if (cmdCase_ == CmdOneofCase.SetAllWeaponLevels)
                    {
                        setAllLevels.MergeFrom(SetAllWeaponLevels);
                    }
                    input.ReadMessage(setAllLevels);
                    SetAllWeaponLevels = setAllLevels;
                    break;
                }

                case 50u:
                {
                    Types.SetGender setGender = new Types.SetGender();
                    if (cmdCase_ == CmdOneofCase.SetGender)
                    {
                        setGender.MergeFrom(SetGender);
                    }
                    input.ReadMessage(setGender);
                    SetGender = setGender;
                    break;
                }
                }
            }
        }