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

String decoding problem #566

Closed
sonwh98 opened this issue Oct 3, 2017 · 5 comments
Closed

String decoding problem #566

sonwh98 opened this issue Oct 3, 2017 · 5 comments
Labels

Comments

@sonwh98
Copy link

sonwh98 commented Oct 3, 2017

I am using https://github.com/cognitect/transit-java to send json encoded messages between server and client.

On the server I'm using Clojure transit to encoded the list ["a" "b"] which gives the string "[\"a\",\"b\"]" with a hashCode of -939944225

On the client in the WebSocketClient.onMessage I get a message="[\"a\",\"b\"]" with a hashCode of -120497949. The string when printed to the console looks identical to whats encoded but it has a different hashCode which is making decoding transit message to fail.

I created a custom built jar from master because using the jar from maven central failed with a handshake error

@marci4
Copy link
Collaborator

marci4 commented Oct 3, 2017

Hello @sonwh98,

thx for your bug report!
I feel that this issue is not related to the project itself but to the transit-java project.
The reason for this is, that the encoding is there not specified (see this open issue).
For the websocket protocol it is specified that if you are sending a TextFrame, it's payload has to be encoded in utf-8.

What was the handshake error?

Greetings
marci4
This is, what will be the

@marci4 marci4 added the Question label Oct 3, 2017
@sonwh98
Copy link
Author

sonwh98 commented Oct 3, 2017

thanks for responding. I will report the handshake error in a different issue

transit is UTF-8 encoded. I have no problem decoding it from the javascript side in a web browser.

in the onMessage callback the hashCode of message:"[\"a\",\"b\"]" is -120497949. However, in the same code block doing "[\"a\",\"b\"]".hashCode() gives -939944225 as it does on the clojure side on the server. This tells me that the hashCode -939944225 is correct

public static String stringUtf8( ByteBuffer bytes ) throws InvalidDataException {
seems more complicated than it needs to be. it can be replaced with a oneliner
new String(bytes.array(), "UTF-8");

@marci4
Copy link
Collaborator

marci4 commented Oct 3, 2017

Hello @sonwh98,

well, it could be fine on for the browser since you don't compare the string on the hashCode level.

So you are saying the hashCode changes after a hashCode() call?

Thx for your input. That is right now not possible due to the 1.5 java version support (keeping the android support in mind)

Greetings
marci4

@sonwh98
Copy link
Author

sonwh98 commented Oct 4, 2017

@marci4 I think I know whats going on, but I do not know if this is the proper behavior.

encoding a vector in transit ["a"] produces a string which has 5 character and a hasCode of 85147669

[
"
a
"
]

in the onMessage the value of the message is the string which has 9 characters and a hasCode of -530250003. The characters in that string is:

"
[
\
"
a
\
"
]
"

it seems the string in the message has 2 extra " and 2 extra \ characters. is this the expected behavior? This is not the behavior I am expecting. I should get the original string that was sent from the server

@sonwh98
Copy link
Author

sonwh98 commented Oct 4, 2017

@marci4 ok i think this is a problem with the serverside clojure websocket lib i'm using https://github.com/jarohen/chord I sent a raw clojure vector without encoding it with transit and got the expected string on the kotlin side. This shows that chord websocket library already does some kind of encoding before sending it to the client. It works on clojurescript in the browser only because i'm using the chord clientside lib that somehow knows how to decode. Sorry to bother you! the fix was to configure chord to format as string instead of EDN sonwh98/wocket@4384e89

@sonwh98 sonwh98 closed this as completed Oct 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants