Exemplo n.º 1
0
        private T TestBase <T>(T data)
        {
            var writer = NetPool.DataWriterPool.Alloc();

            try
            {
                NetDataSerializer.Serialize <T>(writer, data);
            }
            finally
            {
                NetPool.DataWriterPool.Free(writer);
            }

            byte[] buffer = writer.CopyData();
            var    reader = NetPool.DataReaderPool.Alloc();

            try
            {
                reader.SetSource(buffer);
                return(NetDataSerializer.Deserialize <T>(reader));
            }
            finally
            {
                NetPool.DataReaderPool.Free(reader);
            }
        }
Exemplo n.º 2
0
        public GenericDataStruct <T> Deserialize(NetDataReader _reader_, NetDataSerializerOptions options)
        {
            var __GenericValue = NetDataSerializer.Deserialize <T>(_reader_);

            return(new GenericDataStruct <T>()
            {
                GenericValue = __GenericValue,
            });
        }
Exemplo n.º 3
0
        public GenericClass <T> Deserialize(NetDataReader _reader_, NetDataSerializerOptions options)
        {
            var __SlotId = NetDataSerializer.Deserialize <T>(_reader_);

            return(new GenericClass <T>()
            {
                SlotId = __SlotId,
            });
        }
Exemplo n.º 4
0
        public RoomInfo Deserialize(NetDataReader _reader_, NetDataSerializerOptions options)
        {
            var __Name  = _reader_.ReadString();
            var __Slots = NetDataSerializer.Deserialize <SampleGameCommon.RoomSlotInfo[]>(_reader_);
            var __Id    = _reader_.ReadInt32();

            return(new RoomInfo()
            {
                Name = __Name,
                Slots = __Slots,
                Id = __Id,
            });
        }
Exemplo n.º 5
0
        public async Task <bool> Invoke(object _target_, NetDataReader _reader_, NetDataWriter _writer_)
        {
            ISession session  = _target_ as ISession;
            var      typeEnum = (IGreeterRpc_Enum)_reader_.ReadInt32();

            switch (typeEnum)
            {
            case IGreeterRpc_Enum.Greet:
            {
                var name     = _reader_.ReadString();
                var _result_ = await Greet(name);

                _writer_.Write(_result_);
            }
            break;

            case IGreeterRpc_Enum.GreetClass:
            {
                var dataClass = NetDataSerializer.Deserialize <Rpc.Test.Interface.DataClass>(_reader_);
                var _result_  = await GreetClass(dataClass);

                NetDataSerializer.Serialize <Rpc.Test.Interface.DataClass>(_writer_, _result_);
            }
            break;

            case IGreeterRpc_Enum.GreetInterfaceSerializeClass:
            {
                var dataClass = _reader_.Read <Rpc.Test.Interface.InterfaceSerializeClass>();
                var _result_  = await GreetInterfaceSerializeClass(dataClass);

                _writer_.Write <Rpc.Test.Interface.InterfaceSerializeClass>(_result_);
            }
            break;

            case IGreeterRpc_Enum.SessionParameter:
            {
                var _result_ = await SessionParameter(session);

                _writer_.Write(_result_);
            }
            break;

            default: return(false);
            }

            return(true);
        }
Exemplo n.º 6
0
        public async Task <Common.UserInfo> GetUserInfo()
        {
            var _writer_ = NetPool.DataWriterPool.Alloc();

            try
            {
                _writer_.Write((int)ILoginRpc_Enum.GetUserInfo);
                using (var _reader_ = await SendRequestAndReceive(_writer_))
                {
                    return(NetDataSerializer.Deserialize <Common.UserInfo>(_reader_));
                }
            }
            finally
            {
                NetPool.DataWriterPool.Free(_writer_);
            }
        }
Exemplo n.º 7
0
        public async Task <Rpc.Test.Interface.DataEnumForReturn> GreetEnumReturn()
        {
            var _writer_ = NetPool.DataWriterPool.Alloc();

            try
            {
                _writer_.Write((int)IGreeterRpc_Enum.GreetEnumReturn);
                using (var _reader_ = await SendRequestAndReceive(_writer_))
                {
                    return(NetDataSerializer.Deserialize <Rpc.Test.Interface.DataEnumForReturn>(_reader_));
                }
            }
            finally
            {
                NetPool.DataWriterPool.Free(_writer_);
            }
        }
