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

Method computeHash

go/fory/struct_init.go:949–1086  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

947}
948
949func (s *structSerializer) computeHash() int32 {
950 // Build FieldFingerprintInfo for each field
951 fields := make([]FieldFingerprintInfo, 0, len(s.fields))
952 for _, field := range s.fields {
953 var typeId TypeId
954 isEnumField := false
955 if field.Serializer == nil {
956 typeId = UNKNOWN
957 } else {
958 typeId = field.Meta.TypeId
959 // Check if this is an enum serializer (directly or wrapped in ptrToValueSerializer)
960 if _, ok := field.Serializer.(*enumSerializer); ok {
961 isEnumField = true
962 typeId = UNKNOWN
963 } else if ptrSer, ok := field.Serializer.(*ptrToValueSerializer); ok {
964 if _, ok := ptrSer.valueSerializer.(*enumSerializer); ok {
965 isEnumField = true
966 typeId = UNKNOWN
967 }
968 }
969 // Unions use UNION type ID in fingerprints, regardless of typed/named variants.
970 if typeId == TYPED_UNION || typeId == NAMED_UNION || typeId == UNION {
971 typeId = UNION
972 }
973 // For user-defined types (struct, ext types), use UNKNOWN in fingerprint
974 // This matches Java's behavior where user-defined types return UNKNOWN
975 // to ensure consistent fingerprint computation across languages
976 if isUserDefinedType(typeId) {
977 typeId = UNKNOWN
978 }
979 fieldTypeForHash := field.Meta.Type
980 if field.Kind == FieldKindOptional {
981 fieldTypeForHash = field.Meta.OptionalInfo.valueType
982 }
983 // For fixed-size arrays with primitive elements, use primitive array type IDs
984 if fieldTypeForHash.Kind() == reflect.Array {
985 elemKind := fieldTypeForHash.Elem().Kind()
986 switch elemKind {
987 case reflect.Int8:
988 typeId = INT8_ARRAY
989 case reflect.Uint8:
990 typeId = UINT8_ARRAY
991 case reflect.Int16:
992 typeId = INT16_ARRAY
993 case reflect.Uint16:
994 typeId = UINT16_ARRAY
995 case reflect.Int32:
996 typeId = INT32_ARRAY
997 case reflect.Uint32:
998 typeId = UINT32_ARRAY
999 case reflect.Int64:
1000 typeId = INT64_ARRAY
1001 case reflect.Uint64, reflect.Uint:
1002 typeId = UINT64_ARRAY
1003 case reflect.Float32:
1004 typeId = FLOAT32_ARRAY
1005 case reflect.Float64:
1006 typeId = FLOAT64_ARRAY

Callers 1

initializeMethod · 0.95

Calls 11

isUserDefinedTypeFunction · 0.85
isPrimitiveArrayTypeFunction · 0.85
isSetReflectTypeFunction · 0.85
SnakeCaseFunction · 0.85
ComputeStructFingerprintFunction · 0.85
Murmur3Sum128WithSeedFunction · 0.85
KindMethod · 0.80
CloneMethod · 0.80
TypeIdEnum · 0.50
int32Function · 0.50

Tested by

no test coverage detected