marshal is converted to using the protobuf
This commit is contained in:
parent
62c93069c5
commit
0aa3457e7d
21
main.go
21
main.go
|
@ -159,27 +159,14 @@ func main() {
|
||||||
pb.addMutex(f)
|
pb.addMutex(f)
|
||||||
|
|
||||||
// if foo.pb.go still doesn't exist, protoc failed
|
// if foo.pb.go still doesn't exist, protoc failed
|
||||||
// exit here
|
if !shell.Exists(pbfile) {
|
||||||
if !shell.Exists(sortmap["protoc"]) {
|
log.Info("protoc build error.", pbfile)
|
||||||
log.Info("protoc build error.", sortmap["protoc"], "failed to be created with protoc and proto-gen-go")
|
|
||||||
badExit(errors.New("failed to be created with protoc and proto-gen-go"))
|
badExit(errors.New("failed to be created with protoc and proto-gen-go"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if argv.NoSort {
|
pb.marshal(f)
|
||||||
// log.Info("not making sort.pb.go file (--no-sort == true)")
|
|
||||||
} else {
|
|
||||||
if len(uniqueKeys) != 0 {
|
|
||||||
}
|
|
||||||
makeSortfile()
|
|
||||||
}
|
|
||||||
|
|
||||||
if argv.NoMarshal {
|
|
||||||
// log.Info("not making marshal.pb.go file (--no-marshal == true)")
|
|
||||||
} else {
|
|
||||||
// make the foo.marshal.pb.go file
|
|
||||||
marshal(sortmap)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// pb.makeSortfile(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func okExit(s string) {
|
func okExit(s string) {
|
||||||
|
|
26
marshal.go
26
marshal.go
|
@ -8,19 +8,16 @@ import (
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func marshal(names map[string]string) {
|
// makes Marshal and Unmarshal functions for protoWIRE protoTEXT and protoJSON
|
||||||
|
func (pb *Files) marshal(f *File) {
|
||||||
if argv.DryRun {
|
if argv.DryRun {
|
||||||
for k, v := range names {
|
return
|
||||||
log.Info(k, "=", v)
|
|
||||||
}
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
w, _ := os.OpenFile(names["protobase"]+".marshal.pb.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
w, _ := os.OpenFile(f.Filebase+".marshal.pb.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
||||||
|
|
||||||
fmt.Fprintln(w, "package "+names["package"])
|
|
||||||
headerComment(w)
|
headerComment(w)
|
||||||
|
fmt.Fprintf(w, "package %s\n", f.Package)
|
||||||
fmt.Fprintln(w, "import (")
|
fmt.Fprintln(w, "import (")
|
||||||
fmt.Fprintln(w, " \"google.golang.org/protobuf/encoding/protojson\"")
|
fmt.Fprintln(w, " \"google.golang.org/protobuf/encoding/protojson\"")
|
||||||
fmt.Fprintln(w, " \"google.golang.org/protobuf/encoding/prototext\"")
|
fmt.Fprintln(w, " \"google.golang.org/protobuf/encoding/prototext\"")
|
||||||
|
@ -28,15 +25,12 @@ func marshal(names map[string]string) {
|
||||||
fmt.Fprintln(w, ")")
|
fmt.Fprintln(w, ")")
|
||||||
fmt.Fprintln(w, "")
|
fmt.Fprintln(w, "")
|
||||||
|
|
||||||
for _, v := range marshalKeys {
|
for _, msg := range f.MsgNames {
|
||||||
// log.Info("found marshal key in .proto", v)
|
if msg.DoMarshal {
|
||||||
marshalThing(w, v)
|
marshalThing(w, msg.Name)
|
||||||
|
} else {
|
||||||
|
log.Info("Skipping. DoMarshal = false for", msg.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// marshalThing(w, names["Base"])
|
|
||||||
// marshalThing(w, names["Bases"])
|
|
||||||
for _, v := range argv.Marshal {
|
|
||||||
marshalThing(w, v)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue