Bifcode
view release on metacpan or search on metacpan
lib/Bifcode.pm view on Meta::CPAN
| F -? [0-9]+ \. [0-9]+ e -? [0-9]+ ,
| I [0-9]+ ,
) /\n$1/gmx;
$bifcode =~ s/ \A \n //mx;
$bifcode . "\n";
}
sub diff_bifcode {
_croak 'DiffUsage' unless @_ >= 2 and @_ <= 3;
my $b1 = shift;
my $b2 = shift;
my $diff_args = shift || { STYLE => 'Unified' };
require Text::Diff;
$b1 = _expand_bifcode($b1);
$b2 = _expand_bifcode($b2);
return Text::Diff::diff( \$b1, \$b2, $diff_args );
}
decode_bifcode('I1,');
__END__
=pod
=encoding utf8
=head1 NAME
Bifcode - simple serialization format
=head1 VERSION
1.002 (2018-09-23)
=head1 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;
=head1 DESCRIPTION
B<Bifcode> implements the I<bifcode> serialisation format, a mixed
binary/text encoding with support for the following data types:
=over
=item * Primitive:
=over
=item * Undefined(null)
=item * Booleans(true/false)
=item * Integer numbers
=item * Floating point numbers
=item * UTF8 strings
=item * Binary strings
=back
=item * Structured:
=over
=item * Arrays(lists)
=item * Hashes(dictionaries)
=back
=back
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.
I<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.
=head1 MOTIVATION
I<bifcode> was created for a project because none of currently
available serialization formats (Bencode, JSON, MsgPack, Netstrings,
Sereal, YAML, etc) met the requirements of:
=over
=item * Support for undef
( run in 0.575 second using v1.01-cache-2.11-cpan-13bb782fe5a )