You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.9 KiB

// ------------------------------------------------------------------------
// 🚀 Project Active8
// 🔗 Active Thing (activething.com) git.activething.com/go
//
// File name actor_id.go
// ✍️ Created by DEV
// 📅 Modified 07/12/2024
//
// 🔒 Copyright 2024 activething.com
//
// 📜 LICENSE --------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package brbac
type (
ActorID uint64
)
// Type extrae los 6 bits más significativos para determinar el tipo de Actor.
func (a ActorID) Type() ActorType {
// Desplazar el ActorID 58 bits a la derecha para que los 6 bits más significativos estén al inicio,
// y luego convertirlos en un ActorType.
return ActorType(a >> 58) // Extraemos los 6 bits más significativos
}
// SetType establece los 6 bits más significativos como el tipo de Actor.
func (a ActorID) SetType(actorType ActorType) ActorID {
// Verificar que el tipo está dentro del rango de 6 bits (0-63).
if actorType > 0x3F { // 0x3F es 63 en decimal, el rango de 6 bits
panic(G.ErrInvalidActor)
}
// Establecer el nuevo tipo en los 6 bits más significativos.
return ActorID((a &^ (ActorID(0x3F) << 58)) | (ActorID(actorType) << 58))
}
func HasActor (actors []ActorID, id ActorID) bool {
for _,ai := range actors {
if ai == id {
return true
}
}
return false
}

Powered by TurnKey Linux.