Forum General getUInt

Discussion and help relating to the PlayerIO JavaScript SDK

getUInt

Postby Emalton » May 4th, 2017, 2:12 am

Hi all,

How can I get the unsigned-integer from a message based off of the index? I get the following while trying message.getUInt(1), even though the documentation clearly states that as a method.
Code: Select all
Unhandled error in callback: entryType_UInt is not defined

Stack:
ReferenceError: entryType_UInt is not defined
    at _pio.message.getUInt (PlayerIOClient.development.js:3152:22)
    at Object._pio.runCallback (PlayerIOClient.development.js:65:5)
    at executeCallbacks (PlayerIOClient.development.js:2875:12)
    at PlayerIOClient.development.js:2860:9
    at FileReader.fr.onloadend (PlayerIOClient.development.js:2733:7)
Callsite stack:
Error
    at _pio.connection.addMessageCallback (PlayerIOClient.development.js:2907:49)
    at Object._pio.runCallback (PlayerIOClient.development.js:65:5)
    at PlayerIOClient.development.js:2853:16
    at FileReader.fr.onloadend (PlayerIOClient.development.js:2733:7)


Any help is appreciated!

Emalton
Emalton
 
Posts: 86
Joined: June 28th, 2013, 3:49 am

Re: getUInt

Postby Henrik » May 4th, 2017, 2:31 am

Thanks for catching that typo for us. It's fixed now, if you download the latest SDK that I just published. :-)
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: getUInt

Postby Emalton » May 7th, 2017, 7:14 pm

Hey Henrik,

Everything has been working great so far, but for some reasons doubles do not seem to return their correct values.
Instead of returning just a double, it returns 2 more messages.

Return from C#:
Code: Select all
msg[10] = 16  (4)


Return from JS:
Code: Select all
msg[10] = 6.1027e-320 (Double)
msg[11] = 0 (Float)
msg[12] = true (Boolean)


pls help

Emalton
Emalton
 
Posts: 86
Joined: June 28th, 2013, 3:49 am

Re: getUInt

Postby atillabyte » May 7th, 2017, 10:52 pm

I fixed both of these, forgot several case breaks and also little endian.

Code: Select all
@@ -3521,9 +3534,9 @@ PlayerIOErrorCode = {
               case shortLongBottomPattern:
               case longBottomPattern: output.addLong(_pio.binaryserializer.longFromBytes(bytes, position, length)); break;
               case shortUnsignedLongBottomPattern:
-               case unsignedLongBottomPattern: output.addULong(_pio.binaryserializer.ulongFromBytes(bytes, position, length));
-               case doublePattern: output.addDouble(_pio.binaryserializer.doubleFromBytes(bytes, position, length));
-               case floatPattern: output.addFloat(_pio.binaryserializer.floatFromBytes(bytes, position, length));
+               case unsignedLongBottomPattern: output.addULong(_pio.binaryserializer.ulongFromBytes(bytes, position, length)); break;
+               case doublePattern: output.addDouble(_pio.binaryserializer.doubleFromBytes(bytes, position, length)); break;
+               case floatPattern: output.addFloat(_pio.binaryserializer.floatFromBytes(bytes, position, length)); break;
               case booleanTruePattern: output.addBool(true); break;
               case booleanFalsePattern: output.addBool(false); break;
            }
@@ -3651,7 +3664,7 @@ PlayerIOErrorCode = {
            var o = b.length - i;
            b[i] = length >= o ? bytes[position + length - o] : 0;
         }
-         return decodeFloat(b, 1, 11, 52, -1022, 1023, true);
+         return decodeFloat(b, 1, 11, 52, -1022, 1023, false);
      }
   }
atillabyte
 
Posts: 2
Joined: March 13th, 2017, 11:59 pm

Re: getUInt

Postby Emalton » May 7th, 2017, 11:24 pm

Thanks Atilla!
Emalton
 
Posts: 86
Joined: June 28th, 2013, 3:49 am

Re: getUInt

Postby Henrik » May 19th, 2017, 4:52 am

Thanks for bringing these bugs to our attention!

We've fixed them, and a few more that were lurking around the same place. It was mostly related to edge-cases involving large numbers, which are iffy to start with since JavaScript doesn't really have all the datatypes that the protocol and the other clients support.

We've also added a little bit of type coercion when you use the type-specific methods for adding data to a message. If you do something like:

Code: Select all
var m = connection.createMessage('hello');
m.addInt(3.141592);
connection.sendMessage(m);

...it actually gets sent as the integer 3, and you need to call message.GetInteger(0); to pick it up on the server-side.

However, if you do something like:

Code: Select all
connection.send('hello', 3.141592);

...type inference kicks in, and it gets sent as the double 3.141592.

There's also some gotchas here due to the lack of types, if you do something like this:

Code: Select all
connection.send('hello', 0.33333333333333333333333333333 * 3);

...it gets sent as the integer 1, even though you obviously did a fractional calculation to get the data.
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm


Return to General