Giter VIP home page Giter VIP logo

float-numbers-with-huffman's Introduction

Float-numbers-with-Huffman

This library designed to compress a JSON string that contains float numbers. It uses Huffman algorithm (except order) to compress JSON string.

Reason

I'm using socket.io on my online games because of simplicity and advantages of JSON format. However transfering position and rotation data over JSON format costs too much bandwidth. This is why I wrote this simple library. The library compresses JSON format that contains float numbers and provides an ASCI output that can be used on socket.io data transfer.

Also, compressing all data on socket.io causes another problem. It sends extra bytes to catch byte point or cursor. Because of that it continues to send JSON data and that makes it useless for compression.

Advantages

  • Very simple
  • Works on browser (Tested on Chrome, Firefox)
  • Easy to implement (only encode and decode functions)
  • It's still possible to use JSON format on socket io for other emits

Examples

I'm sending position and rotation data like this : [1,0,-108.566,2.200,0.182,0.800,0.00044049781129770765,-89.968]

It costs 63 bytes, this is random data captured from my FPS game.

When we compress this data with this compressor, it provides an ASCI output like this : ñ`Í!6Îøvx,¤ð\à°¨Z":í5tóþ

And this output costs 23 bytes which is perfect for most cases.

Simply using encode function encodes JSON and decode function decodes ASCI output. Here is an full example :

var value = JSON.stringify([1,0,-108.566,2.200,0.182,0.800,0.00044049781129770765,-89.968]);

var encoded = floatCompress.encode(value);

var decoded = floatCompress.decode(encoded);

TODO

  • Consider to use sort function to provide better compression quality.
  • Consider to support all characters to provide a reliable library for socket.io

float-numbers-with-huffman's People

Contributors

devcem avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.