// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT. // This file was autogenerated with autogenpb v0.5.6-2-gfabf425 2025-09-23_15:21:15_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 forgepb import ( "fmt" "iter" "sort" "sync" "google.golang.org/protobuf/proto" ) // a simple global lock var forgeConfigMu sync.RWMutex func (x *ForgeConfigs) fixUuid() { if x == nil { return } if x.Uuid == "1941cd4f-1cfd-4bf6-aa75-c2c391907e81" { return } x.Uuid = "1941cd4f-1cfd-4bf6-aa75-c2c391907e81" x.Version = "v0.0.47 go.wit.com/lib/protobuf/forgepb" } func NewForgeConfigs() *ForgeConfigs { x := new(ForgeConfigs) x.Uuid = "1941cd4f-1cfd-4bf6-aa75-c2c391907e81" x.Version = "v0.0.47 go.wit.com/lib/protobuf/forgepb" return x } // START SORT // DEFINE THE ForgeConfigs SCANNER. // itializes a new scanner. func newForgeConfigsScanner(things []*ForgeConfigs) *ForgeConfigsScanner { return &ForgeConfigsScanner{things: things} } type ForgeConfigsScanner struct { sync.Mutex things []*ForgeConfigs index int } func (it *ForgeConfigsScanner) 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 *ForgeConfigsScanner) Next() *ForgeConfigs { if it.things[it.index-1] == nil { fmt.Println("Next() error in ForgeConfigsScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE ForgeConfig SCANNER. // itializes a new scanner. func newForgeConfigScanner(things []*ForgeConfig) *ForgeConfigScanner { return &ForgeConfigScanner{things: things} } type ForgeConfigScanner struct { sync.Mutex things []*ForgeConfig index int } func (it *ForgeConfigScanner) 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 *ForgeConfigScanner) Next() *ForgeConfig { if it.things[it.index-1] == nil { fmt.Println("Next() error in ForgeConfigScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE Identify SCANNER. // itializes a new scanner. func newIdentifyScanner(things []*Identify) *IdentifyScanner { return &IdentifyScanner{things: things} } type IdentifyScanner struct { sync.Mutex things []*Identify index int } func (it *IdentifyScanner) 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 *IdentifyScanner) Next() *Identify { if it.things[it.index-1] == nil { fmt.Println("Next() error in IdentifyScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // sort struct by GoPath type sortForgeConfigGoPath []*ForgeConfig func (a sortForgeConfigGoPath) Len() int { return len(a) } func (a sortForgeConfigGoPath) Less(i, j int) bool { return a[i].GoPath < a[j].GoPath } func (a sortForgeConfigGoPath) Swap(i, j int) { a[i], a[j] = a[j], a[i] } // sort struct by Namespace type sortForgeConfigNamespace []*ForgeConfig func (a sortForgeConfigNamespace) Len() int { return len(a) } func (a sortForgeConfigNamespace) Less(i, j int) bool { return a[i].Namespace < a[j].Namespace } func (a sortForgeConfigNamespace) Swap(i, j int) { a[i], a[j] = a[j], a[i] } // safely returns a slice of pointers to the FRUIT protobufs func (x *ForgeConfigs) allForgeConfigs() []*ForgeConfig { forgeConfigMu.RLock() defer forgeConfigMu.RUnlock() // Create a new slice to hold pointers to each FRUIT var tmp []*ForgeConfig tmp = make([]*ForgeConfig, len(x.ForgeConfigs)) for i, p := range x.ForgeConfigs { tmp[i] = p // Copy pointers for safe iteration } return tmp } // safely returns a slice of pointers to the ForgeConfig protobufs func (x *ForgeConfigs) selectAllForgeConfigs() []*ForgeConfig { forgeConfigMu.RLock() defer forgeConfigMu.RUnlock() // Create a new slice to hold pointers to each ForgeConfig var tmp []*ForgeConfig tmp = make([]*ForgeConfig, len(x.ForgeConfigs)) for i, p := range x.ForgeConfigs { tmp[i] = p // Copy pointers for safe iteration } return tmp } func (x *ForgeConfigs) SortByGoPath() *ForgeConfigScanner { // copy the pointers as fast as possible. things := x.selectAllForgeConfigs() // todo: try slices.SortFunc() instead to see what happens sort.Sort(sortForgeConfigGoPath(things)) // slices.SortFunc(things, func(a, b *ForgeConfigs) bool { // return a.GoPath < b.GoPath // Sort by ??. let the compiler work it out?? // }) return newForgeConfigScanner(things) } // 'for x := range' syntax using the awesome golang 1.24 'iter' func (x *ForgeConfigs) IterByGoPath() iter.Seq[*ForgeConfig] { items := x.selectAllForgeConfigs() sort.Sort(sortForgeConfigGoPath(items)) // log.Println("Made Iter.Seq[] with length", len(items)) return func(yield func(*ForgeConfig) bool) { for _, v := range items { if !yield(v) { return } } } } func (x *ForgeConfigs) SortByNamespace() *ForgeConfigScanner { // copy the pointers as fast as possible. things := x.selectAllForgeConfigs() // todo: try slices.SortFunc() instead to see what happens sort.Sort(sortForgeConfigNamespace(things)) // slices.SortFunc(things, func(a, b *ForgeConfigs) bool { // return a.Namespace < b.Namespace // Sort by ??. let the compiler work it out?? // }) return newForgeConfigScanner(things) } // 'for x := range' syntax using the awesome golang 1.24 'iter' func (x *ForgeConfigs) IterByNamespace() iter.Seq[*ForgeConfig] { items := x.selectAllForgeConfigs() sort.Sort(sortForgeConfigNamespace(items)) // log.Println("Made Iter.Seq[] with length", len(items)) return func(yield func(*ForgeConfig) bool) { for _, v := range items { if !yield(v) { return } } } } // END SORT func (x *ForgeConfigs) Len() int { forgeConfigMu.RLock() defer forgeConfigMu.RUnlock() return len(x.ForgeConfigs) } // a Append() shortcut (that does Clone() with a mutex) notsure if it really works func (x *ForgeConfigs) Append(y *ForgeConfig) *ForgeConfig { forgeConfigMu.Lock() defer forgeConfigMu.Unlock() z := proto.Clone(y).(*ForgeConfig) x.ForgeConfigs = append(x.ForgeConfigs, z) return z } func (x *ForgeConfigs) All() *ForgeConfigScanner { ForgeConfigPointers := x.selectAllForgeConfigs() scanner := newForgeConfigScanner(ForgeConfigPointers) return scanner } // Iterate 'for x := range' syntax using the awesome golang 1.24 'iter' func (x *ForgeConfigs) IterAll() iter.Seq[*ForgeConfig] { items := x.selectAllForgeConfigs() // log.Println("Made All() Iter.Seq[] with length", len(items)) return func(yield func(*ForgeConfig) bool) { for _, v := range items { if !yield(v) { return } } } } func (x *ForgeConfigs) Delete(y *ForgeConfig) bool { forgeConfigMu.Lock() defer forgeConfigMu.Unlock() for i, _ := range x.ForgeConfigs { if x.ForgeConfigs[i] == y { x.ForgeConfigs[i] = x.ForgeConfigs[len(x.ForgeConfigs)-1] x.ForgeConfigs = x.ForgeConfigs[:len(x.ForgeConfigs)-1] return true } } return false } // lookup a ForgeConfigs by the GoPath func (x *ForgeConfigs) FindByGoPath(s string) *ForgeConfig { if x == nil { return nil } forgeConfigMu.RLock() defer forgeConfigMu.RUnlock() for i, _ := range x.ForgeConfigs { if x.ForgeConfigs[i].GoPath == s { return x.ForgeConfigs[i] } } return nil } // returns a ForgeConfig if GoPath matches, otherwise create func (x *ForgeConfigs) InsertByGoPath(y string) *ForgeConfig { forgeConfigMu.Lock() defer forgeConfigMu.Unlock() for _, z := range x.ForgeConfigs { if z.GoPath == y { return z } } z := new(ForgeConfig) z.GoPath = y x.ForgeConfigs = append(x.ForgeConfigs, z) return z } // lookup a ForgeConfigs by the Namespace func (x *ForgeConfigs) FindByNamespace(s string) *ForgeConfig { if x == nil { return nil } forgeConfigMu.RLock() defer forgeConfigMu.RUnlock() for i, _ := range x.ForgeConfigs { if x.ForgeConfigs[i].Namespace == s { return x.ForgeConfigs[i] } } return nil } // returns a ForgeConfig if Namespace matches, otherwise create func (x *ForgeConfigs) InsertByNamespace(y string) *ForgeConfig { forgeConfigMu.Lock() defer forgeConfigMu.Unlock() for _, z := range x.ForgeConfigs { if z.Namespace == y { return z } } z := new(ForgeConfig) z.Namespace = y x.ForgeConfigs = append(x.ForgeConfigs, z) return z } func (x *ForgeConfigs) DeleteByGoPath(s string) bool { forgeConfigMu.Lock() defer forgeConfigMu.Unlock() for i, _ := range x.ForgeConfigs { if x.ForgeConfigs[i].GoPath == s { x.ForgeConfigs[i] = x.ForgeConfigs[len(x.ForgeConfigs)-1] x.ForgeConfigs = x.ForgeConfigs[:len(x.ForgeConfigs)-1] return true } } return false } func (x *ForgeConfigs) DeleteByNamespace(s string) bool { forgeConfigMu.Lock() defer forgeConfigMu.Unlock() for i, _ := range x.ForgeConfigs { if x.ForgeConfigs[i].Namespace == s { x.ForgeConfigs[i] = x.ForgeConfigs[len(x.ForgeConfigs)-1] x.ForgeConfigs = x.ForgeConfigs[:len(x.ForgeConfigs)-1] return true } } return false } func (x *ForgeConfigs) AppendByGoPath(y *ForgeConfig) bool { forgeConfigMu.Lock() defer forgeConfigMu.Unlock() for _, p := range x.ForgeConfigs { if p.GoPath == y.GoPath { return false } } x.ForgeConfigs = append(x.ForgeConfigs, proto.Clone(y).(*ForgeConfig)) return true } func (x *ForgeConfigs) AppendByNamespace(y *ForgeConfig) bool { forgeConfigMu.Lock() defer forgeConfigMu.Unlock() for _, p := range x.ForgeConfigs { if p.Namespace == y.Namespace { return false } } x.ForgeConfigs = append(x.ForgeConfigs, proto.Clone(y).(*ForgeConfig)) return true }