mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2024-12-28 00:19:55 +00:00
c7d07d9ba5
Copy generator.CamelCase for camel-casing names, with one change: Convert '.' in names to '_'. This removes the need for the CamelCaseSlice function which operates on a []string representing a name split along '.'s. Add protogen.Message. Reformat generated code. Add regenerate.bash, largely copied from regenerate.sh. Change-Id: Iecf0bfc43b552f53e458499a328b933b0c9c5f82 Reviewed-on: https://go-review.googlesource.com/130915 Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
51 lines
1.0 KiB
Go
51 lines
1.0 KiB
Go
// Copyright 2018 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// The protoc-gen-go binary is a protoc plugin to generate a Go protocol
|
|
// buffer package.
|
|
package main
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"google.golang.org/proto/protogen"
|
|
)
|
|
|
|
func main() {
|
|
protogen.Run(func(gen *protogen.Plugin) error {
|
|
for _, f := range gen.Files {
|
|
if !f.Generate {
|
|
continue
|
|
}
|
|
genFile(gen, f)
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func genFile(gen *protogen.Plugin, f *protogen.File) {
|
|
g := gen.NewGeneratedFile(strings.TrimSuffix(f.Desc.GetName(), ".proto") + ".pb.go")
|
|
g.P("// Code generated by protoc-gen-go. DO NOT EDIT.")
|
|
g.P("// source: ", f.Desc.GetName())
|
|
g.P()
|
|
g.P("package TODO")
|
|
g.P()
|
|
|
|
for _, m := range f.Messages {
|
|
genMessage(gen, g, m)
|
|
}
|
|
|
|
// TODO: Everything.
|
|
}
|
|
|
|
func genMessage(gen *protogen.Plugin, g *protogen.GeneratedFile, m *protogen.Message) {
|
|
g.P("type ", m.GoIdent, " struct {")
|
|
g.P("}")
|
|
g.P()
|
|
|
|
for _, nested := range m.Messages {
|
|
genMessage(gen, g, nested)
|
|
}
|
|
}
|