Notes added by 'git notes append'

This commit is contained in:
Jeff Carr 2025-01-09 21:39:47 -06:00
parent e10b025644
commit 1f2b1e55b8
1 changed files with 96 additions and 0 deletions

View File

@ -1234,3 +1234,99 @@ func file_patch_proto_init() {
package forgepb package forgepb
// `autogen:uuid.newsort.pb.go` // `autogen:uuid.newsort.pb.go`
// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
// This file was autogenerated with autogenpb v0.0.37-30-g805d3cd 2025.01.09_2100
// 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"
"sync"
)
// bad global lock until modifying the .pb.go file is tested
// sync.RWMutex or sync.Mutex?
var uuidMu sync.RWMutex
type UuidIterator struct {
sync.RWMutex
things []*Uuid
index int
}
// NewUuidIterator initializes a new iterator.
func NewUuidIterator(things []*Uuid) *UuidIterator {
return &UuidIterator{things: things}
}
// Scan moves to the next element and returns false if there are no more things.
// Use Scan() in a loop, similar to a while loop
//
// for iterator.Scan()
// d := iterator.Next(
// fmt.Println("found UUID:", d.Uuid
// }
func (it *UuidIterator) Scan() bool {
if it.index >= len(it.things) {
return false
}
it.index++
return true
}
// Next() returns the next thing in the array
func (it *UuidIterator) Next() *Uuid {
if it.things[it.index-1] == nil {
for i, d := range it.things {
fmt.Println("i =", i, d)
}
}
return it.things[it.index-1]
}
// safely returns a slice of pointers to the Uuid protobufs
func (all *Uuids) selectAllUuid() []*Uuid {
uuidMu.RLock()
defer uuidMu.RUnlock()
// Create a new slice to hold pointers to each Uuid
var tmp []*Uuid
tmp = make([]*Uuid, len(all.Uuids))
for i, p := range all.Uuids {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// just a simple Append() with no checking (but still uses the mutex lock)
func (all *Uuids) Append(newP *Uuid) bool {
uuidMu.RLock()
defer uuidMu.RUnlock()
all.Uuids = append(all.Uuids, newP)
return true
}
func (all *Uuids) All() *UuidIterator {
UuidPointers := all.selectAllUuid()
iterator := NewUuidIterator(UuidPointers)
return iterator
}
func (all *Uuids) Len() int {
uuidMu.RLock()
defer uuidMu.RUnlock()
return len(all.Uuids)
}