A Java implementation of Binson. Binson is like JSON, but faster, binary and even simpler. See binson.org.
Add binson.jar to your project. There are no other dependencies. Most developers only need to use the Binson class.
The code below first creates a Binson object with two fields: one integer named 'a' and one string named 's'. Then 'obj' is serialized to bytes. The third line parses back the bytes to a Binson object again, and the last line checks that the parsed Binson object is the same as the original one.
Binson obj = new Binson().put("a", 123).put("s", "Hello world!"); byte bytes = obj.toBytes(); Binson obj2 = Binson.fromBytes(bytes); assert obj2.equals(obj);
This library also contains JSON (http://json.org/) support. See methods Binson.fromJson() and Binson.toJson().
Build with ANT:
Other build tools should be easy to adapt for the source. The code in src/ only depends on the JVM (Java 6 or later should work).
The tests in src-test/ depends on JUnit (junit-4.12.jar, hamcrest-core-1.3.jar). JUnit jars are not included in the repo.
Log entries, latest entry first, format: YYMMDD.
Frans: improvements based on a security analysis 2018-05-31.
Frans: Tested the tool abnfgen (http://www.quut.com/abnfgen/). Not very useful since most generated random abnf documents will not be valid Binson due to Binson's additional rules beyond following the ABNF format. Most often, sizes of strings or bytes will be wrong. This is expected.
However, I did find an issue (known, but not fixed). It triggered rewriting BinsonParser to support more controlled memory allocation. Now there is a maxSize setting; the maximum size a Binson object should have, otherwise the Parser will throw a BinsonFormatException when parsing. This is important. In previous versions, a maliciously crafted Binson object could be used to provoke an OutOfMemoryException.
Frans: Release 2.0. Renaming: FormatException to BinsonFormatException. Stable code: No known bugs, 225 successful unit tests, good coverage, no warnings. There has been zero known bugs since November 2015 and the library has been used heavily since then. Perhaps fuzz testing could find a few bugs, though? Would be interesting to try https://github.com/nradov/abnffuzzer.
Frans: Release 1.5. The BinsonArray.getXxx() method now throws FormatException for unexpected element types.
Frans: Release 1.4. Minor changes from previous release. Note, this release was not added to the Github releases.
Frans: Bug in field sort order fixed thanks to a bug report by Alexander Reshniuk.
Frans: Release 1.1.
Frans: Release 1.0.
Frans: Added Binson Schema validation (might be called BINSON-SCHEMA-1) in 40 lines of code.
Frans: First upload to github.com. Before that I stored it locally.