Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are furygo and furyJava not compatible? #2014

Open
1 of 2 tasks
LouisLou2 opened this issue Jan 20, 2025 · 1 comment
Open
1 of 2 tasks

Are furygo and furyJava not compatible? #2014

LouisLou2 opened this issue Jan 20, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@LouisLou2
Copy link

Search before asking

  • I had searched in the issues and found no similar issues.

Version

I'm using XLANG mode on both ends, but go still doesn't deserialize java serialized objects correctly!

Component(s)

Go

Minimal reproduce step

here is my trail. and please Let me know if I'm making some kind of cheap mistake.

My First Trial

java

public class Main {
  public static void main(String[] args) {
    Fury fury = Fury.builder()
      .withLanguage(Language.XLANG)
      .withRefTracking(true)
      .build();

    Map<String, Double> map = new HashMap<>();
    map.put("key", 1.0);
    map.put("key2", 2.0);
    byte [] bytes = fury.serialize(map);

    // save to file
    try (FileOutputStream fos = new FileOutputStream("sample_map.fury")) {
      fos.write(bytes);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

go

func deserialize() {
	bytes, err := os.ReadFile("./res/sample_map.fury")
	if err != nil {
		fmt.Println("Error reading file:", err)
		return
	}
	fury := fury2.NewFury(true)
	var newValue interface{}
	if err := fury.Unmarshal(bytes, &newValue); err != nil {
		panic(err)
	}
	fmt.Println(newValue)
}

The result is that bytes can be successfully deserialized in java but gives a strange error in go.

go console

GOROOT=/usr/lib/go-1.22 #gosetup
GOPATH=/home/leo/go #gosetup
/usr/lib/go-1.22/bin/go build -o /home/leo/.cache/JetBrains/GoLand2024.3/tmp/GoLand/___go_build_github_com_apache_fury_go_fury_main github.com/apache/fury/go/fury/main #gosetup
/home/leo/.cache/JetBrains/GoLand2024.3/tmp/GoLand/___go_build_github_com_apache_fury_go_fury_main #gosetup
panic: type of id 50 not supported, supported types: map[1:bool 2:uint8 3:int8 5:int16 7:int32 9:int64 11:float32 12:float64 13:string 14:[]uint8 16:fury.Date 18:time.Time 25:[]interface {} 30:map[interface {}]interface {} 257:fury.GenericSet 258:[]bool 259:[]int16 260:[]int32 261:[]int64 262:[]float32 263:[]float64 264:[]string]

goroutine 1 [running]:
main.deserialize()
	/home/leo/projects/furygo/main/main.go:54 +0x185
main.main()
	/home/leo/projects/furygo/main/main.go:37 +0xf

Process finished with the exit code 2

Second Trial

Next I went to discover the difference in the logic of the deserialization code between the two.

And then realized that in the go code there is one more part than in the java

go

buf.ReadInt32() // nativeObjectsStartOffset
nativeObjectsSize := buf.ReadInt32()
if f.peerLanguage == GO {
	if nativeObjectsSize > 0 {
		return fmt.Errorf("native serialization for golang is not supported currently")
	}
}
return f.ReadReferencable(buf, reflect.ValueOf(v).Elem())

java

obj = xreadRef(buffer);

I tried commenting out the code that reads an additional 4+4=8 bytes and then re-running the go code, however, a new error occurs

GOROOT=/usr/lib/go-1.22 #gosetup
GOPATH=/home/leo/go #gosetup
/usr/lib/go-1.22/bin/go build -o /home/leo/.cache/JetBrains/GoLand2024.3/tmp/GoLand/___go_build_github_com_apache_fury_go_fury_main github.com/apache/fury/go/fury/main #gosetup
/home/leo/.cache/JetBrains/GoLand2024.3/tmp/GoLand/___go_build_github_com_apache_fury_go_fury_main #gosetup
panic: type of id 29 not supported, supported types: map[1:bool 2:uint8 3:int8 5:int16 7:int32 9:int64 11:float32 12:float64 13:string 14:[]uint8 16:fury.Date 18:time.Time 25:[]interface {} 30:map[interface {}]interface {} 257:fury.GenericSet 258:[]bool 259:[]int16 260:[]int32 261:[]int64 262:[]float32 263:[]float64 264:[]string]

goroutine 1 [running]:
main.deserialize()
	/home/leo/projects/furygo/main/main.go:54 +0x185
main.main()
	/home/leo/projects/furygo/main/main.go:37 +0xf

Process finished with the exit code 2

I can roughly see that it's a type mismatch error, and then I went and compared the type id declared in furygo's type.go with the definition in the guide(xlang_type_mapping), and there seems to be some discrepancies, and I'm a little confused about these conflicts, or am I using it incorrectly?

What did you expect to see?

furygo deserialized object successfully

What did you see instead?

unsupported type error

Anything Else?

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR!
@LouisLou2 LouisLou2 added the bug Something isn't working label Jan 20, 2025
@chaokunyang
Copy link
Collaborator

Hi @LouisLou2 , which fury java version are you using? We are refactoring the xlang serialization spec. The first part of Fury java has been finished in #1690 , but the golang implementation has not be finished. Is this related to your issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants