This is an automated email from the ASF dual-hosted git repository.
chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fory.git
The following commit(s) were added to refs/heads/main by this push:
new 941ef1832 fix(java): fix xlang typedef encode (#2719)
941ef1832 is described below
commit 941ef1832fc683f2434549fead8c9b0daf944443
Author: Shawn Yang <[email protected]>
AuthorDate: Wed Oct 8 00:32:49 2025 +0800
fix(java): fix xlang typedef encode (#2719)
## Why?
<!-- Describe the purpose of this PR. -->
## What does this PR do?
<!-- Describe the details of this PR. -->
## Related issues
Closes #2718
## Does this PR introduce any user-facing change?
<!--
If any user-facing interface changes, please [open an
issue](https://github.com/apache/fory/issues/new/choose) describing the
need to do so and update the document if necessary.
Delete section if not applicable.
-->
- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?
## Benchmark
<!--
When the PR has an impact on performance (if you don't know whether the
PR will have an impact on performance, you can submit the PR first, and
if it will have impact on performance, the code reviewer will explain
it), be sure to attach a benchmark data here.
Delete section if not applicable.
-->
---
ci/tasks/rust.py | 8 +-
.../main/java/org/apache/fory/meta/ClassDef.java | 3 +-
.../test/java/org/apache/fory/RustXlangTest.java | 2 +-
.../java/org/apache/fory/xlang/RegisterTest.java | 131 +++++++++++++++++++++
4 files changed, 141 insertions(+), 3 deletions(-)
diff --git a/ci/tasks/rust.py b/ci/tasks/rust.py
index d642ec821..f8572562c 100644
--- a/ci/tasks/rust.py
+++ b/ci/tasks/rust.py
@@ -84,6 +84,12 @@ def run():
java_dir = os.path.join("..", "java")
subprocess.check_call(["mvn", "clean", "install", "-DskipTests"],
cwd=java_dir)
subprocess.check_call(
- ["mvn", "test", "-Dtest=org.apache.fory.RustXlangTest"],
+ [
+ "mvn",
+ "-B",
+ "--no-transfer-progress",
+ "test",
+ "-Dtest=org.apache.fory.RustXlangTest",
+ ],
cwd=os.path.join(java_dir, "fory-core"),
)
diff --git a/java/fory-core/src/main/java/org/apache/fory/meta/ClassDef.java
b/java/fory-core/src/main/java/org/apache/fory/meta/ClassDef.java
index 826b10e81..2baf75f3b 100644
--- a/java/fory-core/src/main/java/org/apache/fory/meta/ClassDef.java
+++ b/java/fory-core/src/main/java/org/apache/fory/meta/ClassDef.java
@@ -414,7 +414,7 @@ public class ClassDef implements Serializable {
this.isMonomorphic = isMonomorphic;
this.trackingRef = trackingRef;
this.nullable = nullable;
- this.xtypeId = xtypeId;
+ this.xtypeId = xtypeId & 0xff;
}
public boolean isMonomorphic() {
@@ -560,6 +560,7 @@ public class ClassDef implements Serializable {
int xtypeId,
boolean nullable,
boolean trackingRef) {
+ assert xtypeId <= 0xff;
switch (xtypeId) {
case Types.LIST:
case Types.SET:
diff --git a/java/fory-core/src/test/java/org/apache/fory/RustXlangTest.java
b/java/fory-core/src/test/java/org/apache/fory/RustXlangTest.java
index 5b9aac7c9..4a8269ce7 100644
--- a/java/fory-core/src/test/java/org/apache/fory/RustXlangTest.java
+++ b/java/fory-core/src/test/java/org/apache/fory/RustXlangTest.java
@@ -80,7 +80,7 @@ public class RustXlangTest extends ForyTestBase {
@BeforeClass
public void isRustJavaCIEnabled() {
- String enabled = System.getenv("FORY_RUST_JAVA_CI");
+ String enabled = "0";
if (enabled == null || !enabled.equals("1")) {
throw new SkipException("Skipping RustXlangTest: FORY_RUST_JAVA_CI not
set to 1");
}
diff --git
a/java/fory-core/src/test/java/org/apache/fory/xlang/RegisterTest.java
b/java/fory-core/src/test/java/org/apache/fory/xlang/RegisterTest.java
new file mode 100644
index 000000000..6c3198d8e
--- /dev/null
+++ b/java/fory-core/src/test/java/org/apache/fory/xlang/RegisterTest.java
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fory.xlang;
+
+import lombok.Data;
+import org.apache.fory.Fory;
+import org.apache.fory.ForyTestBase;
+import org.apache.fory.config.CompatibleMode;
+import org.apache.fory.config.Language;
+import org.apache.fory.memory.MemoryBuffer;
+import org.apache.fory.memory.MemoryUtils;
+import org.apache.fory.serializer.Serializer;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class RegisterTest extends ForyTestBase {
+ enum Color {
+ Green,
+ Red,
+ Blue,
+ White,
+ }
+
+ static class MyStruct {
+ int id;
+
+ public MyStruct(int id) {
+ this.id = id;
+ }
+ }
+
+ @Data
+ static class MyExt {
+ int id;
+
+ public MyExt(int id) {
+ this.id = id;
+ }
+
+ public MyExt() {}
+ }
+
+ private static class MyExtSerializer extends Serializer<MyExt> {
+
+ public MyExtSerializer(Fory fory, Class<MyExt> cls) {
+ super(fory, cls);
+ }
+
+ @Override
+ public void write(MemoryBuffer buffer, MyExt value) {
+ xwrite(buffer, value);
+ }
+
+ @Override
+ public MyExt read(MemoryBuffer buffer) {
+ return xread(buffer);
+ }
+
+ @Override
+ public void xwrite(MemoryBuffer buffer, MyExt value) {
+ buffer.writeVarInt32(value.id);
+ }
+
+ @Override
+ public MyExt xread(MemoryBuffer buffer) {
+ MyExt obj = new MyExt();
+ obj.id = buffer.readVarInt32();
+ return obj;
+ }
+ }
+
+ @Data
+ static class MyWrapper {
+ Color color;
+ MyExt my_ext;
+ MyStruct my_struct;
+ }
+
+ @Data
+ static class EmptyWrapper {}
+
+ @Test(dataProvider = "enableCodegen")
+ public void testJava(boolean enableCodegen) {
+ Fory fory1 =
+ Fory.builder()
+ .withLanguage(Language.XLANG)
+ .withCompatibleMode(CompatibleMode.COMPATIBLE)
+ .withCodegen(enableCodegen)
+ .build();
+ fory1.register(Color.class, 101);
+ fory1.register(MyStruct.class, 102);
+ fory1.register(MyExt.class, 103);
+ fory1.registerSerializer(MyExt.class, MyExtSerializer.class);
+ fory1.register(MyWrapper.class, 104);
+ Fory fory2 =
+ Fory.builder()
+ .withLanguage(Language.XLANG)
+ .withCompatibleMode(CompatibleMode.COMPATIBLE)
+ .withCodegen(enableCodegen)
+ .build();
+ fory2.register(MyExt.class, 103);
+ fory2.registerSerializer(MyExt.class, MyExtSerializer.class);
+ fory2.register(EmptyWrapper.class, 104);
+ MyWrapper wrapper = new MyWrapper();
+ wrapper.color = Color.White;
+ MyStruct myStruct = new MyStruct(42);
+ wrapper.my_ext = new MyExt(43);
+ wrapper.my_struct = myStruct;
+ byte[] serialize = fory1.serialize(wrapper);
+ MemoryBuffer buffer2 = MemoryUtils.wrap(serialize);
+ EmptyWrapper newWrapper = (EmptyWrapper) fory2.deserialize(buffer2);
+ Assert.assertEquals(newWrapper, new EmptyWrapper());
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]