Example #1
0
        public void Encode(ProtocolBuffer protocolBuffer, object data)
        {
            int length = (int)this.countProperty.GetValue(data, BindingFlags.Default, null, null, null);

            LengthCodecHelper.EncodeLength(protocolBuffer.Data.Stream, length);
            if (length > 0)
            {
                IEnumerator enumerator = ((IEnumerable)data).GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        object current = enumerator.Current;
                        this.elementCodec.Encode(protocolBuffer, current);
                    }
                }
                finally
                {
                    IDisposable disposable = enumerator as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
            }
        }
Example #2
0
        public void Encode(ProtocolBuffer protocolBuffer, object data)
        {
            IDictionary dictionary = (IDictionary)data;

            LengthCodecHelper.EncodeLength(protocolBuffer.Data.Stream, dictionary.Count);
            if (dictionary.Count > 0)
            {
                IEnumerator enumerator = dictionary.Keys.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        object current = enumerator.Current;
                        this.keyCodec.Encode(protocolBuffer, current);
                        this.valueCodec.Encode(protocolBuffer, dictionary[current]);
                    }
                }
                finally
                {
                    IDisposable disposable = enumerator as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
            }
        }
        public object Decode(ProtocolBuffer protocolBuffer)
        {
            ComponentChangeCommand instance = Activator.CreateInstance <ComponentChangeCommand>();

            this.DecodeToInstance(protocolBuffer, instance);
            return(instance);
        }
Example #4
0
        public override object Decode(ProtocolBuffer protocolBuffer)
        {
            long uid       = (long)this.longCodec.Decode(protocolBuffer);
            Type typeByUid = this.protocol.GetTypeByUid(uid);

            return(GroupRegistry.FindOrCreateGroup(typeByUid, (long)this.longCodec.Decode(protocolBuffer)));
        }
        public void Encode(ProtocolBuffer protocolBuffer, object data)
        {
            ComponentChangeCommand command = (ComponentChangeCommand)data;

            this.entityCodec.Encode(protocolBuffer, command.Entity);
            this.EncodeVaried(protocolBuffer, command.Component);
        }
Example #6
0
        public object Decode(ProtocolBuffer protocolBuffer)
        {
            object instance = Activator.CreateInstance(this.type);

            this.DecodeToInstance(protocolBuffer, instance);
            return(instance);
        }
Example #7
0
        public override object Decode(ProtocolBuffer protocolBuffer)
        {
            int count = LengthCodecHelper.DecodeLength(protocolBuffer.Reader);

            byte[] bytes = protocolBuffer.Reader.ReadBytes(count);
            return(Encoding.GetString(bytes));
        }
Example #8
0
        public void DecodeToInstance(ProtocolBuffer protocolBuffer, object instance)
        {
            int num = 0;

            try
            {
                while (num < this.codecCount)
                {
                    PropertyCodec codec = this.codecs[num];
                    object        obj2  = codec.Codec.Decode(protocolBuffer);
                    codec.PropertyInfo.SetValue(instance, obj2, null);
                    num++;
                }
            }
            catch (Exception exception)
            {
                StringBuilder builder = new StringBuilder();
                for (int i = 0; i <= num; i++)
                {
                    PropertyCodec codec2 = this.codecs[i];
                    builder.Append(codec2.PropertyInfo.Name);
                    builder.Append("=");
                    builder.Append(codec2.PropertyInfo.GetValue(instance, BindingFlags.Default, null, null, null));
                    builder.Append("\n");
                }
                object[] objArray1 = new object[] { "Struct decode failed; Type: ", instance.GetType().Name, " decodedPropertis: ", builder };
                throw new Exception(string.Concat(objArray1), exception);
            }
        }
Example #9
0
        public override void Encode(ProtocolBuffer protocolBuffer, object data)
        {
            base.Encode(protocolBuffer, data);
            long num = ((Date)data).ToServerTime(TimeService.DiffToServer);

            protocolBuffer.Writer.Write(num);
        }
Example #10
0
        public void Encode(ProtocolBuffer protocolBuffer, object data)
        {
            IList list = (IList)data;

            LengthCodecHelper.EncodeLength(protocolBuffer.Data.Stream, list.Count);
            if (list.Count > 0)
            {
                IEnumerator enumerator = list.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        object current = enumerator.Current;
                        this.elementCodec.Encode(protocolBuffer, current);
                    }
                }
                finally
                {
                    IDisposable disposable = enumerator as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
            }
        }
Example #11
0
        public override object Decode(ProtocolBuffer protocolBuffer)
        {
            EntityInternal internal2;
            long           entityId = (long)this.longCodec.Decode(protocolBuffer);

            return(!SharedEntityRegistry.TryGetEntity(entityId, out internal2) ? SharedEntityRegistry.CreateEntity(entityId) : internal2);
        }