Exemplo n.º 8
0
        public async Task <System.Tuple <int, System.Net.Sockets.SocketFlags> > GreetTuple(System.Tuple <string, string> value)
        {
            var _writer_ = NetPool.DataWriterPool.Alloc();

            try
            {
                _writer_.Write((int)IGreeterRpc_Enum.GreetTuple);
                NetDataSerializer.Serialize <System.Tuple <string, string> >(_writer_, value);
                using (var _reader_ = await SendRequestAndReceive(_writer_))
                {
                    return(NetDataSerializer.Deserialize <System.Tuple <int, System.Net.Sockets.SocketFlags> >(_reader_));
                }
            }
            finally
            {
                NetPool.DataWriterPool.Free(_writer_);
            }
        }
Exemplo n.º 9
0
        public async Task <System.Collections.Generic.Dictionary <int, int> > GreetDictionary(System.Collections.Generic.Dictionary <string, string> value)
        {
            var _writer_ = NetPool.DataWriterPool.Alloc();

            try
            {
                _writer_.Write((int)IGreeterRpc_Enum.GreetDictionary);
                NetDataSerializer.Serialize <System.Collections.Generic.Dictionary <string, string> >(_writer_, value);
                using (var _reader_ = await SendRequestAndReceive(_writer_))
                {
                    return(NetDataSerializer.Deserialize <System.Collections.Generic.Dictionary <int, int> >(_reader_));
                }
            }
            finally
            {
                NetPool.DataWriterPool.Free(_writer_);
            }
        }
Exemplo n.º 10
0
        public async Task <bool> Invoke(object _target_, NetDataReader _reader_, NetDataWriter _writer_)
        {
            ISession session  = _target_ as ISession;
            var      typeEnum = (IGreeterRpc_Enum)_reader_.ReadInt32();

            switch (typeEnum)
            {
            case IGreeterRpc_Enum.Greet:
            {
                var name     = _reader_.ReadString();
                var _result_ = await(session as IGreeterRpc).Greet(name);
                _writer_.Write(_result_);
            }
            break;

            case IGreeterRpc_Enum.GreetClass:
            {
                var dataClass = NetDataSerializer.Deserialize <Rpc.Test.Interface.DataClass>(_reader_);
                var _result_  = await(session as IGreeterRpc).GreetClass(dataClass);
                NetDataSerializer.Serialize <Rpc.Test.Interface.DataClass>(_writer_, _result_);
            }
            break;

            case IGreeterRpc_Enum.GreetDictionary:
            {
                var value    = NetDataSerializer.Deserialize <System.Collections.Generic.Dictionary <string, string> >(_reader_);
                var _result_ = await(session as IGreeterRpc).GreetDictionary(value);
                NetDataSerializer.Serialize <System.Collections.Generic.Dictionary <int, int> >(_writer_, _result_);
            }
            break;

            case IGreeterRpc_Enum.GreetEnum:
            {
                var dataEnum = NetDataSerializer.Deserialize <Rpc.Test.Interface.DataEnum>(_reader_);
                await(session as IGreeterRpc).GreetEnum(dataEnum);
            }
            break;

            case IGreeterRpc_Enum.GreetEnumOther:
            {
                var flags = NetDataSerializer.Deserialize <System.Net.Sockets.SocketFlags>(_reader_);
                await(session as IGreeterRpc).GreetEnumOther(flags);
            }
            break;

            case IGreeterRpc_Enum.GreetEnumReturn:
            {
                var _result_ = await(session as IGreeterRpc).GreetEnumReturn();
                NetDataSerializer.Serialize <Rpc.Test.Interface.DataEnumForReturn>(_writer_, _result_);
            }
            break;

            case IGreeterRpc_Enum.GreetInterfaceSerializeClass:
            {
                var dataClass = _reader_.Read <Rpc.Test.Interface.InterfaceSerializeClass>();
                var _result_  = await(session as IGreeterRpc).GreetInterfaceSerializeClass(dataClass);
                _writer_.Write <Rpc.Test.Interface.InterfaceSerializeClass>(_result_);
            }
            break;

            case IGreeterRpc_Enum.GreetTuple:
            {
                var value    = NetDataSerializer.Deserialize <System.Tuple <string, string> >(_reader_);
                var _result_ = await(session as IGreeterRpc).GreetTuple(value);
                NetDataSerializer.Serialize <System.Tuple <int, System.Net.Sockets.SocketFlags> >(_writer_, _result_);
            }
            break;

            case IGreeterRpc_Enum.SessionParameter:
            {
                var _result_ = await(session as IGreeterRpc).SessionParameter(session);
                _writer_.Write(_result_);
            }
            break;

            default: return(false);
            }

            return(true);
        }