Repository navigation
fix(protocol): refine Fory 2.0 implementation - #4249
Merged
Merged
Conversation
…a native layer alignment, and Swift union skip
ayush00git
approved these changes
Dec 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why?
Follow-up fixes for five correctness and protocol edge cases found during post-merge review of Fory 2.0 (#4245):
type Balance int64) as an unregistered enum silently truncated 64-bit and negative values through 32-bit unsigned enum ordinals.TYPED_*(and non-compatibleNAMED_*) readers for enum, ext, union, and non-evolving struct discarded the wire user type ID / name, allowing a known registered ID (e.g., enum A) to decode silently into a different registered target (e.g., enum B).TypeDef.getDescriptorsnumbered only anonymous remote layers instead of the full layer sequence, misaligning superclass anonymous fields into a registered middle layer when shadowing fields were present or added during schema evolution.UNIONsupport: Unregistered Go unions had no way to supply their case table without global ID/name registration.ReadContext.readSkipTypeInfoandresolveSkippedTypeInforejected.union,.typedUnion, and.namedUnionwhen skipping nested or dynamic union payloads inside removed fields.What does this PR do?
foryc(go/fory/,benchmarks/go/models.go,compiler/fory_compiler/generators/go.py):EnumMarker(ForyEnumMarker()) so only explicitly marked Go enums (includingforyc-generated enums) use unregisteredENUMordinal encoding while ordinary named integer types preserve their underlying scalar numeric encoding and full range.0 .. math.MaxUint32) inenumSerializer.WriteDatainstead of silently truncating out-of-range values.UnionDescriptor(ForyUnionCases() []UnionCase) and emit it inforycGo union codegen so Go unions can serialize and deserialize as unregisteredUNBOUNDUNIONvalues without global wire ID/name registration, while still rejecting dynamicanymaterialization ofUNBOUNDunions.javascript/packages/core/lib/):userTypeIdforTYPED_ENUM,TYPED_EXT,TYPED_UNION, andTYPED_STRUCT(and wirenamespace/typeNamefor non-compatibleNAMED_*) with a fast primitive comparison and cold error helper.UNBOUNDtargets inReadContext.readAsymmetricNonEvolvingTypeInfoandreadIdentityOnlyTypeMetaForUnboundTarget, while preserving asymmetric fallback for unknown wire identities.java/fory-core/src/main/java/org/apache/fory/meta/TypeDef.java):TypeDef.getDescriptorsand align anonymous layers between monotonic registered/named anchor layers so superclass fields stay bound to their owning layer segment.swift/Sources/Fory/):TypeInfo.skippedUnion()backed byReadContext.readSkippedUnion()and handle.union,.typedUnion, and.namedUnioninReadContext.readSkipTypeInfoandresolveSkippedTypeInfo.go/fory/fory_2_0_test.go,compiler/fory_compiler/tests/test_fory_2_0_codegen.py,javascript/test/fory2.test.ts,java/fory-core/src/test/java/org/apache/fory/Fory20UnregisteredTest.java, andswift/Tests/ForyTests/Fory20Tests.swift.Related issues
Follow-up to #4245.
Does this PR introduce any user-facing change?
EnumMarkerandUnionDescriptoropt-in marker/descriptor interfaces for unregistered Go enums and unions.)Verification
go test -race ./...ingo/fory/, Go benchmark compile, Go IDL codegen & tests, Go gRPC peer build,go fmt.pytest(584 passed),ruff check,ruff format --check.npm run format-check.Fory20UnregisteredTest,TypeDefTest,NativeTypeDefEncoderTest,mvn spotless:check -pl fory-core.swift test(289 tests passed),swiftlint lint.