Example #12
0
        public override void Encode(ProtocolBuffer protocolBuffer, object data)
        {
            Type cl        = (Type)data;
            long uidByType = this.protocol.GetUidByType(cl);

            protocolBuffer.Writer.Write(uidByType);
        }
Example #13
0
        public override void Encode(ProtocolBuffer protocolBuffer, object data)
        {
            base.Encode(protocolBuffer, data);
            DateTimeOffset offset = new DateTimeOffset((DateTime)data);
            long           num    = (offset.UtcTicks - UNIX_EPOCH.Ticks) / 0x2710L;

            protocolBuffer.Writer.Write(num);
        }
Example #14
0
        public override void Encode(ProtocolBuffer protocolBuffer, object data)
        {
            base.Encode(protocolBuffer, data);
            string s         = (string)data;
            int    byteCount = Encoding.GetByteCount(s);

            LengthCodecHelper.EncodeLength(protocolBuffer.Data.Stream, byteCount);
            protocolBuffer.Writer.Write(Encoding.GetBytes(s), 0, byteCount);
        }
Example #15
0
        public override object Decode(ProtocolBuffer protocolBuffer)
        {
            long  serverTime   = protocolBuffer.Reader.ReadInt64();
            long  diffToServer = TimeService.DiffToServer;
            float num3         = Date.FromServerTime(diffToServer, serverTime);

            LoggerProvider.GetLogger(this).InfoFormat("Decode: serverTime={0} diffToServer={1} unityTime={2}", serverTime, diffToServer, num3);
            return(new Date(num3));
        }
Example #16
0
        public override void Encode(ProtocolBuffer protocolBuffer, object data)
        {
            base.Encode(protocolBuffer, data);
            GroupComponent component = (GroupComponent)data;
            long           uidByType = this.protocol.GetUidByType(component.GetType());

            this.longCodec.Encode(protocolBuffer, uidByType);
            this.longCodec.Encode(protocolBuffer, component.Key);
        }
Example #17
0
        public override object Decode(ProtocolBuffer protocolBuffer)
        {
            float f = protocolBuffer.Reader.ReadSingle();

            if (float.IsNaN(f) || float.IsInfinity(f))
            {
                DECODE_NAN_ERRORS++;
            }
            return(f);
        }
Example #18
0
        public void Encode(ProtocolBuffer protocolBuffer, object data)
        {
            Command     command = (Command)data;
            Type        type    = command.GetType();
            CommandCode code    = this.codeByType[type];
            Codec       codec   = this.protocol.GetCodec(type);

            this.commandCodeCodec.Encode(protocolBuffer, code);
            codec.Encode(protocolBuffer, command);
        }
Example #19
0
        public override void Encode(ProtocolBuffer protocolBuffer, object data)
        {
            base.Encode(protocolBuffer, data);
            Vector3      vector = (Vector3)data;
            BinaryWriter writer = protocolBuffer.Writer;

            writer.Write(vector.x);
            writer.Write(vector.y);
            writer.Write(vector.z);
        }
Example #20
0
        public override object Decode(ProtocolBuffer protocolBuffer)
        {
            if (protocolBuffer.OptionalMap.Get())
            {
                return(this.emptyMethod.Invoke(null, null));
            }
            object obj2 = this.elementCodec.Decode(protocolBuffer);

            object[] parameters = new object[] { obj2 };
            return(this.ofMethod.Invoke(null, parameters));
        }
Example #21
0
        public void Encode(ProtocolBuffer protocolBuffer, object data)
        {
            Array array  = (Array)data;
            int   length = array.Length;

            LengthCodecHelper.EncodeLength(protocolBuffer.Data.Stream, length);
            for (int i = 0; i < length; i++)
            {
                this.elementCodec.Encode(protocolBuffer, array.GetValue(i));
            }
        }
Example #22
0
        public override void Encode(ProtocolBuffer protocolBuffer, object data)
        {
            base.Encode(protocolBuffer, data);
            Enum enum2 = (Enum)data;

            if (enum2.GetTypeCode() != TypeCode.Byte)
            {
                throw new UnsupportedEnumTypeCodeException(enum2.GetTypeCode());
            }
            protocolBuffer.Writer.Write((byte)data);
        }
Example #23
0
 public void Encode(ProtocolBuffer protocolBuffer, object data)
 {
     if (data == null)
     {
         protocolBuffer.OptionalMap.Add(true);
     }
     else
     {
         protocolBuffer.OptionalMap.Add(false);
         this.codec.Encode(protocolBuffer, data);
     }
 }
        private bool TryUnwrapPacket(ProtocolBuffer packetData)
        {
            long position = this.partialReceivedData.Position;

            this.partialReceivedData.Position = 0L;
            if (this.protocol.UnwrapPacket(this.partialReceivedData, packetData))
            {
                return(true);
            }
            this.partialReceivedData.Position = position;
            return(false);
        }
