本文整理匯總了Golang中github.com/gogo/protobuf/protoc-gen-gogo/generator.Descriptor.GetOneofDecl方法的典型用法代碼示例。如果您正苦於以下問題:Golang Descriptor.GetOneofDecl方法的具體用法?Golang Descriptor.GetOneofDecl怎麽用?Golang Descriptor.GetOneofDecl使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gogo/protobuf/protoc-gen-gogo/generator.Descriptor
的用法示例。
在下文中一共展示了Descriptor.GetOneofDecl方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: genMsgDeepCopy
func (d *deepCopyGen) genMsgDeepCopy(m *generator.Descriptor) {
ccTypeName := generator.CamelCaseSlice(m.TypeName())
// Generate backwards compatible, type-safe Copy() function.
d.P("func (m *", ccTypeName, ") Copy() *", ccTypeName, "{")
d.In()
d.P("if m == nil {")
d.In()
d.P("return nil")
d.Out()
d.P("}")
d.P("o := &", ccTypeName, "{}")
d.P("o.CopyFrom(m)")
d.P("return o")
d.Out()
d.P("}")
d.P()
if len(m.Field) == 0 {
d.P("func (m *", ccTypeName, ") CopyFrom(src interface{})", " {}")
return
}
d.P("func (m *", ccTypeName, ") CopyFrom(src interface{})", " {")
d.P()
d.P("o := src.(*", ccTypeName, ")")
// shallow copy handles all scalars
d.P("*m = *o")
oneofByIndex := [][]*descriptor.FieldDescriptorProto{}
for _, f := range m.Field {
fName := generator.CamelCase(*f.Name)
if gogoproto.IsCustomName(f) {
fName = gogoproto.GetCustomName(f)
}
// Handle oneof type, we defer them to a loop below
if f.OneofIndex != nil {
if len(oneofByIndex) <= int(*f.OneofIndex) {
oneofByIndex = append(oneofByIndex, []*descriptor.FieldDescriptorProto{})
}
oneofByIndex[*f.OneofIndex] = append(oneofByIndex[*f.OneofIndex], f)
continue
}
// Handle all kinds of message type
if f.IsMessage() {
// Handle map type
if d.genMap(m, f) {
continue
}
// Handle any message which is not repeated or part of oneof
if !f.IsRepeated() && f.OneofIndex == nil {
if !gogoproto.IsNullable(f) {
d.genCopyFunc("&m."+fName, "&o."+fName)
} else {
d.P("if o.", fName, " != nil {")
d.In()
// allocate dst object
d.P("m.", fName, " = &", d.TypeName(d.ObjectNamed(f.GetTypeName())), "{}")
// copy into the allocated struct
d.genCopyFunc("m."+fName, "o."+fName)
d.Out()
d.P("}")
}
continue
}
}
// Handle repeated field
if f.IsRepeated() {
d.genRepeated(m, f)
continue
}
// skip: field was a scalar handled by shallow copy!
}
for i, oo := range m.GetOneofDecl() {
d.genOneOf(m, oo, oneofByIndex[i])
}
d.P("}")
d.P()
}