_                   _      _     
 ___| |_ _ __ _   _  ___| |_   (_)___ 
/ __| __| '__| | | |/ __| __|  | / __|
\__ \ |_| |  | |_| | (__| |_ _ | \__ \
|___/\__|_|   \__,_|\___|\__(_)/ |___/
                             |__/     
This is an implementation of Python Struct to Javascript.
The idea is to make an easy interface like python struct in javascript to parse strings as C Types.
- Full unpack support. I implemented all types unpack from python struct
- Big Endian and Little endian Support. You can choose the endianess like you do in python struct.
- Make use of Typed Arrays, Array Buffer and DataView from HTML5 Spec
- Packing functions.
In python, you use something like that for an int 1234:
import struct
data = '\xd2\x04\x00\x00'
struct.unpack("I", data)    #   This will return (1234,)So in struct.js you will do basicly the same:
var data = '\xd2\x04\x00\x00';
struct.unpack("I", data);   //   This will return [1234]It works also for multiple packed data, in python:
import struct
data = '\xe0#\x00\x00\x00\x00(Aa'
struct.unpack("Ifc", data)  #   This will return (9184, 10.5, 'a')In struct.js:
var data = '\xe0#\x00\x00\x00\x00(Aa';
struct.unpack("Ifc", data); //  This will return [9184, 10.5, "a"]struct.unpack(fmt, string)Arguments: fmt a string containing the types and endianess:
First Character is endianess (Optional)
- @Little Endian
- =Little Endian
- <Little Endian
- >Big Endian
- !Big Endian
First and/or other characters as the format:
- Format - C Type - Size - Description
- xPad Byte - 1 - This just skips one byte at the data
- cchar - 1 - String of Length 1
- bsigned char - 1 - Integer
- Bunsigned char - 1 - Integer
- ?boolean - 1 - Boolean
- hshort int - 2 - Int
- Hunsigned short - 2 - Integer
- iint - 4 - Integer
- Iunsigned int - 4 - Integer
- llong integer - 4 - Integer
- Lunsigned long - 4 - Integer
- qlong long - 8 - Integer
- Qunsigned long long - 8 - Integer
- ffloat - 4 - Float
- ddouble - 8 - Double
- schar[] - ? - String
- pchar[] - ? - String
- Pvoid * - 4 - Integer
Returns : array with the elements