internal override int ParseBlock(int receiveSize)
            {
                base.dataOffset = 0;

                while (base.dataOffset < receiveSize)
                {
                    int resultCode = base.dataBuffer[base.dataOffset + 1];

                    if (resultCode != 0)
                    {
                        return resultCode;
                    }

                    Role role = new Role();
                    int fieldCount = base.dataBuffer[base.dataOffset + 3];
                    base.dataOffset += HEADER_REMAINING;

                    for (int i = 0; i < fieldCount; i++)
                    {
                        int len = ByteUtil.BytesToInt(base.dataBuffer, base.dataOffset);
                        base.dataOffset += 4;
                        int id = base.dataBuffer[base.dataOffset++];
                        len--;

                        if (id == ROLE)
                        {
                            role.name = ByteUtil.Utf8ToString(base.dataBuffer, base.dataOffset, len);
                            base.dataOffset += len;
                        }
                        else if (id == PRIVILEGES)
                        {
                            ParsePrivileges(role);
                        }
                        else
                        {
                            base.dataOffset += len;
                        }
                    }

                    if (role.name == null && role.privileges == null)
                    {
                        continue;
                    }

                    if (role.privileges == null)
                    {
                        role.privileges = new List<Privilege>(0);
                    }
                    list.Add(role);
                }
                return 0;
            }
            internal void ParsePrivileges(Role role)
            {
                int size = base.dataBuffer[base.dataOffset++];
                role.privileges = new List<Privilege>(size);

                for (int i = 0; i < size; i++)
                {
                    Privilege priv = new Privilege();
                    priv.code = (PrivilegeCode)base.dataBuffer[base.dataOffset++];

                    if (priv.CanScope())
                    {
                        int len = base.dataBuffer[base.dataOffset++];
                        priv.ns = ByteUtil.Utf8ToString(base.dataBuffer, base.dataOffset, len);
                        base.dataOffset += len;

                        len = base.dataBuffer[base.dataOffset++];
                        priv.setName = ByteUtil.Utf8ToString(base.dataBuffer, base.dataOffset, len);
                        base.dataOffset += len;
                    }
                    role.privileges.Add(priv);
                }
            }
Пример #3
0
 public RoleRow(Role role)
 {
     this.name = role.name;
     this.privileges = role.privileges;
     this.privilegeRows = new BindingList<Privilege>(role.privileges);
 }