本文整理匯總了Golang中github.com/gogo/protobuf/protoc-gen-gogo/generator.CamelCaseSlice函數的典型用法代碼示例。如果您正苦於以下問題:Golang CamelCaseSlice函數的具體用法?Golang CamelCaseSlice怎麽用?Golang CamelCaseSlice使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CamelCaseSlice函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: hasLoop
func (p *plugin) hasLoop(field *descriptor.FieldDescriptorProto, visited []*generator.Descriptor, excludes []*generator.Descriptor) *generator.Descriptor {
if field.IsMessage() || p.IsGroup(field) {
fieldMessage := p.ObjectNamed(field.GetTypeName()).(*generator.Descriptor)
fieldTypeName := generator.CamelCaseSlice(fieldMessage.TypeName())
for _, message := range visited {
messageTypeName := generator.CamelCaseSlice(message.TypeName())
if fieldTypeName == messageTypeName {
for _, e := range excludes {
if fieldTypeName == generator.CamelCaseSlice(e.TypeName()) {
return nil
}
}
return fieldMessage
}
}
for _, f := range fieldMessage.Field {
visited = append(visited, fieldMessage)
loopTo := p.hasLoop(f, visited, excludes)
if loopTo != nil {
return loopTo
}
}
}
return nil
}
示例2: checkNameSpace
func (p *plugin) checkNameSpace(message *generator.Descriptor) map[string]bool {
ccTypeName := generator.CamelCaseSlice(message.TypeName())
names := make(map[string]bool)
for _, field := range message.Field {
fieldname := generator.CamelCase(*field.Name)
if field.IsMessage() && gogoproto.IsEmbed(field) {
desc := p.ObjectNamed(field.GetTypeName())
moreNames := p.checkNameSpace(desc.(*generator.Descriptor))
for another := range moreNames {
if names[another] {
fmt.Fprintf(os.Stderr, "ERROR: duplicate embedded fieldname %v in type %v\n", fieldname, ccTypeName)
os.Exit(1)
}
names[another] = true
}
} else {
if names[fieldname] {
fmt.Fprintf(os.Stderr, "ERROR: duplicate embedded fieldname %v in type %v\n", fieldname, ccTypeName)
os.Exit(1)
}
names[fieldname] = true
}
}
return names
}
示例3: Generate
func (p *test) Generate(imports generator.PluginImports, file *generator.FileDescriptor) bool {
used := false
randPkg := imports.NewImport("math/rand")
timePkg := imports.NewImport("time")
testingPkg := imports.NewImport("testing")
fmtPkg := imports.NewImport("fmt")
for _, message := range file.Messages() {
ccTypeName := generator.CamelCaseSlice(message.TypeName())
if !gogoproto.IsStringer(file.FileDescriptorProto, message.DescriptorProto) {
continue
}
if message.DescriptorProto.GetOptions().GetMapEntry() {
continue
}
if gogoproto.HasTestGen(file.FileDescriptorProto, message.DescriptorProto) {
used = true
p.P(`func Test`, ccTypeName, `Stringer(t *`, testingPkg.Use(), `.T) {`)
p.In()
p.P(`popr := `, randPkg.Use(), `.New(`, randPkg.Use(), `.NewSource(`, timePkg.Use(), `.Now().UnixNano()))`)
p.P(`p := NewPopulated`, ccTypeName, `(popr, false)`)
p.P(`s1 := p.String()`)
p.P(`s2 := `, fmtPkg.Use(), `.Sprintf("%v", p)`)
p.P(`if s1 != s2 {`)
p.In()
p.P(`t.Fatalf("String want %v got %v", s1, s2)`)
p.Out()
p.P(`}`)
p.Out()
p.P(`}`)
}
}
return used
}
示例4: genOneOfWriter
func (d *deepCopyGen) genOneOfWriter(m *generator.Descriptor, f *descriptor.FieldDescriptorProto, oneOfFuncs map[string][]func()) {
ccTypeName := generator.CamelCaseSlice(m.TypeName())
fName := generator.CamelCase(*f.Name)
if gogoproto.IsCustomName(f) {
fName = gogoproto.GetCustomName(f)
}
odp := m.OneofDecl[int(*f.OneofIndex)]
oneOfName := generator.CamelCase(odp.GetName())
oneOfNameFuncs, ok := oneOfFuncs[oneOfName]
if !ok {
oneOfFunc := func() {
d.gen.P("\tswitch m.", oneOfName, ".(type) {")
}
oneOfNameFuncs = append(oneOfNameFuncs, oneOfFunc)
}
isMessage := f.IsMessage()
oneOfFunc := func() {
tName := ccTypeName + "_" + fName
d.gen.P("\tcase *", tName, ":")
d.gen.P("\t\ti := &", tName, " {")
if isMessage {
d.gen.P("\t\t\t", fName, ": m.Get", fName, "().Copy(),")
} else {
d.gen.P("\t\t\t", fName, ": m.Get", fName, "(),")
}
d.gen.P("\t\t}")
d.gen.P()
d.gen.P("\t\to.", oneOfName, " = i")
}
oneOfNameFuncs = append(oneOfNameFuncs, oneOfFunc)
oneOfFuncs[oneOfName] = oneOfNameFuncs
}
示例5: Generate
func (p *test) Generate(imports generator.PluginImports, file *generator.FileDescriptor) bool {
used := false
randPkg := imports.NewImport("math/rand")
timePkg := imports.NewImport("time")
testingPkg := imports.NewImport("testing")
for _, message := range file.Messages() {
ccTypeName := generator.CamelCaseSlice(message.TypeName())
if !gogoproto.IsFace(file.FileDescriptorProto, message.DescriptorProto) {
continue
}
if message.DescriptorProto.GetOptions().GetMapEntry() {
continue
}
if gogoproto.HasTestGen(file.FileDescriptorProto, message.DescriptorProto) {
used = true
p.P(`func Test`, ccTypeName, `Face(t *`, testingPkg.Use(), `.T) {`)
p.In()
p.P(`popr := `, randPkg.Use(), `.New(`, randPkg.Use(), `.NewSource(`, timePkg.Use(), `.Now().UnixNano()))`)
p.P(`p := NewPopulated`, ccTypeName, `(popr, true)`)
p.P(`msg := p.TestProto()`)
p.P(`if !p.Equal(msg) {`)
p.In()
p.P(`t.Fatalf("%#v !Face Equal %#v", msg, p)`)
p.Out()
p.P(`}`)
p.Out()
p.P(`}`)
}
}
return used
}
示例6: Generate
func (p *enumstringer) Generate(file *generator.FileDescriptor) {
p.PluginImports = generator.NewPluginImports(p.Generator)
p.atleastOne = false
p.localName = generator.FileName(file)
strconvPkg := p.NewImport("strconv")
for _, enum := range file.Enums() {
if !gogoproto.IsEnumStringer(file.FileDescriptorProto, enum.EnumDescriptorProto) {
continue
}
if gogoproto.IsGoEnumStringer(file.FileDescriptorProto, enum.EnumDescriptorProto) {
panic("old enum string method needs to be disabled, please use gogoproto.old_enum_stringer or gogoproto.old_enum_string_all and set it to false")
}
p.atleastOne = true
ccTypeName := generator.CamelCaseSlice(enum.TypeName())
p.P("func (x ", ccTypeName, ") String() string {")
p.In()
p.P(`s, ok := `, ccTypeName, `_name[int32(x)]`)
p.P(`if ok {`)
p.In()
p.P(`return s`)
p.Out()
p.P(`}`)
p.P(`return `, strconvPkg.Use(), `.Itoa(int(x))`)
p.Out()
p.P(`}`)
}
if !p.atleastOne {
return
}
}
示例7: Generate
func (p *test) Generate(imports generator.PluginImports, file *generator.FileDescriptor) bool {
used := false
randPkg := imports.NewImport("math/rand")
timePkg := imports.NewImport("time")
testingPkg := imports.NewImport("testing")
protoPkg := imports.NewImport("github.com/gogo/protobuf/proto")
if !gogoproto.ImportsGoGoProto(file.FileDescriptorProto) {
protoPkg = imports.NewImport("github.com/golang/protobuf/proto")
}
for _, message := range file.Messages() {
ccTypeName := generator.CamelCaseSlice(message.TypeName())
if !gogoproto.HasCompare(file.FileDescriptorProto, message.DescriptorProto) {
continue
}
if message.DescriptorProto.GetOptions().GetMapEntry() {
continue
}
if gogoproto.HasTestGen(file.FileDescriptorProto, message.DescriptorProto) {
used = true
p.P(`func Test`, ccTypeName, `Compare(t *`, testingPkg.Use(), `.T) {`)
p.In()
p.P(`popr := `, randPkg.Use(), `.New(`, randPkg.Use(), `.NewSource(`, timePkg.Use(), `.Now().UnixNano()))`)
p.P(`p := NewPopulated`, ccTypeName, `(popr, false)`)
p.P(`data, err := `, protoPkg.Use(), `.Marshal(p)`)
p.P(`if err != nil {`)
p.In()
p.P(`panic(err)`)
p.Out()
p.P(`}`)
p.P(`msg := &`, ccTypeName, `{}`)
p.P(`if err := `, protoPkg.Use(), `.Unmarshal(data, msg); err != nil {`)
p.In()
p.P(`panic(err)`)
p.Out()
p.P(`}`)
p.P(`if c := p.Compare(msg); c != 0 {`)
p.In()
p.P(`t.Fatalf("%#v !Compare %#v, since %d", msg, p, c)`)
p.Out()
p.P(`}`)
p.P(`p2 := NewPopulated`, ccTypeName, `(popr, false)`)
p.P(`c := p.Compare(p2)`)
p.P(`c2 := p2.Compare(p)`)
p.P(`if c != (-1 * c2) {`)
p.In()
p.P(`t.Errorf("p.Compare(p2) = %d", c)`)
p.P(`t.Errorf("p2.Compare(p) = %d", c2)`)
p.P(`t.Errorf("p = %#v", p)`)
p.P(`t.Errorf("p2 = %#v", p2)`)
p.Out()
p.P(`}`)
p.Out()
p.P(`}`)
}
}
return used
}
示例8: Generate
func (p *testJson) Generate(imports generator.PluginImports, file *generator.FileDescriptor) bool {
used := false
testingPkg := imports.NewImport("testing")
randPkg := imports.NewImport("math/rand")
timePkg := imports.NewImport("time")
jsonPkg := imports.NewImport("encoding/json")
for _, message := range file.Messages() {
ccTypeName := generator.CamelCaseSlice(message.TypeName())
if message.DescriptorProto.GetOptions().GetMapEntry() {
continue
}
if gogoproto.HasTestGen(file.FileDescriptorProto, message.DescriptorProto) {
used = true
p.P(`func Test`, ccTypeName, `JSON(t *`, testingPkg.Use(), `.T) {`)
p.In()
p.P(`popr := `, randPkg.Use(), `.New(`, randPkg.Use(), `.NewSource(`, timePkg.Use(), `.Now().UnixNano()))`)
p.P(`p := NewPopulated`, ccTypeName, `(popr, true)`)
p.P(`jsondata, err := `, jsonPkg.Use(), `.Marshal(p)`)
p.P(`if err != nil {`)
p.In()
p.P(`if _, ok := err.(*`, jsonPkg.Use(), `.UnsupportedTypeError); ok {`)
p.In()
p.P(`t.Skip(err)`)
p.Out()
p.P(`}`)
p.P(`t.Fatal(err)`)
p.Out()
p.P(`}`)
p.P(`msg := &`, ccTypeName, `{}`)
p.P(`err = `, jsonPkg.Use(), `.Unmarshal(jsondata, msg)`)
p.P(`if err != nil {`)
p.In()
p.P(`t.Fatal(err)`)
p.Out()
p.P(`}`)
if gogoproto.HasVerboseEqual(file.FileDescriptorProto, message.DescriptorProto) {
p.P(`if err := p.VerboseEqual(msg); err != nil {`)
p.In()
p.P(`t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)`)
p.Out()
p.P(`}`)
}
p.P(`if !p.Equal(msg) {`)
p.In()
p.P(`t.Fatalf("%#v !Json Equal %#v", msg, p)`)
p.Out()
p.P(`}`)
p.Out()
p.P(`}`)
}
}
return used
}
示例9: Generate
func (p *test) Generate(imports generator.PluginImports, file *generator.FileDescriptor) bool {
used := false
testingPkg := imports.NewImport("testing")
randPkg := imports.NewImport("math/rand")
timePkg := imports.NewImport("time")
for _, message := range file.Messages() {
if !gogoproto.HasTestGen(file.FileDescriptorProto, message.DescriptorProto) {
continue
}
if message.DescriptorProto.GetOptions().GetMapEntry() {
continue
}
used = true
ccTypeName := generator.CamelCaseSlice(message.TypeName())
p.P(`func Test`, ccTypeName, `Copy(t *`, testingPkg.Use(), `.T) {`)
p.In()
p.P(`popr := `, randPkg.Use(), `.New(`, randPkg.Use(), `.NewSource(`, timePkg.Use(), `.Now().UnixNano()))`)
p.P(`in := NewPopulated`, ccTypeName, `(popr, true)`)
p.P(`out := in.Copy()`)
p.P(`if !in.Equal(out) {`)
p.In()
p.P(`t.Fatalf("%#v != %#v", in, out)`)
p.Out()
p.P(`}`)
for _, f := range message.Field {
fName := generator.CamelCase(*f.Name)
if gogoproto.IsCustomName(f) {
fName = gogoproto.GetCustomName(f)
}
if f.OneofIndex != nil {
odp := message.OneofDecl[int(*f.OneofIndex)]
fName = generator.CamelCase(odp.GetName())
}
p.P(`if &in.`, fName, ` == &out.`, fName, ` {`)
p.In()
p.P(`t.Fatalf("`, fName, `: %#v == %#v", &in.`, fName, `, &out.`, fName, `)`)
p.Out()
p.P(`}`)
}
p.Out()
p.P(`}`)
}
return used
}
示例10: checkRepeated
func (p *plugin) checkRepeated(message *generator.Descriptor) {
ccTypeName := generator.CamelCaseSlice(message.TypeName())
for _, field := range message.Field {
if !gogoproto.IsEmbed(field) {
continue
}
if !field.IsRepeated() {
continue
}
fieldname := generator.CamelCase(*field.Name)
fmt.Fprintf(os.Stderr, "ERROR: found repeated embedded field %s in message %s\n", fieldname, ccTypeName)
os.Exit(1)
}
}
示例11: hasLoop
func (p *plugin) hasLoop(field *descriptor.FieldDescriptorProto, visited []*generator.Descriptor, excludes []*generator.Descriptor) *generator.Descriptor {
if field.IsMessage() || p.IsGroup(field) || p.IsMap(field) {
var fieldMessage *generator.Descriptor
if p.IsMap(field) {
m := p.GoMapType(nil, field)
if !m.ValueField.IsMessage() {
return nil
}
fieldMessage = p.ObjectNamed(m.ValueField.GetTypeName()).(*generator.Descriptor)
} else {
fieldMessage = p.ObjectNamed(field.GetTypeName()).(*generator.Descriptor)
}
fieldTypeName := generator.CamelCaseSlice(fieldMessage.TypeName())
for _, message := range visited {
messageTypeName := generator.CamelCaseSlice(message.TypeName())
if fieldTypeName == messageTypeName {
for _, e := range excludes {
if fieldTypeName == generator.CamelCaseSlice(e.TypeName()) {
return nil
}
}
return fieldMessage
}
}
pkg := strings.Split(field.GetTypeName(), ".")[1]
for _, f := range fieldMessage.Field {
if strings.HasPrefix(f.GetTypeName(), "."+pkg+".") {
visited = append(visited, fieldMessage)
loopTo := p.hasLoop(f, visited, excludes)
if loopTo != nil {
return loopTo
}
}
}
}
return nil
}
示例12: genOneOf
func (d *deepCopyGen) genOneOf(m *generator.Descriptor, oneof *descriptor.OneofDescriptorProto, fields []*descriptor.FieldDescriptorProto) {
oneOfName := generator.CamelCase(oneof.GetName())
d.P("if o.", oneOfName, " != nil {")
d.In()
d.P("switch o.", oneOfName, ".(type) {")
for _, f := range fields {
ccTypeName := generator.CamelCaseSlice(m.TypeName())
fName := generator.CamelCase(*f.Name)
if gogoproto.IsCustomName(f) {
fName = gogoproto.GetCustomName(f)
}
tName := ccTypeName + "_" + fName
d.P("case *", tName, ":")
d.In()
d.P("v := ", tName, " {")
d.In()
var rhs string
if f.IsMessage() {
goType := d.TypeName(d.ObjectNamed(f.GetTypeName())) // elides [] or *
rhs = "&" + goType + "{}"
} else {
rhs = "o.Get" + fName + "()"
}
d.P(fName, ": ", rhs, ",")
d.Out()
d.P("}")
if f.IsMessage() {
d.genCopyFunc("v."+fName, "o.Get"+fName+"()")
}
d.P("m.", oneOfName, " = &v")
d.Out()
}
d.Out()
d.P("}")
d.Out()
d.P("}")
d.P()
}
示例13: checkOverwrite
func (p *plugin) checkOverwrite(message *generator.Descriptor, enablers map[string]gogoproto.EnableFunc) {
ccTypeName := generator.CamelCaseSlice(message.TypeName())
names := []string{}
for name := range enablers {
names = append(names, name)
}
for _, field := range message.Field {
if field.IsMessage() && gogoproto.IsEmbed(field) {
fieldname := generator.CamelCase(*field.Name)
desc := p.ObjectNamed(field.GetTypeName())
msg := desc.(*generator.Descriptor)
for errStr, enabled := range enablers {
if enabled(msg.File(), msg.DescriptorProto) {
fmt.Fprintf(os.Stderr, "WARNING: found non-%v %v with embedded %v %v\n", names, ccTypeName, errStr, fieldname)
}
}
p.checkOverwrite(msg, enablers)
}
}
}
示例14: Generate
func (p *plugin) Generate(file *generator.FileDescriptor) {
p.used = false
localName := generator.FileName(file)
for _, message := range file.Messages() {
if !gogoproto.HasDescription(file.FileDescriptorProto, message.DescriptorProto) {
continue
}
if message.DescriptorProto.GetOptions().GetMapEntry() {
continue
}
p.used = true
ccTypeName := generator.CamelCaseSlice(message.TypeName())
p.P(`func (this *`, ccTypeName, `) Description() (desc *descriptor.FileDescriptorSet) {`)
p.In()
p.P(`return `, localName, `Description()`)
p.Out()
p.P(`}`)
}
if p.used {
p.P(`func `, localName, `Description() (desc *descriptor.FileDescriptorSet) {`)
p.In()
//Don't generate SourceCodeInfo, since it will create too much code.
ss := make([]*descriptor.SourceCodeInfo, 0)
for _, f := range p.Generator.AllFiles().GetFile() {
ss = append(ss, f.SourceCodeInfo)
f.SourceCodeInfo = nil
}
s := fmt.Sprintf("%#v", p.Generator.AllFiles())
for i, f := range p.Generator.AllFiles().GetFile() {
f.SourceCodeInfo = ss[i]
}
p.P(`return `, s)
p.Out()
p.P(`}`)
}
}
示例15: genMsgDeepCopy
func (d *deepCopyGen) genMsgDeepCopy(m *generator.Descriptor) {
if !plugin.DeepcopyEnabled(m.Options) {
return
}
ccTypeName := generator.CamelCaseSlice(m.TypeName())
d.gen.P("func (m *", ccTypeName, ") Copy() *", ccTypeName, "{")
d.gen.P("\tif m == nil {")
d.gen.P("\t\treturn nil")
d.gen.P("\t}")
d.gen.P()
d.gen.P("\to := &", ccTypeName, "{")
var funcs []func()
oneOfFuncs := make(map[string][]func())
for _, f := range m.Field {
fName := generator.CamelCase(*f.Name)
if gogoproto.IsCustomName(f) {
fName = gogoproto.GetCustomName(f)
}
notNullablePrefix := ""
if !gogoproto.IsNullable(f) {
notNullablePrefix = "*"
}
// Handle all kinds of message type
if f.IsMessage() {
// Handle map type
if mapfunc := d.genMapWriter(m, f, notNullablePrefix); mapfunc != nil {
funcs = append(funcs, mapfunc)
continue
}
// Handle any message which is not repeated or part of oneof
if !f.IsRepeated() && f.OneofIndex == nil {
d.gen.P("\t\t", fName, ": ", notNullablePrefix, "m.", fName, ".Copy(),")
continue
}
}
// Handle repeated field
if f.IsRepeated() {
funcs = append(funcs, d.genRepeatedWriter(m, f, notNullablePrefix))
continue
}
// Handle oneof type
if f.OneofIndex != nil {
d.genOneOfWriter(m, f, oneOfFuncs)
continue
}
// Handle all kinds of scalar type
d.gen.P("\t\t", fName, ": m.", fName, ",")
}
d.gen.P("\t}")
d.gen.P()
for _, fn := range funcs {
fn()
}
// Sort map keys from oneOfFuncs so that generated code has consistent
// ordering.
oneOfKeys := make([]string, 0, len(oneOfFuncs))
for key := range oneOfFuncs {
oneOfKeys = append(oneOfKeys, key)
}
sort.Strings(oneOfKeys)
for _, key := range oneOfKeys {
oneOfNameFuncs := oneOfFuncs[key]
for _, oneOfFunc := range oneOfNameFuncs {
oneOfFunc()
}
d.gen.P("\t}")
d.gen.P()
}
d.gen.P("\treturn o")
d.gen.P("}")
d.gen.P()
}