Clean up tg ID stuff

This commit is contained in:
Daniel Ponte 2024-11-07 12:53:20 -05:00
parent c423749f26
commit d0c398f6f7
2 changed files with 7 additions and 12 deletions

View file

@ -127,7 +127,7 @@ func (t *cache) add(rec *Talkgroup) error {
t.Lock() t.Lock()
defer t.Unlock() defer t.Unlock()
tg := TG(rec.System.ID, int(rec.Talkgroup.Tgid)) tg := TG(rec.System.ID, rec.Talkgroup.Tgid)
t.tgs[tg] = rec t.tgs[tg] = rec
t.systems[int32(rec.System.ID)] = rec.System.Name t.systems[int32(rec.System.ID)] = rec.System.Name

View file

@ -28,7 +28,11 @@ func (ids *IDs) Packed() []int64 {
return r return r
} }
func TG[T int | uint | int64 | uint64 | int32 | uint32](sys, tgid T) ID { type intId interface {
int | uint | int64 | uint64 | int32 | uint32
}
func TG[T intId, U intId](sys T, tgid U) ID {
return ID{ return ID{
System: uint32(sys), System: uint32(sys),
Talkgroup: uint32(tgid), Talkgroup: uint32(tgid),
@ -42,14 +46,5 @@ func (t ID) Pack() int64 {
func (t ID) String() string { func (t ID) String() string {
return fmt.Sprintf("%d:%d", t.System, t.Talkgroup) return fmt.Sprintf("%d:%d", t.System, t.Talkgroup)
}
func PackedTGs(tg []ID) []int64 {
s := make([]int64, len(tg))
for i, v := range tg {
s[i] = v.Pack()
}
return s
} }