125 lines
3.3 KiB
Go
125 lines
3.3 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"go.wit.com/log"
|
|
)
|
|
|
|
// This was just going to be a function to print the results to stdout
|
|
|
|
// print the protobuf in human form
|
|
func (pf *File) printMsgTable() error {
|
|
pf.Bases.printMsg()
|
|
pf.Base.printMsg()
|
|
|
|
// everything else
|
|
for _, msg := range pf.MsgNames {
|
|
msg.printMsg()
|
|
}
|
|
|
|
log.Printf("\n")
|
|
log.Printf(" %-2s %20s %20s %20s %20s\n", "", "PARENT STRUCT", "VAR STRUCT TYPE", "VAR NAME", "LOCK")
|
|
// for i, s := range slices.Backward(pf.ToSort) {
|
|
for i, s := range pf.ToSort {
|
|
var funcname string
|
|
STRUCT := s.MsgName
|
|
CHILD := s.VarType
|
|
VARNAME := s.VarName
|
|
LOCK := s.Lockname
|
|
|
|
log.Printf("SORT: %-2d %20s %20s %20s %20s %s\n", i, STRUCT, CHILD, VARNAME, LOCK, "")
|
|
|
|
var FUNCTYPE string
|
|
if STRUCT == VARNAME {
|
|
FUNCTYPE = STRUCT
|
|
} else {
|
|
FUNCTYPE = VARNAME
|
|
}
|
|
|
|
if s.VarType+"s" == s.VarName {
|
|
funcname = "func (x *" + FUNCTYPE + ") All() *[]iter" + s.VarType
|
|
} else {
|
|
funcname = "func (x *" + FUNCTYPE + ") all" + s.VarName + "() *[]iter" + s.VarType
|
|
}
|
|
log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "", "", funcname)
|
|
msg := pf.findMsg(s.VarType)
|
|
if msg == nil {
|
|
return fmt.Errorf("failed to find struct %s", s.VarType)
|
|
}
|
|
for _, v := range msg.Vars {
|
|
if v.HasSort {
|
|
funcname := "func (x *" + FUNCTYPE + ") SortBy" + v.VarName + "(" + v.VarType + ") *[]iter" + s.VarType
|
|
log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "", "", funcname)
|
|
}
|
|
}
|
|
|
|
var ucount int
|
|
for _, v := range msg.Vars {
|
|
if v.HasUnique {
|
|
ucount += 1
|
|
funcname := "func (x *" + FUNCTYPE + ") AppendUnique" + v.VarName + "(" + v.VarType + ")"
|
|
log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "", "", funcname)
|
|
}
|
|
}
|
|
for _, v := range msg.Vars {
|
|
if v.HasUnique {
|
|
funcname := "func (x *" + FUNCTYPE + ") DeleteBy" + v.VarName + "(" + v.VarType + ") bool"
|
|
log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "", "", funcname)
|
|
}
|
|
}
|
|
|
|
for _, v := range msg.Vars {
|
|
if v.HasUnique {
|
|
funcname = "func (x *" + FUNCTYPE + ") FindBy" + v.VarName + "(a " + v.VarType + ") *" + s.VarType + "(using" + v.VarName + ")"
|
|
log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "", "", funcname)
|
|
} else {
|
|
if v.VarType == "string" {
|
|
funcname = "func (x *" + FUNCTYPE + ") FindBy" + v.VarName + "(a string) []*" + s.VarType + " ???"
|
|
log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "", "", funcname)
|
|
}
|
|
}
|
|
}
|
|
if ucount == 1 {
|
|
for _, v := range msg.Vars {
|
|
if !v.HasUnique {
|
|
continue
|
|
}
|
|
funcname = "func (x *" + FUNCTYPE + ") Insert(a *" + v.VarType + ") (*" + CHILD + ", isNew bool)"
|
|
log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "", "", funcname)
|
|
}
|
|
}
|
|
if ucount > 1 {
|
|
funcname = "func (x *" + FUNCTYPE + ") Insert(a *" + CHILD + ") (*" + CHILD + ", isNew bool)"
|
|
log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "", "", funcname)
|
|
}
|
|
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (msg *MsgName) printMsg() {
|
|
var s string
|
|
if msg.DoMutex {
|
|
s += "(mutex) "
|
|
}
|
|
if msg.DoMarshal {
|
|
s += "(marshal) "
|
|
}
|
|
log.Printf("%s %s\n", msg.Name, s)
|
|
|
|
for _, v := range msg.Vars {
|
|
var end string
|
|
if v.IsRepeated {
|
|
end += "(repeated) "
|
|
}
|
|
if v.HasSort {
|
|
end += "(sort) "
|
|
}
|
|
if v.HasUnique {
|
|
end += "(unique) "
|
|
}
|
|
log.Printf("\t%s %s %s\n", v.VarName, v.VarType, end)
|
|
}
|
|
}
|