Bifcode
view release on metacpan or search on metacpan
NAME
Bifcode - simple serialization format
VERSION
1.002 (2018-09-23)
SYNOPSIS
use boolean;
use Bifcode qw( encode_bifcode decode_bifcode );
my $bifcode = encode_bifcode {
bools => [ boolean::false, boolean::true, ],
bytes => \pack( 's<', 255 ),
integer => 25,
float => 1.25e-5,
undef => undef,
utf8 => "\x{df}",
};
# 7b 55 35 3a 62 6f 6f 6c 73 2c 5b 30 {U5:bools,[0
# 31 5d 55 35 3a 62 79 74 65 73 2c 42 1]U5:bytes,B
# 32 3a ff 0 2c 55 35 3a 66 6c 6f 61 2:..,U5:floa
# 74 2c 46 31 2e 32 35 65 2d 35 2c 55 t,F1.25e-5,U
# 37 3a 69 6e 74 65 67 65 72 2c 49 32 7:integer,I2
# 35 2c 55 35 3a 75 6e 64 65 66 2c 7e 5,U5:undef,~
# 55 34 3a 75 74 66 38 2c 55 32 3a c3 U4:utf8,U2:.
# 9f 2c 7d .,}
my $decoded = decode_bifcode $bifcode;
DESCRIPTION
Bifcode implements the *bifcode* serialisation format, a mixed
binary/text encoding with support for the following data types:
* Primitive:
* Undefined(null)
* Booleans(true/false)
* Integer numbers
* Floating point numbers
* UTF8 strings
* Binary strings
* Structured:
* Arrays(lists)
* Hashes(dictionaries)
The encoding is simple to construct and relatively easy to parse.
There is no need to escape special characters in strings. It is not
considered human readable, but as it is mostly text it can usually
be visually debugged.
*bifcode* can only be constructed canonically; i.e. there is only
one possible encoding per data structure. This property makes it
suitable for comparing structures (using cryptographic hashes)
across networks.
In terms of size the encoding is similar to minified JSON. In terms
of speed this module compares well with other pure Perl encoding
modules with the same features.
MOTIVATION
*bifcode* was created for a project because none of currently
available serialization formats (Bencode, JSON, MsgPack, Netstrings,
Sereal, YAML, etc) met the requirements of:
* Support for undef
* Support for binary data
* Support for UTF8 strings
* Universally-recognized canonical form for hashing
* Trivial to construct on the fly from SQLite triggers
I have no lofty goals or intentions to promote this outside of my
specific case, but would appreciate hearing about other uses or
implementations.
SPECIFICATION
The encoding is defined as follows:
( run in 0.555 second using v1.01-cache-2.11-cpan-e1769b4cff6 )