MCPcopy Create free account
hub / github.com/apache/fory / initialize

Method initialize

go/fory/struct_init.go:41–74  ·  view source on GitHub ↗

initialize performs eager initialization of the struct serializer. This should be called at registration time to pre-compute all field metadata.

(typeResolver *TypeResolver)

Source from the content-addressed store, hash-verified

39// initialize performs eager initialization of the struct serializer.
40// This should be called at registration time to pre-compute all field metadata.
41func (s *structSerializer) initialize(typeResolver *TypeResolver) error {
42 if s.initialized {
43 return nil
44 }
45 // Ensure type is set
46 if s.type_ == nil {
47 return errors.New("struct type not set")
48 }
49 // Normalize pointer types
50 for s.type_.Kind() == reflect.Ptr {
51 s.type_ = s.type_.Elem()
52 }
53 // Set compatible mode flag BEFORE field initialization
54 // This is needed for groupFields to apply correct sorting
55 s.isCompatibleMode = typeResolver.Compatible()
56 // Build fields from type or fieldDefs
57 if s.fieldDefs != nil {
58 if err := s.initFieldsFromTypeDef(typeResolver); err != nil {
59 return err
60 }
61 } else {
62 if err := s.initFields(typeResolver); err != nil {
63 return err
64 }
65 }
66 // Compute struct hash
67 s.structHash = s.computeHash()
68 if s.tempValue == nil {
69 tmp := reflect.New(s.type_).Elem()
70 s.tempValue = &tmp
71 }
72 s.initialized = true
73 return nil
74}
75
76func primitiveTypeIdMatchesKind(typeId TypeId, kind reflect.Kind) bool {
77 switch typeId {

Callers 3

WriteDataMethod · 0.95
ReadDataMethod · 0.95
GetStructHashFunction · 0.45

Calls 5

initFieldsFromTypeDefMethod · 0.95
initFieldsMethod · 0.95
computeHashMethod · 0.95
KindMethod · 0.80
CompatibleMethod · 0.45

Tested by

no test coverage detected