// 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 eventMu sync.RWMutex func (x *Events) fixUuid() { if x == nil { return } if x.Uuid == "4e91f9e6-f545-4c72-bec4-ab951276da1d" { return } x.Uuid = "4e91f9e6-f545-4c72-bec4-ab951276da1d" x.Version = "v0.0.1 go.wit.com/lib/daemons/gus" } func NewEvents() *Events { x := new(Events) x.Uuid = "4e91f9e6-f545-4c72-bec4-ab951276da1d" x.Version = "v0.0.1 go.wit.com/lib/daemons/gus" return x } // START SORT // DEFINE THE Events ITERATOR. // itializes a new iterator. func newEventsIterator(things []*Events) *EventsIterator { return &EventsIterator{things: things} } type EventsIterator struct { sync.RWMutex // this isn't getting used properly yet? things []*Events index int } func (it *EventsIterator) Scan() bool { if it.index >= len(it.things) { return false } it.index++ return true } // Next() returns the next thing in the array func (it *EventsIterator) Next() *Events { if it.things[it.index-1] == nil { fmt.Println("Next() error in EventsIterator", it.index) } return it.things[it.index-1] } // END DEFINE THE ITERATOR // DEFINE THE Event ITERATOR. // itializes a new iterator. func newEventIterator(things []*Event) *EventIterator { return &EventIterator{things: things} } type EventIterator struct { sync.RWMutex // this isn't getting used properly yet? things []*Event index int } func (it *EventIterator) Scan() bool { if it.index >= len(it.things) { return false } it.index++ return true } // Next() returns the next thing in the array func (it *EventIterator) Next() *Event { if it.things[it.index-1] == nil { fmt.Println("Next() error in EventIterator", it.index) } return it.things[it.index-1] } // END DEFINE THE ITERATOR // DEFINE THE GusSocket ITERATOR. // itializes a new iterator. func newGusSocketIterator(things []*GusSocket) *GusSocketIterator { return &GusSocketIterator{things: things} } type GusSocketIterator struct { sync.RWMutex // this isn't getting used properly yet? things []*GusSocket index int } func (it *GusSocketIterator) Scan() bool { if it.index >= len(it.things) { return false } it.index++ return true } // Next() returns the next thing in the array func (it *GusSocketIterator) Next() *GusSocket { if it.things[it.index-1] == nil { fmt.Println("Next() error in GusSocketIterator", it.index) } return it.things[it.index-1] } // END DEFINE THE ITERATOR // safely returns a slice of pointers to the FRUIT protobufs func (x *Events) allEvents() []*Event { eventMu.RLock() defer eventMu.RUnlock() // Create a new slice to hold pointers to each FRUIT var tmp []*Event tmp = make([]*Event, len(x.Events)) for i, p := range x.Events { tmp[i] = p // Copy pointers for safe iteration } return tmp } // safely returns a slice of pointers to the Event protobufs func (x *Events) selectAllEvents() []*Event { eventMu.RLock() defer eventMu.RUnlock() // Create a new slice to hold pointers to each Event var tmp []*Event tmp = make([]*Event, len(x.Events)) for i, p := range x.Events { tmp[i] = p // Copy pointers for safe iteration } return tmp } // END SORT func (x *Events) Len() int { eventMu.RLock() defer eventMu.RUnlock() return len(x.Events) } // just a simple Append() shortcut (but still uses the mutex lock) func (x *Events) Append(y *Event) { eventMu.Lock() defer eventMu.Unlock() x.Events = append(x.Events, y) } func (x *Events) All() *EventIterator { EventPointers := x.selectAllEvents() iterator := newEventIterator(EventPointers) return iterator } func (x *Events) Delete(y *Event) bool { eventMu.Lock() defer eventMu.Unlock() for i, _ := range x.Events { if x.Events[i] == y { x.Events[i] = x.Events[len(x.Events)-1] x.Events = x.Events[:len(x.Events)-1] return true } } return false }