parse for all the structs
This commit is contained in:
parent
d850ec82c8
commit
ad67a6f42d
5
Makefile
5
Makefile
|
@ -23,8 +23,9 @@ install:
|
|||
GO111MODULE=off go install \
|
||||
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
|
||||
|
||||
auto.pb.go: auto.proto
|
||||
./autogenpb --proto auto.proto --package testfiles
|
||||
auto:
|
||||
rm -f auto.pb.go
|
||||
./autogenpb --proto auto.proto --package main
|
||||
rm -f auto.sort.pb.go auto.marshal.pb.go
|
||||
|
||||
test:
|
||||
|
|
|
@ -64,8 +64,8 @@ message MsgName {
|
|||
//
|
||||
|
||||
string name = 1; // the name of the message aka struct. for this example: "Shelf"
|
||||
bool marshal = 2; // if "Shelf" should have Marshal & Unmarshal functions
|
||||
bool mutex = 3; // an experiment to insert a mutex into the protoc generated msg struct (bad idea?)
|
||||
bool doMarshal = 2; // if "Shelf" should have Marshal & Unmarshal functions
|
||||
bool doMutex = 3; // an experiment to insert a mutex into the protoc generated msg struct (bad idea?)
|
||||
repeated string sort = 4; // "Book", "Picture", etc
|
||||
repeated string unique = 5; // if the fields should have AppendUnique() functions
|
||||
}
|
||||
|
|
|
@ -25,6 +25,13 @@ func (pb *Files) findAutogenpb(f *File) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// first parse the proto file for message struct names
|
||||
for _, line := range strings.Split(string(data), "\n") {
|
||||
if strings.HasPrefix(line, "message ") {
|
||||
f.parseForMessage(line)
|
||||
}
|
||||
}
|
||||
|
||||
// look for included proto files
|
||||
lines := strings.Split(string(data), "\n")
|
||||
for _, line := range lines {
|
||||
|
@ -41,18 +48,31 @@ func (pb *Files) findAutogenpb(f *File) error {
|
|||
// log.Info("found unique field", newu)
|
||||
uniqueKeys = append(uniqueKeys, newu)
|
||||
}
|
||||
if strings.Contains(line, "autogenpb:mutex") {
|
||||
parts := strings.Split(line, "autogenpb:mutex")
|
||||
// log.Info("FOUND MUTEX line:", parts[0])
|
||||
fields := strings.Fields(parts[0])
|
||||
if fields[0] == "message" {
|
||||
log.Info("FOUND MUTEX:", fields[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// looks for mutex and marshal entries
|
||||
func (f *File) parseForMessage(line string) {
|
||||
fields := strings.Fields(line)
|
||||
if fields[0] != "message" {
|
||||
return
|
||||
}
|
||||
msgName := fields[1]
|
||||
msg := new(MsgName)
|
||||
f.MsgNames = append(f.MsgNames, msg)
|
||||
msg.Name = msgName
|
||||
|
||||
if strings.Contains(line, "`autogenpb:mutex`") {
|
||||
msg.DoMutex = true
|
||||
log.Info("Found Mutex for:", msg.Name)
|
||||
}
|
||||
if strings.Contains(line, "`autogenpb:marshal`") {
|
||||
msg.DoMarshal = true
|
||||
log.Info("Found Marshal for:", msg.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func (pb *Files) findGlobalAutogenpb(f *File) error {
|
||||
// log.Info("starting findAutogenpb() on", filename)
|
||||
// read in the .proto file
|
||||
|
|
Loading…
Reference in New Issue