xstartplacement/placement.sort.pb.go

145 lines
3.2 KiB
Go

// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
// This file was autogenerated with autogenpb v0.5.0 2025-09-11_08:28:21_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 placementMu sync.RWMutex
func (x *Placements) fixUuid() {
if x == nil {
return
}
if x.Uuid == "31769bcb-5865-4926-b7d6-501083312eea" {
return
}
x.Uuid = "31769bcb-5865-4926-b7d6-501083312eea"
x.Version = "v0.0.1 go.wit.com/apps/utils/startxplacement"
}
func NewPlacements() *Placements {
x := new(Placements)
x.Uuid = "31769bcb-5865-4926-b7d6-501083312eea"
x.Version = "v0.0.1 go.wit.com/apps/utils/startxplacement"
return x
}
// START SORT
// DEFINE THE Placements SCANNER.
// itializes a new scanner.
func newPlacementsScanner(things []*Placements) *PlacementsScanner {
return &PlacementsScanner{things: things}
}
type PlacementsScanner struct {
sync.Mutex
things []*Placements
index int
}
func (it *PlacementsScanner) 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 *PlacementsScanner) Next() *Placements {
if it.things[it.index-1] == nil {
fmt.Println("Next() error in PlacementsScanner", it.index)
}
return it.things[it.index-1]
}
// END DEFINE THE SCANNER
// DEFINE THE Placement SCANNER.
// itializes a new scanner.
func newPlacementScanner(things []*Placement) *PlacementScanner {
return &PlacementScanner{things: things}
}
type PlacementScanner struct {
sync.Mutex
things []*Placement
index int
}
func (it *PlacementScanner) 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 *PlacementScanner) Next() *Placement {
if it.things[it.index-1] == nil {
fmt.Println("Next() error in PlacementScanner", it.index)
}
return it.things[it.index-1]
}
// END DEFINE THE SCANNER
// sort struct by Name
type sortPlacementName []*Placement
func (a sortPlacementName) Len() int { return len(a) }
func (a sortPlacementName) Less(i, j int) bool { return a[i].Name < a[j].Name }
func (a sortPlacementName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
// safely returns a slice of pointers to the FRUIT protobufs
func (x *Placements) allPlacement() []*Placement {
x.RLock()
defer x.RUnlock()
// Create a new slice to hold pointers to each FRUIT
var tmp []*Placement
tmp = make([]*Placement, len(x.Placement))
for i, p := range x.Placement {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// safely returns a slice of pointers to the Placement protobufs
func (x *Placements) selectAllPlacement() []*Placement {
x.RLock()
defer x.RUnlock()
// Create a new slice to hold pointers to each Placement
var tmp []*Placement
tmp = make([]*Placement, len(x.Placement))
for i, p := range x.Placement {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// END SORT