JSON and NODE
- hallsofvallhalla
- Site Admin
- Posts: 12023
- Joined: Wed Apr 22, 2009 11:29 pm
JSON and NODE
So I know need to add several arrays to my map system and transfer them through Node. I want to make this as small as a footprint as possible. It will be around 10 arrays with the size of 144. I am not that familiar with JSON but would it be the best choice for transferring this info? Will it reduce the size significantly?
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: JSON and NODE
JSON is not really designed to shrink your dataset, but rather, to make it easy to work with (particularly in Javascript since they are native JS objects). JSON was largely a response to the horrid bother of dealing with XML data in the early-to-mid 2000's.
If you have that much data, you would likely be better off with a custom, compressed protocol. Provided you can write the code to pack it on the server side and the code to unpack it on the client-side, it can be as tight as you want. For example, you could even have something that looks like this:
...where each symbol represents a map point type and the semi-colons are some kind of delimiter. Of course I have no idea if that specific format would be helpful, since only you would know a way to represent it.
JSON is simply a way of representing data, but it is not a byte-efficient way of storing it for certain usages (for strings it is actually quite efficient, but games don't typically need whole, unique strings to represent map data).
If you have that much data, you would likely be better off with a custom, compressed protocol. Provided you can write the code to pack it on the server side and the code to unpack it on the client-side, it can be as tight as you want. For example, you could even have something that looks like this:
Code: Select all
"[ajD342sasDFg;aA35iDiap@;p51z5OHH9a;]"
JSON is simply a way of representing data, but it is not a byte-efficient way of storing it for certain usages (for strings it is actually quite efficient, but games don't typically need whole, unique strings to represent map data).
The indelible lord of tl;dr
-
- Posts: 21
- Joined: Thu Jul 12, 2012 11:28 pm
Re: JSON and NODE
You can come up with your own compression algorithm or use gzip or other compression technologies. Node .6 or higher has it built in I believe. I have not done it myself, but a google search should help you figure out how to do it.
This link was for a library that is no longer needed I believe: http://me.dt.in.th/page/NodeJS-express-gzip . Make sure you read the June update at the top if you look at the link (That's where I read it was built into Node).
This link was for a library that is no longer needed I believe: http://me.dt.in.th/page/NodeJS-express-gzip . Make sure you read the June update at the top if you look at the link (That's where I read it was built into Node).
- hallsofvallhalla
- Site Admin
- Posts: 12023
- Joined: Wed Apr 22, 2009 11:29 pm
Re: JSON and NODE
interesting info here thanks. I assumed JSON shrunk the data but actually never questioned how. I already have a compressed version of the data coming across. I basically use a simple array of numbers to represent the map much like Impact works. The entire map with data is around 200 bytes.
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
- hallsofvallhalla
- Site Admin
- Posts: 12023
- Joined: Wed Apr 22, 2009 11:29 pm
Re: JSON and NODE
kewl. I was hoping it would be good. I may have to stretch that but I figure 1 character = about a byte so I just got to keep it low. I want to do a stress test soon. Might get it up and going with the chat system then have everyone test it.