All Projects → danprince → Tiny Binary Format

danprince / Tiny Binary Format

Licence: mit
Memory efficient binary formats instead of objects.

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Tiny Binary Format

Nexe
🎉 create a single executable out of your node.js apps
Stars: ✭ 10,565 (+7288.11%)
Mutual labels:  binary
Snodge
Randomly mutate JSON, XML, HTML forms, text and binary data for fuzz testing
Stars: ✭ 121 (-15.38%)
Mutual labels:  binary
Heksa
CLI hex dumper with colors
Stars: ✭ 133 (-6.99%)
Mutual labels:  binary
Safe
SAFE: Self-Attentive Function Embeddings for binary similarity
Stars: ✭ 112 (-21.68%)
Mutual labels:  binary
Formatfuzzer
FormatFuzzer is a framework for high-efficiency, high-quality generation and parsing of binary inputs.
Stars: ✭ 117 (-18.18%)
Mutual labels:  binary
Opennpd
C++ detect and train of "A Fast and Accurate Unconstrained Face Detector".
Stars: ✭ 126 (-11.89%)
Mutual labels:  binary
Bingrep
like ~~grep~~ UBER, but for binaries
Stars: ✭ 1,395 (+875.52%)
Mutual labels:  binary
Binarykeyboard
A keyboard with two buttons that types in binary.
Stars: ✭ 141 (-1.4%)
Mutual labels:  binary
Go Wasm
WebAssembly binary file parser written in go
Stars: ✭ 121 (-15.38%)
Mutual labels:  binary
Borer
Efficient CBOR and JSON (de)serialization in Scala
Stars: ✭ 131 (-8.39%)
Mutual labels:  binary
Epk2extract
Extraction tool for LG, Hisense, Sharp, Philips/TPV, Thompson and similar TVs/Embedded Devices
Stars: ✭ 115 (-19.58%)
Mutual labels:  binary
Bssom.net
A small, high performance, powerful serializer using bssom binary protocol
Stars: ✭ 117 (-18.18%)
Mutual labels:  binary
Pwninit
pwninit - automate starting binary exploit challenges
Stars: ✭ 127 (-11.19%)
Mutual labels:  binary
Bepasty Server
binary pastebin server
Stars: ✭ 111 (-22.38%)
Mutual labels:  binary
Phpasn1
A PHP library to encode and decode arbitrary ASN.1 structures using ITU-T X.690 encoding rules.
Stars: ✭ 136 (-4.9%)
Mutual labels:  binary
Render
Go package for easily rendering JSON, XML, binary data, and HTML templates responses.
Stars: ✭ 1,562 (+992.31%)
Mutual labels:  binary
Vcf2phylip
Convert SNPs in VCF format to PHYLIP, NEXUS, binary NEXUS, or FASTA alignments for phylogenetic analysis
Stars: ✭ 126 (-11.89%)
Mutual labels:  binary
Exodus
Painless relocation of Linux binaries–and all of their dependencies–without containers.
Stars: ✭ 2,560 (+1690.21%)
Mutual labels:  binary
Binch
A light ELF binary patch tool in python urwid
Stars: ✭ 139 (-2.8%)
Mutual labels:  binary
Libmali
The Mali GPU library used in Rockchip Platform
Stars: ✭ 128 (-10.49%)
Mutual labels:  binary

Travis Status

tiny-binary-format

Memory efficient JS using binary formats instead of objects.

var BinaryFormat = require('tiny-binary-format');

var Tile = new BinaryFormat([
  { length: 8, name: 'type' },
  { length: 8, name: 'height' },
  { length: 1, name: 'vegetation' }
]);

Tile.pack(4, 48, 1);
// 000000100001100001 (2145)

Tile.unpack(2145);
// { type: 4, height: 48, vegetation: 1 }

Tile.unpackArray(2145);
// [4, 48, 1]

This library is designed to be used as a very thin wrapper around dealing with binary data yourself.

Define a format by creating an instance of BinaryFormat and passing in your field specifications. Then call the resulting object, passing instance data as arguments in order to create a binary representation.

When you need to read the values back, pass the number to either .unpack which returns the values in an object, or .unpackArray which returns them in an array.

Install

npm install tiny-binary-format
# or
bower install tiny-binary-format

Gotchas

The module was designed for storing lightweight tile representations for games, however it could be used for a lot of other things too. Just remember that once the data has been serialized, it will always be read back out as numbers.

This module should be used for removing the neccessity of working with bitwise operators when dealing with binary formats. It's not a framework and it won't hold your hand.

This module does no error handling whatsoever. If you care enough about performance to be using a binary format in the first place, then you'll appreciate the transparency of the pack and unpack methods.

However, this does mean that if you pass in a 9 bit number into an 8 bit field, you'll lose precision silently. Use it carefully.

As pointed out by @dioxmat, you're still bound by the restrictions of MAX_SAFE_INTEGER. If you're dealing with integers greater than 2 ^ 53, then expect things to break.

FAQ

What if I need to store strings or objects too?

If you arrived here looking for a Javascript library for parsing binary format files that include lots of data types, you've come to the wrong place. Go and check out binary-format

It doesn't seem to work for 64 bit floating numbers?

That's because the Javascript bitwise operators don't either. For a quick workaround, use the 64-bit-support branch.

What would be a good use case for this library?

This code was born from a game engine, read more about where it might be useful in the accompanying blog blost.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].