Join
Google+

User:
Pass:
Save:

New Demos

Top Demos

Web Tools   (13)


Android (1) Archive (7) Audio (1) C64 (1) Construct2 (1) Ebook (2) Flash (25) Html5 (4) Image (39) Java (1) Javascript (19) Stylesheet (1) SVG (2) - RaphaelJS - WebGL - Unity - Box2D

Top Author






Top Reviewer






Top Commenter






Binary Parser

var BinaryParser = function (binaryReader, description, caller) { this.binaryReader = binaryReader; this.description = BinaryParser.stdDescription; for (var i in description) { this.description[i] = description[i]; } this.caller = caller; var that = this; this.param = { parse: function (desc, param) { return that.parse(desc, param); }, binaryReader: binaryReader }; }; BinaryParser.stdDescription = { uint8: function (config) { return config.binaryReader.getUint8(); }, int8: function (config) { return config.binaryReader.getInt8(); }, uint16: function (config) { return config.binaryReader.getUint16(); }, int16: function (config) { return config.binaryReader.getInt16(); }, uint32: function (config) { return config.binaryReader.getUint32(); }, int32: function (config) { return config.binaryReader.getInt32(); }, float: function (config) { return config.binaryReader.getFloat32(); }, char: function (config) { return config.binaryReader.getChar(); }, string: function (config, size) { return config.binaryReader.getString(size); }, array: function (config, type, number) { var num_type = typeof number; var k = num_type === 'number' ? number : num_type === 'function' ? number(config) : 0; var array = []; for (var i = 0; i < k; ++i) { array[i] = config.parse(type); } return array; } }; BinaryParser.prototype = { parse: function (description, param) { var type = typeof description; if (type === 'function') { return description.apply(this.caller, [this.param].concat(param)); } // Shortcut: 'string' == ['string'] if (type === 'string') { description = [description]; } if (description instanceof Array) { return this.parse(this.description[description[0]], description.slice(1)); } if (type === 'object') { var output = {}; for (var key in description) { if (!description.hasOwnProperty(key)) { continue; } output[key] = this.parse(description[key]); } return output; } throw new Error('Unknown description type ' + description); } };

About: Javascript Binary Parser

Info: binary parser function


Category: Javascript


Author: Unknown


Viewed: 2017-04-26 02:50:53

Views: 77128


BinaryParser.js

Downloads: 0

Rating: 5

Rate: 1 2 3 4 5 6 7 8 9 10


Comments welcome.


New Comment

Title:        By:



{kustomzone.com}