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

Function getOptionalInfo

go/fory/optional_serializer.go:36–66  ·  view source on GitHub ↗
(type_ reflect.Type)

Source from the content-addressed store, hash-verified

34}
35
36func getOptionalInfo(type_ reflect.Type) (optionalInfo, bool) {
37 if type_ == nil {
38 return optionalInfo{}, false
39 }
40 if type_.Kind() == reflect.Ptr {
41 return optionalInfo{}, false
42 }
43 if type_.Kind() != reflect.Struct {
44 return optionalInfo{}, false
45 }
46 if type_.PkgPath() != optionalPkgPath {
47 return optionalInfo{}, false
48 }
49 name := type_.Name()
50 if name != "Optional" && !strings.HasPrefix(name, "Optional[") {
51 return optionalInfo{}, false
52 }
53 valueField, ok := type_.FieldByName("value")
54 if !ok {
55 return optionalInfo{}, false
56 }
57 hasField, ok := type_.FieldByName("has")
58 if !ok || hasField.Type.Kind() != reflect.Bool {
59 return optionalInfo{}, false
60 }
61 return optionalInfo{
62 valueType: valueField.Type,
63 valueOffset: valueField.Offset,
64 hasOffset: hasField.Offset,
65 }, true
66}
67
68func validateOptionalValueType(valueType reflect.Type) error {
69 if valueType == nil {

Callers 15

IsUnionTypeMethod · 0.85
validateOptionalFieldsFunction · 0.85
getTypeIdByTypeMethod · 0.85
createSerializerMethod · 0.85
isOptionalTypeFunction · 0.85
unwrapOptionalTypeFunction · 0.85
initFieldsMethod · 0.85
initFieldsFromTypeDefMethod · 0.85
isUnionTypeFunction · 0.85
isStructFieldFunction · 0.85
typesCompatibleFunction · 0.85

Calls 1

KindMethod · 0.80

Tested by

no test coverage detected