I cant deserialize a sfs object with Java

Post here your questions about the HTML5 / JavaScript for SFS2X

Moderators: Lapo, Bax

impedro29
Posts: 2
Joined: 27 Oct 2021, 00:01

I cant deserialize a sfs object with Java

Postby impedro29 » 27 Oct 2021, 00:43

Hi, i trying to deserialize these data:

Code: Select all

        var sfsObj = new SFSObject();
        byte[] bts = new byte[]{128, 1, 89, 18, 0, 3, 0, 1, 112, 18, 0, 2, 0, 1, 112, 18, 0, 3, 0, 11, 110, 101, 119, 95, 98, 111, 109, 98, 101, 114, 115, 17, 0, 0, 0, 7, 98, 111, 109, 98, 101, 114, 115, 17, 0, 1, 18, 0, 17, 0, 9, 99, 104, 97, 114, 97, 99, 116, 111, 114, 4, 0, 0, 0, 4, 0, 5, 99, 111, 108, 111, 114, 4, 0, 0, 0, 1, 0, 5, 108, 101, 118, 101, 108, 4, 0, 0, 0, 1, 0, 7, 115, 116, 97, 109, 105, 110, 97, 4, 0, 0, 0, 2, 0, 6, 97, 99, 116, 105, 118, 101, 4, 0, 0, 0, 1, 0, 4, 98, 111, 109, 98, 4, 0, 0, 0, 1, 0, 5, 115, 112, 101, 101, 100, 4, 0, 0, 0, 2, 0, 6, 103, 101, 110, 95, 105, 100, 8, 0, 30, 49, 50, 48, 49, 50, 48, 49, 51, 50, 55, 52, 54, 49, 56, 49, 56, 49, 56, 48, 48, 53, 51, 48, 55, 56, 49, 50, 49, 53, 49, 0, 5, 115, 116, 97, 103, 101, 4, 0, 0, 0, 1, 0, 10, 114, 101, 115, 116, 111, 114, 101, 95, 104, 112, 4, 0, 0, 0, 100, 0, 4, 114, 97, 114, 101, 4, 0, 0, 0, 0, 0, 2, 105, 100, 5, 0, 0, 0, 0, 0, 12, 105, 55, 0, 5, 112, 111, 119, 101, 114, 4, 0, 0, 0, 1, 0, 7, 97, 98, 105, 108, 105, 116, 121, 17, 0, 1, 4, 0, 0, 0, 3, 0, 10, 98, 111, 109, 98, 95, 114, 97, 110, 103, 101, 4, 0, 0, 0, 1, 0, 9, 98, 111, 109, 98, 95, 115, 107, 105, 110, 4, 0, 0, 0, 14, 0, 6, 101, 110, 101, 114, 103, 121, 4, 0, 0, 0, 0, 0, 2, 101, 99, 4, 0, 0, 0, 0, 0, 1, 99, 8, 0, 14, 83, 89, 78, 67, 95, 66, 79, 77, 66, 69, 82, 77, 65, 78, 0, 1, 97, 3, 0, 13, 0, 1, 99, 2, 1};
        SFSObject deserializedData = SFSObject.newFromBinaryData(bts);

        System.out.println(deserializedData.getDump());


Error returned:

Code: Select all

Exception in thread "main" java.lang.IllegalStateException: Invalid SFSDataType. Expected: 18, found: 1
   at com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.decodeSFSObject(DefaultSFSDataSerializer.java:182)
   at com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.binary2object(DefaultSFSDataSerializer.java:170)
   at com.smartfoxserver.v2.entities.data.SFSObject.newFromBinaryData(SFSObject.java:149)
   at com.company.Main.main(main.java:13)



Obs: im beginner on java
Last edited by impedro29 on 28 Oct 2021, 15:26, edited 1 time in total.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: I cant deserialize a sfs object with JS

Postby Lapo » 27 Oct 2021, 07:48

Hi,
the code posted here is Java not JS ... presuming JS == Javascript.

Can you give us more details as to what you're trying to accomplish?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
impedro29
Posts: 2
Joined: 27 Oct 2021, 00:01

Re: I cant deserialize a sfs object with Java

Postby impedro29 » 29 Oct 2021, 01:48

I have this array of bytes, im setting it in the memory and i have to get with byte array and decode on other language (java/other backend).
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: I cant deserialize a sfs object with Java

Postby Lapo » 29 Oct 2021, 07:11

The packet posted here contains an header which is parsed before passing the actual data to the deserializer.
If you pass the whole thing to the deserializer it will fail because it doesn't know how to parse the packet header, as it's not its job.

You need to remove the first three bytes in the array.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X HTML5 / JavaScript API”

Who is online

Users browsing this forum: No registered users and 20 guests