MCPcopy
hub / github.com/golang/protobuf / generateOneofFuncs

Method generateOneofFuncs

protoc-gen-go/generator/generator.go:2050–2073  ·  view source on GitHub ↗

generateOneofFuncs adds all the utility functions for oneof, including marshalling, unmarshalling and sizer.

(mc *msgCtx, topLevelFields []topLevelField)

Source from the content-addressed store, hash-verified

2048
2049// generateOneofFuncs adds all the utility functions for oneof, including marshalling, unmarshalling and sizer.
2050func (g *Generator) generateOneofFuncs(mc *msgCtx, topLevelFields []topLevelField) {
2051 ofields := []*oneofField{}
2052 for _, f := range topLevelFields {
2053 if o, ok := f.(*oneofField); ok {
2054 ofields = append(ofields, o)
2055 }
2056 }
2057 if len(ofields) == 0 {
2058 return
2059 }
2060
2061 // OneofFuncs
2062 g.P("// XXX_OneofWrappers is for the internal use of the proto package.")
2063 g.P("func (*", mc.goName, ") XXX_OneofWrappers() []interface{} {")
2064 g.P("return []interface{}{")
2065 for _, of := range ofields {
2066 for _, sf := range of.subFields {
2067 sf.typedNil(g)
2068 }
2069 }
2070 g.P("}")
2071 g.P("}")
2072 g.P()
2073}
2074
2075// generateMessageStruct adds the actual struct with it's members (but not methods) to the output.
2076func (g *Generator) generateMessageStruct(mc *msgCtx, topLevelFields []topLevelField) {

Callers 1

generateMessageMethod · 0.95

Calls 2

PMethod · 0.95
typedNilMethod · 0.80

Tested by

no test coverage detected