// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT. // This file was autogenerated with autogenpb v0.5.3-12-g0ccf2c0 2025-09-18_03:40:35_UTC // go install go.wit.com/apps/autogenpb@latest // // define which structs (messages) you want to use in the .proto file // Then sort.pb.go and marshal.pb.go files are autogenerated // // autogenpb uses it and has an example .proto file with instructions // package main import ( "fmt" "iter" "sync" "google.golang.org/protobuf/proto" ) // a simple global lock var portmapMu sync.RWMutex func (x *Portmaps) fixUuid() { if x == nil { return } if x.Uuid == "49a865ea-292d-48fd-8dc2-d0f82d5fd016" { return } x.Uuid = "49a865ea-292d-48fd-8dc2-d0f82d5fd016" x.Version = "v0.0.1 go.wit.com/lib/daemons/gus" } func NewPortmaps() *Portmaps { x := new(Portmaps) x.Uuid = "49a865ea-292d-48fd-8dc2-d0f82d5fd016" x.Version = "v0.0.1 go.wit.com/lib/daemons/gus" return x } // START SORT // DEFINE THE Portmaps SCANNER. // itializes a new scanner. func newPortmapsScanner(things []*Portmaps) *PortmapsScanner { return &PortmapsScanner{things: things} } type PortmapsScanner struct { sync.Mutex things []*Portmaps index int } func (it *PortmapsScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *PortmapsScanner) Next() *Portmaps { if it.things[it.index-1] == nil { fmt.Println("Next() error in PortmapsScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE Portmap SCANNER. // itializes a new scanner. func newPortmapScanner(things []*Portmap) *PortmapScanner { return &PortmapScanner{things: things} } type PortmapScanner struct { sync.Mutex things []*Portmap index int } func (it *PortmapScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *PortmapScanner) Next() *Portmap { if it.things[it.index-1] == nil { fmt.Println("Next() error in PortmapScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // safely returns a slice of pointers to the FRUIT protobufs func (x *Portmaps) allPortmaps() []*Portmap { portmapMu.RLock() defer portmapMu.RUnlock() // Create a new slice to hold pointers to each FRUIT var tmp []*Portmap tmp = make([]*Portmap, len(x.Portmaps)) for i, p := range x.Portmaps { tmp[i] = p // Copy pointers for safe iteration } return tmp } // safely returns a slice of pointers to the Portmap protobufs func (x *Portmaps) selectAllPortmaps() []*Portmap { portmapMu.RLock() defer portmapMu.RUnlock() // Create a new slice to hold pointers to each Portmap var tmp []*Portmap tmp = make([]*Portmap, len(x.Portmaps)) for i, p := range x.Portmaps { tmp[i] = p // Copy pointers for safe iteration } return tmp } // END SORT func (x *Portmaps) Len() int { portmapMu.RLock() defer portmapMu.RUnlock() return len(x.Portmaps) } // a Append() shortcut (that does Clone() with a mutex) notsure if it really works func (x *Portmaps) Append(y *Portmap) *Portmap { portmapMu.Lock() defer portmapMu.Unlock() z := proto.Clone(y).(*Portmap) x.Portmaps = append(x.Portmaps, z) return z } func (x *Portmaps) All() *PortmapScanner { PortmapPointers := x.selectAllPortmaps() scanner := newPortmapScanner(PortmapPointers) return scanner } // Iterate 'for x := range' syntax using the awesome golang 1.24 'iter' func (x *Portmaps) IterAll() iter.Seq[*Portmap] { items := x.selectAllPortmaps() // log.Println("Made All() Iter.Seq[] with length", len(items)) return func(yield func(*Portmap) bool) { for _, v := range items { if !yield(v) { return } } } } func (x *Portmaps) Delete(y *Portmap) bool { portmapMu.Lock() defer portmapMu.Unlock() for i, _ := range x.Portmaps { if x.Portmaps[i] == y { x.Portmaps[i] = x.Portmaps[len(x.Portmaps)-1] x.Portmaps = x.Portmaps[:len(x.Portmaps)-1] return true } } return false } // lookup a Portmaps by the Localport func (x *Portmaps) FindByLocalport(y int64) *Portmap { if x == nil { return nil } portmapMu.RLock() defer portmapMu.RUnlock() for i, _ := range x.Portmaps { if x.Portmaps[i].Localport == y { return x.Portmaps[i] } } return nil } // returns a Portmap if Localport matches, otherwise create func (x *Portmaps) InsertByLocalport(y int64) *Portmap { portmapMu.Lock() defer portmapMu.Unlock() for _, z := range x.Portmaps { if z.Localport == y { return z } } z := new(Portmap) z.Localport = y x.Portmaps = append(x.Portmaps, z) return z }