Create json object with integers of type char

Hi,
I am using this method
to convert an int to a char (1 byte in length). But, when I create the following json object
Then, on the mobile client I see that "a_key" has a value with length of 8 bytes, and not 1.
How can I fix this?
I am using this method
function toChar(number) { var int8 = new Int8Array(1); int8[0] = number; return int8[0]; }
to convert an int to a char (1 byte in length). But, when I create the following json object
var obj = {"a_key":tochar(1)};
Then, on the mobile client I see that "a_key" has a value with length of 8 bytes, and not 1.
"{length = 8, bytes = 0x0000000000804840}"
How can I fix this?
0
Comments
Json format used for serialization does not support typed arrays. You can use only conventional javascript arrays.
Then this is a bug of the JS SDK. I should be able to use a short / char (or byte) integer in a json object.
On the other hand, I found the Photon.TypeExt class, and it has methods for byte, short, etc.
Is this what I should use?
There has to be a way to send a message that has the correct size.
Which doc you are referencing in your last message?
Here is the doc
https://doc.photonengine.com/en-us/realtime/current/reference/serialization-in-photon
According to that documentation, the JS client should be able to handle byte and short data types
So you can send anything that json supports: https://www.json.org/json-en.html
If type information required, you can send it in wrapping object: Instead of sending 100 as a byte, send {value=100, type=1} object, for 100 as a short, send {value=100, type=2}. Then parse to whatever you want on receiving side.
The purpose of using the byte/short data type is because I want to reduce the size of the message.
Is it in your plans to use a binary protocol for sending data?
You can try to pack entire message to one string. Such payload should produce json serialized message of minimal size in theory.
We have experimental js library implementation which uses the same serialization as native or c# client. But we are not supporting it currently. So in case you switch to it, it might happen that you find a bug and we can't fix it.
Firstly, the smaller the size of the message is the faster it will be transmitted
Secondly, because I used those data types on the mobile apps. Since the JS client does not support them, I have to release a new version for the mobile apps.
How buggy is this experimental library? Does this library has the same callbacks with the existing one? If yes, I prefer to use it, than to release a new version for the mobile apps.
Change import from Photon-Javascript_SDK.js to Photon-Javascript_Emscripten_SDK.js (this file should be in SDK package).
Now client uses binary protocol and is able to apply types on numbers with methods like Photon.TypeExt.Byte.
Thank you
I tried this code:
But, I get the following error message:
I tried everything, even the [TypeExt.Int(1)], but I did not think of your solution.
Thank you!!
After a few logins, I see the following error message:
Is this the bug that you mentioned?
I followed the instructions from https://github.com/gimite/web-socket-js#troubleshooting
and I am not opening the html page as a local page. But, it did not help
So you joined a room a few times and since then you can't join anymore?
Can you reproduce this with one of demo apps from sdk package? If yes, can you provide steps required?
I do not think that I will be able to reproduce it with your demo app. This is because when I start the app, all users (from mobile clients) connect to a custom Lobby room.
I get the above error after the 5th time.
Could it be because I am not properly disconnecting from the server?
Which url you connect initially? ws://ns.exitgames.com:9093 ?
It makes sense to send us at least full client log with maximum logging level,
I will try to, but , I notice the following:
When I successfully login it makes two requests.
When it fails, it makes 3 requests