autogenpb/file.sort.pb.go

540 lines
11 KiB
Go

// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
// This file was autogenerated with autogenpb v0.5.3 2025-09-13_13:40: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"
"iter"
"sync"
"google.golang.org/protobuf/proto"
)
// a simple global lock
var fileMu sync.RWMutex
func (x *Files) fixUuid() {
if x == nil {
return
}
if x.Uuid == "6c9ae4dd-648d-4b51-9738-bd59fb8fafd5" {
return
}
x.Uuid = "6c9ae4dd-648d-4b51-9738-bd59fb8fafd5"
x.Version = "v0.0.38 go.wit.com/apps/autogenpb"
}
func NewFiles() *Files {
x := new(Files)
x.Uuid = "6c9ae4dd-648d-4b51-9738-bd59fb8fafd5"
x.Version = "v0.0.38 go.wit.com/apps/autogenpb"
return x
}
// START SORT
// DEFINE THE Files SCANNER.
// itializes a new scanner.
func newFilesScanner(things []*Files) *FilesScanner {
return &FilesScanner{things: things}
}
type FilesScanner struct {
sync.Mutex
things []*Files
index int
}
func (it *FilesScanner) 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 *FilesScanner) Next() *Files {
if it.things[it.index-1] == nil {
fmt.Println("Next() error in FilesScanner", it.index)
}
return it.things[it.index-1]
}
// END DEFINE THE SCANNER
// DEFINE THE File SCANNER.
// itializes a new scanner.
func newFileScanner(things []*File) *FileScanner {
return &FileScanner{things: things}
}
type FileScanner struct {
sync.Mutex
things []*File
index int
}
func (it *FileScanner) 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 *FileScanner) Next() *File {
if it.things[it.index-1] == nil {
fmt.Println("Next() error in FileScanner", it.index)
}
return it.things[it.index-1]
}
// END DEFINE THE SCANNER
// DEFINE THE MsgVar SCANNER.
// itializes a new scanner.
func newMsgVarScanner(things []*MsgVar) *MsgVarScanner {
return &MsgVarScanner{things: things}
}
type MsgVarScanner struct {
sync.Mutex
things []*MsgVar
index int
}
func (it *MsgVarScanner) 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 *MsgVarScanner) Next() *MsgVar {
if it.things[it.index-1] == nil {
fmt.Println("Next() error in MsgVarScanner", it.index)
}
return it.things[it.index-1]
}
// END DEFINE THE SCANNER
// DEFINE THE MsgName SCANNER.
// itializes a new scanner.
func newMsgNameScanner(things []*MsgName) *MsgNameScanner {
return &MsgNameScanner{things: things}
}
type MsgNameScanner struct {
sync.Mutex
things []*MsgName
index int
}
func (it *MsgNameScanner) 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 *MsgNameScanner) Next() *MsgName {
if it.things[it.index-1] == nil {
fmt.Println("Next() error in MsgNameScanner", it.index)
}
return it.things[it.index-1]
}
// END DEFINE THE SCANNER
// DEFINE THE Sort SCANNER.
// itializes a new scanner.
func newSortScanner(things []*Sort) *SortScanner {
return &SortScanner{things: things}
}
type SortScanner struct {
sync.Mutex
things []*Sort
index int
}
func (it *SortScanner) 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 *SortScanner) Next() *Sort {
if it.things[it.index-1] == nil {
fmt.Println("Next() error in SortScanner", it.index)
}
return it.things[it.index-1]
}
// END DEFINE THE SCANNER
// DEFINE THE FormatMsg SCANNER.
// itializes a new scanner.
func newFormatMsgScanner(things []*FormatMsg) *FormatMsgScanner {
return &FormatMsgScanner{things: things}
}
type FormatMsgScanner struct {
sync.Mutex
things []*FormatMsg
index int
}
func (it *FormatMsgScanner) 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 *FormatMsgScanner) Next() *FormatMsg {
if it.things[it.index-1] == nil {
fmt.Println("Next() error in FormatMsgScanner", it.index)
}
return it.things[it.index-1]
}
// END DEFINE THE SCANNER
// DEFINE THE Find SCANNER.
// itializes a new scanner.
func newFindScanner(things []*Find) *FindScanner {
return &FindScanner{things: things}
}
type FindScanner struct {
sync.Mutex
things []*Find
index int
}
func (it *FindScanner) 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 *FindScanner) Next() *Find {
if it.things[it.index-1] == nil {
fmt.Println("Next() error in FindScanner", 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
// safely returns a slice of pointers to the FRUIT protobufs
func (x *Files) allFiles() []*File {
x.RLock()
defer x.RUnlock()
// Create a new slice to hold pointers to each FRUIT
var tmp []*File
tmp = make([]*File, len(x.Files))
for i, p := range x.Files {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// safely returns a slice of pointers to the FRUIT protobufs
func (x *File) allMsgNames() []*MsgName {
x.RLock()
defer x.RUnlock()
// Create a new slice to hold pointers to each FRUIT
var tmp []*MsgName
tmp = make([]*MsgName, len(x.MsgNames))
for i, p := range x.MsgNames {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// safely returns a slice of pointers to the FRUIT protobufs
func (x *File) allSortNames() []*MsgName {
x.RLock()
defer x.RUnlock()
// Create a new slice to hold pointers to each FRUIT
var tmp []*MsgName
tmp = make([]*MsgName, len(x.SortNames))
for i, p := range x.SortNames {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// safely returns a slice of pointers to the FRUIT protobufs
func (x *File) allToSort() []*Sort {
x.RLock()
defer x.RUnlock()
// Create a new slice to hold pointers to each FRUIT
var tmp []*Sort
tmp = make([]*Sort, len(x.ToSort))
for i, p := range x.ToSort {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// safely returns a slice of pointers to the FRUIT protobufs
func (x *MsgName) allVars() []*MsgVar {
x.RLock()
defer x.RUnlock()
// Create a new slice to hold pointers to each FRUIT
var tmp []*MsgVar
tmp = make([]*MsgVar, len(x.Vars))
for i, p := range x.Vars {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// safely returns a slice of pointers to the FRUIT protobufs
func (x *FormatMsg) allMsgs() []*FormatMsg {
x.RLock()
defer x.RUnlock()
// Create a new slice to hold pointers to each FRUIT
var tmp []*FormatMsg
tmp = make([]*FormatMsg, len(x.Msgs))
for i, p := range x.Msgs {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// safely returns a slice of pointers to the File protobufs
func (x *Files) selectAllFiles() []*File {
x.RLock()
defer x.RUnlock()
// Create a new slice to hold pointers to each File
var tmp []*File
tmp = make([]*File, len(x.Files))
for i, p := range x.Files {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// safely returns a slice of pointers to the MsgName protobufs
func (x *File) selectAllMsgNames() []*MsgName {
x.RLock()
defer x.RUnlock()
// Create a new slice to hold pointers to each MsgName
var tmp []*MsgName
tmp = make([]*MsgName, len(x.MsgNames))
for i, p := range x.MsgNames {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// safely returns a slice of pointers to the MsgName protobufs
func (x *File) selectAllSortNames() []*MsgName {
x.RLock()
defer x.RUnlock()
// Create a new slice to hold pointers to each MsgName
var tmp []*MsgName
tmp = make([]*MsgName, len(x.SortNames))
for i, p := range x.SortNames {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// safely returns a slice of pointers to the Sort protobufs
func (x *File) selectAllToSort() []*Sort {
x.RLock()
defer x.RUnlock()
// Create a new slice to hold pointers to each Sort
var tmp []*Sort
tmp = make([]*Sort, len(x.ToSort))
for i, p := range x.ToSort {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// safely returns a slice of pointers to the MsgVar protobufs
func (x *MsgName) selectAllVars() []*MsgVar {
x.RLock()
defer x.RUnlock()
// Create a new slice to hold pointers to each MsgVar
var tmp []*MsgVar
tmp = make([]*MsgVar, len(x.Vars))
for i, p := range x.Vars {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// safely returns a slice of pointers to the FormatMsg protobufs
func (x *FormatMsg) selectAllMsgs() []*FormatMsg {
x.RLock()
defer x.RUnlock()
// Create a new slice to hold pointers to each FormatMsg
var tmp []*FormatMsg
tmp = make([]*FormatMsg, len(x.Msgs))
for i, p := range x.Msgs {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// END SORT
func (x *Files) Len() int {
x.RLock()
defer x.RUnlock()
return len(x.Files)
}
// a Append() shortcut (that does Clone() with a mutex) notsure if it really works
func (x *Files) Append(y *File) *File {
x.Lock()
defer x.Unlock()
z := proto.Clone(y).(*File)
x.Files = append(x.Files, z)
return z
}
func (x *Files) All() *FileScanner {
FilePointers := x.selectAllFiles()
scanner := newFileScanner(FilePointers)
return scanner
}
// Iterate 'for x := range' syntax using the awesome golang 1.24 'iter'
func (x *Files) IterAll() iter.Seq[*File] {
items := x.selectAllFiles()
// log.Println("Made All() Iter.Seq[] with length", len(items))
return func(yield func(*File) bool) {
for _, v := range items {
if !yield(v) {
return
}
}
}
}
func (x *Files) Delete(y *File) bool {
x.Lock()
defer x.Unlock()
for i, _ := range x.Files {
if x.Files[i] == y {
x.Files[i] = x.Files[len(x.Files)-1]
x.Files = x.Files[:len(x.Files)-1]
return true
}
}
return false
}