Example #25
0
        public override void Encode(ProtocolBuffer protocolBuffer, object data)
        {
            base.Encode(protocolBuffer, data);
            float f = (float)data;

            if (float.IsNaN(f) || float.IsInfinity(f))
            {
                ENCODE_NAN_ERRORS++;
                encodeErrorStack = new Exception();
            }
            protocolBuffer.Writer.Write(f);
        }
        private void EncodeVaried(ProtocolBuffer protocolBuffer, object data)
        {
            Type cl        = data.GetType();
            long uidByType = this.protocol.GetUidByType(cl);

            protocolBuffer.Writer.Write(uidByType);
            ProtocolBuffer buffer = this.protocol.NewProtocolBuffer();

            this.protocol.GetCodec(cl).Encode(buffer, data);
            this.protocol.WrapPacket(buffer, protocolBuffer.Data);
            this.protocol.FreeProtocolBuffer(buffer);
        }
Example #27
0
 public override void Encode(ProtocolBuffer protocolBuffer, object data)
 {
     if (!((data != null) && ((bool)this.isPresentMethod.Invoke(data, null))))
     {
         protocolBuffer.OptionalMap.Add(true);
     }
     else
     {
         protocolBuffer.OptionalMap.Add(false);
         this.elementCodec.Encode(protocolBuffer, this.getMethod.Invoke(data, null));
     }
 }
        public void DecodeToInstance(ProtocolBuffer protocolBuffer, object instance)
        {
            ComponentChangeCommand command   = (ComponentChangeCommand)instance;
            EntityInternal         internal2 = (EntityInternal)this.entityCodec.Decode(protocolBuffer);
            long      uid       = (long)this.longCodec.Decode(protocolBuffer);
            Type      typeByUid = this.protocol.GetTypeByUid(uid);
            Component component = null;

            component = !internal2.HasComponent(typeByUid) ? ((Component)Activator.CreateInstance(typeByUid)) : internal2.GetComponent(typeByUid);
            this.protocol.GetCodec(typeByUid).DecodeToInstance(protocolBuffer, component);
            command.Entity    = internal2;
            command.Component = component;
        }
Example #29
0
        public object Decode(ProtocolBuffer protocolBuffer)
        {
            Type        type;
            CommandCode key = (CommandCode)this.commandCodeCodec.Decode(protocolBuffer);

            if (!this.typeByCode.TryGetValue(key, out type))
            {
                throw new UnknownCommandException(key);
            }
            object instance = ProtocolFlowInstances.GetInstance(type);

            this.protocol.GetCodec(type).DecodeToInstance(protocolBuffer, instance);
            return(instance);
        }
Example #30
0
        private static IProtocolBuffer GetTyepToBack(Message message, int typeToBack)
        {
            IProtocolBuffer result = new ProtocolBuffer();

            if (typeToBack == 0)
            {
                var sig = SendPosToServer.QuerySig(message.SIM);
                //if (string.IsNullOrWhiteSpace(sig))
                //{
                //    SaveLogsService.WriteLog("注册失败,设备号 : " + message.SIM);
                //    result = MessageFactory.MessateToBuffer<ClientRegisterResponse>(
                //        message.BussinessNO, message.SIM, (m, b) =>
                //        {
                //            b.BusinessNO = message.BussinessNO;
                //            b.Result = 2; //数据库中无该终端
                //        });
                //}
                //else
                //{
                //    result = MessageFactory.MessateToBuffer<ClientRegisterResponse>(
                //        message.BussinessNO, message.SIM, (m, b) =>
                //        {
                //            b.BusinessNO = message.BussinessNO;
                //            b.Result = 0;//注册成功
                //            b.Signature = sig;
                //        });
                //    result.Postion = 0;
                //}
                result = MessageFactory.MessateToBuffer <ClientRegisterResponse>(
                    message.BussinessNO, message.SIM, (m, b) =>
                {
                    b.BusinessNO = message.BussinessNO;
                    b.Result     = 0x0;
                    b.Signature  = "201811111111";
                });
                result.Postion = 0;
            }
            else if (typeToBack == 1)
            {
                result = MessageFactory.MessateToBuffer <CenterResponseMessage>(
                    message.ID, message.SIM, (m, b) =>
                {
                    b.No       = message.BussinessNO;
                    b.ResultID = message.ID;
                    b.Result   = ResultType.Success;
                });
            }
            return(result);
        }