Code Monkey home page Code Monkey logo

jspack-arraybuffer's Introduction

jspack-arraybuffer
==================
A reimplementation of jspack (http://code.google.com/p/jspack) which uses native
typed arrays, whilst maintaining a (mostly) compatible API.

May be buggy/incomplete. Built for and tested with lfswsrelay.js
(https://github.com/theangryangel/lfswsrelay.js). Patches, etc. welcome.

lfswsrelay.js is a good example of usage.

If you're used to using the Python struct module, or PHP's pack and unpack, you
might prefer this over natively using the ArrayBuffer & DataView APIs.

 struct.unpack(format, ArrayBuffer, offset);
  Returns an array containing values unpacked from the ArrayBuffer, into their
  native types, begining at offset. If offset is not supplied, it is assumed
  from offset of 0.

 struct.pack(format, values);
  Returns an ArrayBuffer with packed values. The ArrayBuffer size is
  automatically calculated from the supplied format.

 struct.calcLength(format);
  Returns the necessary size required to fit packed values, according to the
  supplied format.

 Format is a string, made up of the following table
   Format | C Type         | JavaScript Type   | Size (bytes) 
  ----------------------------------------------------------------------------
        < | N/A            | N/A               | 0 
          |                |                   | Signifies little endian.
          |                |                   | Must be first value in format
          |                |                   | string. If not supplied big
          |                |                   | endian is assumed
  ----------------------------------------------------------------------------
        A | char[]         | Array             | Length      
  ----------------------------------------------------------------------------
        x | pad byte       | N/A               | 1
  ----------------------------------------------------------------------------
        c | char           | string (length 1) | 1
  ----------------------------------------------------------------------------
        b | signed char    | number            | 1
  ----------------------------------------------------------------------------
        B | unsigned char  | number            | 1
  ----------------------------------------------------------------------------
        h | signed short   | number            | 2
  ----------------------------------------------------------------------------
        H | unsigned short | number            | 2
  ----------------------------------------------------------------------------
        i | signed long    | number            | 4
  ----------------------------------------------------------------------------
        I | unsigned long  | number            | 4
  ----------------------------------------------------------------------------
        l | signed long    | number            | 4
  ----------------------------------------------------------------------------
        L | unsigned long  | number            | 4
  ----------------------------------------------------------------------------
        s | char[]         | string            | Length
  ----------------------------------------------------------------------------
        f | float          | number            | 4
  ----------------------------------------------------------------------------
        d | double         | number            | 8

  For example, to pack a little endian, 32 character string, and 2 unsigned
  char, the following format will work:
   "<32sBB"

jspack-arraybuffer's People

Contributors

theangryangel avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

jspack-arraybuffer's Issues

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.