generateOneofFuncs adds all the utility functions for oneof, including marshalling, unmarshalling and sizer.
(mc *msgCtx, topLevelFields []topLevelField)
| 2048 | |
| 2049 | // generateOneofFuncs adds all the utility functions for oneof, including marshalling, unmarshalling and sizer. |
| 2050 | func (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. |
| 2076 | func (g *Generator) generateMessageStruct(mc *msgCtx, topLevelFields []topLevelField) { |
no test coverage detected