RegisterStruct registers a struct type with a numeric ID for cross-language serialization. This is compatible with Java's fory.register(Class, int) method. type_ can be either a reflect.Type or an instance of the type typeID should be the user type ID in the range 0-0xfffffffe (0xffffffff is reserve
(type_ any, typeID uint32)
| 271 | // |
| 272 | //go:noinline |
| 273 | func (f *Fory) RegisterStruct(type_ any, typeID uint32) error { |
| 274 | if err := validateUserTypeID(typeID); err != nil { |
| 275 | return err |
| 276 | } |
| 277 | var t reflect.Type |
| 278 | if rt, ok := type_.(reflect.Type); ok { |
| 279 | t = rt |
| 280 | } else { |
| 281 | t = reflect.TypeOf(type_) |
| 282 | if t.Kind() == reflect.Ptr { |
| 283 | t = t.Elem() |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | // Only struct types are supported via RegisterStruct |
| 288 | // For enums, use RegisterEnum |
| 289 | if t.Kind() != reflect.Struct { |
| 290 | return fmt.Errorf("RegisterStruct only supports struct types; for enum types use RegisterEnum. Got: %v", t.Kind()) |
| 291 | } |
| 292 | |
| 293 | // Determine the internal type ID based on config |
| 294 | var internalTypeID TypeId |
| 295 | internalTypeID = f.typeResolver.structTypeID(t, false) |
| 296 | |
| 297 | return f.typeResolver.RegisterStruct(t, internalTypeID, typeID) |
| 298 | } |
| 299 | |
| 300 | // RegisterUnion registers a union type with a numeric ID for cross-language serialization. |
| 301 | // type_ can be either a reflect.Type or an instance of the union type. |