RegisterStructByName registers a struct type by name for cross-language serialization. type_ can be either a reflect.Type or an instance of the type. name can include a namespace prefix separated by "." (e.g., "example.Foo"). Note: For enum types, use RegisterEnumByName instead. go:noinline
(type_ any, name string)
| 361 | // |
| 362 | //go:noinline |
| 363 | func (f *Fory) RegisterStructByName(type_ any, name string) error { |
| 364 | var t reflect.Type |
| 365 | if rt, ok := type_.(reflect.Type); ok { |
| 366 | t = rt |
| 367 | } else { |
| 368 | t = reflect.TypeOf(type_) |
| 369 | if t.Kind() == reflect.Ptr { |
| 370 | t = t.Elem() |
| 371 | } |
| 372 | } |
| 373 | if t.Kind() != reflect.Struct { |
| 374 | return fmt.Errorf("RegisterStructByName only supports struct types; for enum types use RegisterEnumByName. Got: %v", t.Kind()) |
| 375 | } |
| 376 | namespace, typeName, err := splitRegisteredName(name) |
| 377 | if err != nil { |
| 378 | return err |
| 379 | } |
| 380 | return f.typeResolver.registerStructByName(t, namespace, typeName) |
| 381 | } |
| 382 | |
| 383 | // RegisterEnum registers an enum type with a numeric ID for cross-language serialization. |
| 384 | // In Go, enums are typically defined as int-based types (e.g., type Color int32). |