(t reflect.Type)
| 225 | } |
| 226 | |
| 227 | func newProperties(t reflect.Type) *StructProperties { |
| 228 | if t.Kind() != reflect.Struct { |
| 229 | panic(fmt.Sprintf("%v is not a generated message in the open-struct API", t)) |
| 230 | } |
| 231 | |
| 232 | var hasOneof bool |
| 233 | prop := new(StructProperties) |
| 234 | |
| 235 | // Construct a list of properties for each field in the struct. |
| 236 | for i := 0; i < t.NumField(); i++ { |
| 237 | p := new(Properties) |
| 238 | f := t.Field(i) |
| 239 | tagField := f.Tag.Get("protobuf") |
| 240 | p.Init(f.Type, f.Name, tagField, &f) |
| 241 | |
| 242 | tagOneof := f.Tag.Get("protobuf_oneof") |
| 243 | if tagOneof != "" { |
| 244 | hasOneof = true |
| 245 | p.OrigName = tagOneof |
| 246 | } |
| 247 | |
| 248 | // Rename unrelated struct fields with the "XXX_" prefix since so much |
| 249 | // user code simply checks for this to exclude special fields. |
| 250 | if tagField == "" && tagOneof == "" && !strings.HasPrefix(p.Name, "XXX_") { |
| 251 | p.Name = "XXX_" + p.Name |
| 252 | p.OrigName = "XXX_" + p.OrigName |
| 253 | } else if p.Weak != "" { |
| 254 | p.Name = p.OrigName // avoid possible "XXX_" prefix on weak field |
| 255 | } |
| 256 | |
| 257 | prop.Prop = append(prop.Prop, p) |
| 258 | } |
| 259 | |
| 260 | // Construct a mapping of oneof field names to properties. |
| 261 | if hasOneof { |
| 262 | var oneofWrappers []interface{} |
| 263 | if fn, ok := reflect.PtrTo(t).MethodByName("XXX_OneofFuncs"); ok { |
| 264 | oneofWrappers = fn.Func.Call([]reflect.Value{reflect.Zero(fn.Type.In(0))})[3].Interface().([]interface{}) |
| 265 | } |
| 266 | if fn, ok := reflect.PtrTo(t).MethodByName("XXX_OneofWrappers"); ok { |
| 267 | oneofWrappers = fn.Func.Call([]reflect.Value{reflect.Zero(fn.Type.In(0))})[0].Interface().([]interface{}) |
| 268 | } |
| 269 | if m, ok := reflect.Zero(reflect.PtrTo(t)).Interface().(protoreflect.ProtoMessage); ok { |
| 270 | if m, ok := m.ProtoReflect().(interface{ ProtoMessageInfo() *protoimpl.MessageInfo }); ok { |
| 271 | oneofWrappers = m.ProtoMessageInfo().OneofWrappers |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | prop.OneofTypes = make(map[string]*OneofProperties) |
| 276 | for _, wrapper := range oneofWrappers { |
| 277 | p := &OneofProperties{ |
| 278 | Type: reflect.ValueOf(wrapper).Type(), // *T |
| 279 | Prop: new(Properties), |
| 280 | } |
| 281 | f := p.Type.Elem().Field(0) |
| 282 | p.Prop.Name = f.Name |
| 283 | p.Prop.Parse(f.Tag.Get("protobuf")) |
| 284 |
no test coverage detected