59 lines
963 B
Go
59 lines
963 B
Go
package talkgroups
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"dynatron.me/x/stillbox/pkg/database"
|
|
)
|
|
|
|
type Talkgroup struct {
|
|
database.Talkgroup
|
|
System database.System `json:"system"`
|
|
Learned bool `json:"learned"`
|
|
}
|
|
|
|
type Metadata map[string]interface{}
|
|
|
|
type Names struct {
|
|
System string
|
|
Talkgroup string
|
|
}
|
|
|
|
type ID struct {
|
|
System uint32 `json:"sys"`
|
|
Talkgroup uint32 `json:"tg"`
|
|
}
|
|
|
|
type IDs []ID
|
|
|
|
func (ids *IDs) Tuples() []database.TalkgroupT {
|
|
r := make([]database.TalkgroupT, len(*ids))
|
|
for i := range *ids {
|
|
r[i] = (*ids)[i].Tuple()
|
|
}
|
|
|
|
return r
|
|
}
|
|
|
|
type intId interface {
|
|
int | uint | int64 | uint64 | int32 | uint32
|
|
}
|
|
|
|
func TG[T intId, U intId](sys T, tgid U) ID {
|
|
return ID{
|
|
System: uint32(sys),
|
|
Talkgroup: uint32(tgid),
|
|
}
|
|
}
|
|
|
|
func (t ID) Tuple() database.TalkgroupT {
|
|
return database.TalkgroupT{
|
|
System: t.System,
|
|
Talkgroup: t.Talkgroup,
|
|
}
|
|
}
|
|
|
|
func (t ID) String() string {
|
|
return fmt.Sprintf("%d:%d", t.System, t.Talkgroup)
|
|
|
|
}
|