initialize performs eager initialization of the struct serializer. This should be called at registration time to pre-compute all field metadata.
(typeResolver *TypeResolver)
| 39 | // initialize performs eager initialization of the struct serializer. |
| 40 | // This should be called at registration time to pre-compute all field metadata. |
| 41 | func (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 | |
| 76 | func primitiveTypeIdMatchesKind(typeId TypeId, kind reflect.Kind) bool { |
| 77 | switch typeId { |
no test coverage detected