theangryangel / jspack-arraybuffer Goto Github PK
View Code? Open in Web Editor NEWA reimplementation of jspack, using native array types. A convenience wrapper for ArrayBuffer DataView, essentially.
A reimplementation of jspack, using native array types. A convenience wrapper for ArrayBuffer DataView, essentially.
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"
Node now supports native types.
Test and package under node.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.