diff --git a/parseProtoFile.go b/parseProtoFile.go index 2795bbd..b62e5e2 100644 --- a/parseProtoFile.go +++ b/parseProtoFile.go @@ -25,22 +25,25 @@ func (pb *Files) findAutogenpb(f *File) error { return err } - // first parse the proto file for message struct names + var curmsg *MsgName + + // parse the proto file for message struct names for _, line := range strings.Split(string(data), "\n") { if strings.HasPrefix(line, "message ") { - f.parseForMessage(line) + curmsg = f.parseForMessage(line) + } + if strings.HasPrefix(line, "}") { + curmsg = nil } - } - // look for included proto files - lines := strings.Split(string(data), "\n") - for _, line := range lines { // log.Info("line:", line) parts := strings.Fields(line) if strings.Contains(line, "autogenpb:marshal") { newm := parts[1] - // log.Info("found marshal", newm) - marshalKeys = append(marshalKeys, newm) + if curmsg != nil { + // log.Info("found marshal", newm) + marshalKeys = append(marshalKeys, newm) + } } if strings.Contains(line, "autogenpb:unique") { newu := parts[1] @@ -53,10 +56,10 @@ func (pb *Files) findAutogenpb(f *File) error { } // looks for mutex and marshal entries -func (f *File) parseForMessage(line string) { +func (f *File) parseForMessage(line string) *MsgName { fields := strings.Fields(line) if fields[0] != "message" { - return + return nil } msgName := fields[1] msg := new(MsgName) @@ -71,6 +74,7 @@ func (f *File) parseForMessage(line string) { msg.DoMarshal = true log.Info("Found Marshal for:", msg.Name) } + return msg } func (pb *Files) findGlobalAutogenpb(f *File) error {