// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT. // This file was autogenerated with autogenpb v0.0.65 2025-03-12_15:38:32_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" "sync" ) // 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 ITERATOR. // itializes a new iterator. func newPortmapsIterator(things []*Portmaps) *PortmapsIterator { return &PortmapsIterator{things: things} } type PortmapsIterator struct { sync.RWMutex // this isn't getting used properly yet? things []*Portmaps index int } func (it *PortmapsIterator) Scan() bool { if it.index >= len(it.things) { return false } it.index++ return true } // Next() returns the next thing in the array func (it *PortmapsIterator) Next() *Portmaps { if it.things[it.index-1] == nil { fmt.Println("Next() error in PortmapsIterator", it.index) } return it.things[it.index-1] } // END DEFINE THE ITERATOR // DEFINE THE Portmap ITERATOR. // itializes a new iterator. func newPortmapIterator(things []*Portmap) *PortmapIterator { return &PortmapIterator{things: things} } type PortmapIterator struct { sync.RWMutex // this isn't getting used properly yet? things []*Portmap index int } func (it *PortmapIterator) Scan() bool { if it.index >= len(it.things) { return false } it.index++ return true } // Next() returns the next thing in the array func (it *PortmapIterator) Next() *Portmap { if it.things[it.index-1] == nil { fmt.Println("Next() error in PortmapIterator", it.index) } return it.things[it.index-1] } // END DEFINE THE ITERATOR // 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) } // just a simple Append() shortcut (but still uses the mutex lock) func (x *Portmaps) Append(y *Portmap) { portmapMu.Lock() defer portmapMu.Unlock() x.Portmaps = append(x.Portmaps, y) } func (x *Portmaps) All() *PortmapIterator { PortmapPointers := x.selectAllPortmaps() iterator := newPortmapIterator(PortmapPointers) return iterator } 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 }