summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rw-r--r--auto.proto4
-rw-r--r--parseProtoFile.go36
3 files changed, 33 insertions, 12 deletions
diff --git a/Makefile b/Makefile
index 4ddec1f..84c2924 100644
--- a/Makefile
+++ b/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:
diff --git a/auto.proto b/auto.proto
index 7d5c0d0..9ed008e 100644
--- a/auto.proto
+++ b/auto.proto
@@ -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
}
diff --git a/parseProtoFile.go b/parseProtoFile.go
index cbe670a..2795bbd 100644
--- a/parseProtoFile.go
+++ b/parseProtoFile.go
@@ -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