-
-
Save tomfa/706d10fed78c497731ac to your computer and use it in GitHub Desktop.
// JSON to Uint8Array parsing and visa versa | |
// (Intended Bluetooth communication on Cordova) | |
var JsonToArray = function(json) | |
{ | |
var str = JSON.stringify(json, null, 0); | |
var ret = new Uint8Array(str.length); | |
for (var i = 0; i < str.length; i++) { | |
ret[i] = str.charCodeAt(i); | |
} | |
return ret | |
}; | |
var binArrayToJson = function(binArray) | |
{ | |
var str = ""; | |
for (var i = 0; i < binArray.length; i++) { | |
str += String.fromCharCode(parseInt(binArray[i])); | |
} | |
return JSON.parse(str) | |
} |
i don't need payload to be human readable and i thought i coudl benefit some reduction from the payload size. is there any good way to do this that you could suggest? i don't think im the first one to think of such a thing. ive researched grpc but i guess its only used in backend between different services.
I guess you could, but I'm not sure what benefits that would provide. Most HTTP requests are gzipped, so I doubt it would reduce network traffic
It sounds like you want to reduce network traffic between the server and client. This is well known and optimized problem, and there's various solutions to go for depending on your priorities / most pressing motivation.
- are you trying to learn about computer science?
- are you trying to minimize costs?
- do you consider your time spent on the optimization a cost?
- do you want to minimize experienced latency?
- are you trying to minimize network traffic?
I would not consider doing what you're thinking of in 99.9% of the cases of 2, 3 or 4.
Give me some more info about your situation, and maybe I can give better advice. You could also consider installing Cursor and asking AI - which has better answers and response times than most internet randos like myself
I guess you could, but I'm not sure what benefits that would provide. Most HTTP requests are gzipped, so I doubt it would reduce network traffic