Ejemplo n.º 1
0
        public static RoleTest Read(byte[] buffer, int offset)
        {
            var msg = new RoleTest();

            msg.RoleId = BitConverter.ToInt16(buffer, offset);
            offset    += 2;
            var RoleNameLength = buffer[offset];

            offset++;
            msg.RoleName = StringEncoding.GetString(buffer, offset, RoleNameLength);
            offset      += RoleNameLength;
            msg.Id       = Int24.ReadInt24(buffer, offset);
            offset      += 3;
            var countIds = buffer[offset];

            offset++;
            var listIds = new List <int>();

            for (var i = 0; i < countIds; i++)
            {
                var item = Int24.ReadInt24(buffer, offset);
                offset += 3;
                listIds.Add(item);
            }
            msg.Ids = listIds;
            return(msg);
        }
Ejemplo n.º 2
0
        static void TestUser()
        {
            var _role = new RoleTest();

            _role.RoleId   = 2;
            _role.RoleName = "admin";
            var roleBuffer = _role.Write();
            var _role1     = RoleTest.Read(roleBuffer, 0);


            var user = new UserTest();

            user.Bool     = false;
            user.boolList = new List <bool>()
            {
                false, true
            };
            user.Char      = 'A';
            user.floatList = new List <float>()
            {
                12.1F, 12.1F
            };
            user.Id     = 1;
            user.IdList = new List <int>()
            {
                1, 2, 3
            };
            user.StringList = new List <string>()
            {
                "SS", "ERC"
            };
            user.UInt16 = 12;
            user.UShort = 2342;
            var role = new RoleTest();

            role.RoleId   = 2;
            role.RoleName = "admin";
            role.Id       = -122334;
            role.Ids      = new List <int>()
            {
                Int24.MiniValue, Int24.MaxVlaue, 0
            };
            user.Role = role;
            var roleList = new List <RoleTest>();
            var role1    = new RoleTest();

            role1.RoleId   = 3;
            role1.Id       = 1222;
            role1.RoleName = "user1";
            roleList.Add(role1);
            var role2 = new RoleTest();

            role2.RoleId   = 4;
            role2.Id       = -3737;
            role2.RoleName = "user2";
            roleList.Add(role2);
            roleList.Add(role);
            user.RoleList = roleList;

            var buffer = user.Write();
            var _user  = UserTest.Read(buffer, 0);

            ;
        }
Ejemplo n.º 3
0
        public static UserTest Read(byte[] buffer, int offset)
        {
            var msg = new UserTest();

            msg.UInt16 = BitConverter.ToUInt16(buffer, offset);
            offset    += 2;
            msg.Char   = (Char)buffer[offset];
            offset++;
            msg.Bool = buffer[offset] == 1;
            offset++;
            msg.Int16  = BitConverter.ToInt16(buffer, offset);
            offset    += 2;
            msg.UShort = BitConverter.ToUInt16(buffer, offset);
            offset    += 2;
            msg.Id     = BitConverter.ToUInt16(buffer, offset);
            offset    += 2;
            var countIdList = buffer[offset];

            offset++;
            var listIdList = new List <int>();

            for (var i = 0; i < countIdList; i++)
            {
                var item = BitConverter.ToUInt16(buffer, offset);
                offset += 2;
                listIdList.Add(item);
            }
            msg.IdList = listIdList;
            var countboolList = buffer[offset];

            offset++;
            var listboolList = new List <bool>();

            for (var i = 0; i < countboolList; i++)
            {
                var item = buffer[offset] == 1;
                offset++;
                listboolList.Add(item);
            }
            msg.boolList = listboolList;
            var countIntList = buffer[offset];

            offset++;
            var listIntList = new List <int>();

            for (var i = 0; i < countIntList; i++)
            {
                var item = BitConverter.ToInt32(buffer, offset);
                offset += 4;
                listIntList.Add(item);
            }
            msg.IntList = listIntList;
            var countfloatList = buffer[offset];

            offset++;
            var listfloatList = new List <float>();

            for (var i = 0; i < countfloatList; i++)
            {
                var item = BitConverter.ToSingle(buffer, offset);
                offset += 4;
                listfloatList.Add(item);
            }
            msg.floatList = listfloatList;
            var countStringList = buffer[offset];

            offset++;
            var listStringList = new List <string>();

            for (var i = 0; i < countStringList; i++)
            {
                var strLength = buffer[offset];
                offset++;
                var item = StringEncoding.GetString(buffer, offset, strLength);
                offset += strLength;
                listStringList.Add(item);
            }
            msg.StringList = listStringList;
            var RoleLength = buffer[offset];

            offset++;
            if (RoleLength == 0)
            {
                msg.Role = null;
            }
            else
            {
                var _buffer = new ArraySegment <byte>(buffer, offset, RoleLength).ToArray();
                msg.Role = RoleTest.Read(_buffer, 0);
                offset  += RoleLength;
            }
            var countRoleList = buffer[offset];

            offset++;
            var listRoleTestList = new List <RoleTest>();

            for (var i = 0; i < countRoleList; i++)
            {
                var _RoleTestLength = buffer[offset];
                offset++;
                if (_RoleTestLength == 0)
                {
                    listRoleTestList.Add(null);
                }
                else
                {
                    var _buffer = new ArraySegment <byte>(buffer, offset, _RoleTestLength).ToArray();
                    listRoleTestList.Add(RoleTest.Read(_buffer, 0));
                    offset += _RoleTestLength;
                }
            }
            msg.RoleList = listRoleTestList;
            return(msg);
        }