Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Determining Message Size before sending over peerSocket

ANSWERED
Since there's a hard cap on the size of a single message sent through peerSocket.send() of 1027 bytes, we'll need a way to determine the message size before it is sent. The SDK docs say that messages will be CBOR encoded before sending, but does the message size refer to the size of the CBOR object or of the message before encoding? Also, is there a way to quickly and reliably determine the size of a message before sending it? Or should we try/catch RangeError? ES6 string characters are apparently either 2 or 5 bytes long, depending on the codepoints, but the device uses ES5.1, in which case string characters are always 2 bytes.
Best Answer
1 BEST ANSWER

Accepted Solutions

Unfortunately the options are pretty limited here. You can either catch the exception, or try packing your data into an Uint8Array and checking the size of that. Hopefully in a future update we'll have something to make this easier for you.

View best answer in original post

Best Answer
0 Votes
1 REPLY 1

Unfortunately the options are pretty limited here. You can either catch the exception, or try packing your data into an Uint8Array and checking the size of that. Hopefully in a future update we'll have something to make this easier for you.

Best Answer
0 Votes