// 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:48:42_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 prep import ( "fmt" "iter" "sync" "google.golang.org/protobuf/proto" ) // a simple global lock var autoMu sync.RWMutex func (x *Autos) fixUuid() { if x == nil { return } if x.Uuid == "94210ebf-a534-4b33-aadd-2f5e1f56ae38" { return } x.Uuid = "94210ebf-a534-4b33-aadd-2f5e1f56ae38" x.Version = "v0.0.1 go.wit.com/lib/gui/prep" } func NewAutos() *Autos { x := new(Autos) x.Uuid = "94210ebf-a534-4b33-aadd-2f5e1f56ae38" x.Version = "v0.0.1 go.wit.com/lib/gui/prep" return x } // START SORT // DEFINE THE Autos SCANNER. // itializes a new scanner. func newAutosScanner(things []*Autos) *AutosScanner { return &AutosScanner{things: things} } type AutosScanner struct { sync.Mutex things []*Autos index int } func (it *AutosScanner) 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 *AutosScanner) Next() *Autos { if it.things[it.index-1] == nil { fmt.Println("Next() error in AutosScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE Auto SCANNER. // itializes a new scanner. func newAutoScanner(things []*Auto) *AutoScanner { return &AutoScanner{things: things} } type AutoScanner struct { sync.Mutex things []*Auto index int } func (it *AutoScanner) 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 *AutoScanner) Next() *Auto { if it.things[it.index-1] == nil { fmt.Println("Next() error in AutoScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // safely returns a slice of pointers to the FRUIT protobufs func (x *Autos) allAutos() []*Auto { autoMu.RLock() defer autoMu.RUnlock() // Create a new slice to hold pointers to each FRUIT var tmp []*Auto tmp = make([]*Auto, len(x.Autos)) for i, p := range x.Autos { tmp[i] = p // Copy pointers for safe iteration } return tmp } // safely returns a slice of pointers to the Auto protobufs func (x *Autos) selectAllAutos() []*Auto { autoMu.RLock() defer autoMu.RUnlock() // Create a new slice to hold pointers to each Auto var tmp []*Auto tmp = make([]*Auto, len(x.Autos)) for i, p := range x.Autos { tmp[i] = p // Copy pointers for safe iteration } return tmp } // END SORT func (x *Autos) Len() int { autoMu.RLock() defer autoMu.RUnlock() return len(x.Autos) } // a Append() shortcut (that does Clone() with a mutex) notsure if it really works func (x *Autos) Append(y *Auto) *Auto { autoMu.Lock() defer autoMu.Unlock() z := proto.Clone(y).(*Auto) x.Autos = append(x.Autos, z) return z } func (x *Autos) All() *AutoScanner { AutoPointers := x.selectAllAutos() scanner := newAutoScanner(AutoPointers) return scanner } // Iterate 'for x := range' syntax using the awesome golang 1.24 'iter' func (x *Autos) IterAll() iter.Seq[*Auto] { items := x.selectAllAutos() // log.Println("Made All() Iter.Seq[] with length", len(items)) return func(yield func(*Auto) bool) { for _, v := range items { if !yield(v) { return } } } } func (x *Autos) Delete(y *Auto) bool { autoMu.Lock() defer autoMu.Unlock() for i, _ := range x.Autos { if x.Autos[i] == y { x.Autos[i] = x.Autos[len(x.Autos)-1] x.Autos = x.Autos[:len(x.Autos)-1] return true } } return false }