BSON
view release on metacpan or search on metacpan
[BUG FIXES]
- Fix t/10-bson.t bug comparing floating point values; now using
Test::Number::Delta for comparison
0.12 2015-04-06 16:11:59-04:00 America/New_York
[BUG FIXES]
- added decoding support for BSON type 0x06 (Javascript "undefined");
treated like type 0x0A (null value) and decoded as Perl undef
[OPTIMIZATION]
- Inlined most functions for 10-20% performance increase measured
on a sample of Twitter tweets.
[META]
- Switched repository to Dist::Zilla structure using @DAGOLDEN plugin
bundle and associated file layout
IMPORTANT CAVEAT: the heuristics for determining whether something is a
string or number are less accurate on older Perls. See BSON::Types for
wrapper classes that specify exact serialization types.
The default is false.
wrap_dbrefs
If set to true, during decoding, documents with the fields '$id' and
'$ref' (literal dollar signs, not variables) will be wrapped as
BSON::DBRef objects. If false, they are decoded into ordinary hash
references (or ordered hashes, if "ordered" is true).
The default is true.
wrap_numbers
If set to true, during decoding, numeric values will be wrapped into
BSON type-wrappers: BSON::Double, BSON::Int64 or BSON::Int32. While very
slow, this can help ensure fields can round-trip if unmodified.
The default is false.
* op_char â overrides codec default
* prefer_numeric â overrides codec default
decode_one
$doc = $codec->decode_one( $byte_string );
$doc = $codec->decode_one( $byte_string, \%options );
Takes a byte string with a BSON-encoded document and returns a hash
reference representing the decoded document.
An optional hash reference of options may be provided. Valid options
include:
* dt_type â overrides codec default
* error_callback â overrides codec default
* max_length â overrides codec default
corpus/README.md view on Meta::CPAN
Valid test case keys include:
* `description`: human-readable test case label.
* `subject`: an (uppercase) big-endian hex representation of a BSON byte
string. Be sure to mangle the case as appropriate in any roundtrip
tests.
* `string`: (optional) a representation of an element in the `extjson`
field that can be checked to verify correct extjson decoding. How to
check is language and bson-type specific.
* `extjson`: a document representing the decoded extended JSON document
equivalent to the subject.
* `decodeOnly` (optional): if true, indicates that the BSON can not
roundtrip; decoding the BSON in 'subject' and re-encoding the result will
not generate identical BSON; otherwise, encode(decode(subject)) should be
the same as the subject.
Decode error cases provide an invalid BSON document or field that
should result in an error. For each case, keys include:
* `description`: human-readable test case label.
devel/typemap.md view on Meta::CPAN
There are three possible types of hooks for serializing and deserializing:
key-specific, type-specific and generic.
Doing key-specific hooks correctly really requires maintaining a deep key
representation, which currently doesn't exist. Precedence vs type-specific
keys is also unclear. Therefore, this is out of scope.
Type-specific hooks are registered based on type: for serializing, the
result of the `ref` call; for deserializing, the BSON type. Generic hooks
always run for every element encoded or decoded (unless a type-specific
hook applies); they are discouraged due to the overhead this causes.
## Serialization hooks
Serialization hooks fire early in the encode process, before dispatching
based on a value's type. The hook receives the key and value (or array
index and value). It must return a new key/value pair if it modifies
either element (it must not modify an array index). It must return an
empty list if it makes no changes. If a type changes and there is a hook
for the new type, the new key/value are re-hooked.
lib/BSON.pm view on Meta::CPAN
#pod =cut
has prefer_numeric => (
is => 'ro',
);
#pod =attr wrap_dbrefs
#pod
#pod If set to true, during decoding, documents with the fields C<'$id'> and
#pod C<'$ref'> (literal dollar signs, not variables) will be wrapped as
#pod L<BSON::DBRef> objects. If false, they are decoded into ordinary hash
#pod references (or ordered hashes, if C<ordered> is true).
#pod
#pod The default is true.
#pod
#pod =cut
has wrap_dbrefs => (
is => 'ro',
);
lib/BSON.pm view on Meta::CPAN
return $bson;
}
#pod =method decode_one
#pod
#pod $doc = $codec->decode_one( $byte_string );
#pod $doc = $codec->decode_one( $byte_string, \%options );
#pod
#pod Takes a byte string with a BSON-encoded document and returns a
#pod hash reference representing the decoded document.
#pod
#pod An optional hash reference of options may be provided. Valid options include:
#pod
#pod =for :list
#pod * dt_type â overrides codec default
#pod * error_callback â overrides codec default
#pod * max_length â overrides codec default
#pod * ordered - overrides codec default
#pod * wrap_dbrefs - overrides codec default
#pod * wrap_numbers - overrides codec default
lib/BSON.pm view on Meta::CPAN
B<IMPORTANT CAVEAT>: the heuristics for determining whether something is a
string or number are less accurate on older Perls. See L<BSON::Types>
for wrapper classes that specify exact serialization types.
The default is false.
=head2 wrap_dbrefs
If set to true, during decoding, documents with the fields C<'$id'> and
C<'$ref'> (literal dollar signs, not variables) will be wrapped as
L<BSON::DBRef> objects. If false, they are decoded into ordinary hash
references (or ordered hashes, if C<ordered> is true).
The default is true.
=head2 wrap_numbers
If set to true, during decoding, numeric values will be wrapped into
BSON type-wrappers: L<BSON::Double>, L<BSON::Int64> or L<BSON::Int32>.
While very slow, this can help ensure fields can round-trip if unmodified.
lib/BSON.pm view on Meta::CPAN
prefer_numeric â overrides codec default
=back
=head2 decode_one
$doc = $codec->decode_one( $byte_string );
$doc = $codec->decode_one( $byte_string, \%options );
Takes a byte string with a BSON-encoded document and returns a
hash reference representing the decoded document.
An optional hash reference of options may be provided. Valid options include:
=over 4
=item *
dt_type â overrides codec default
=item *
t/legacy/10-bson.t view on Meta::CPAN
38, 0, 0, 0,
18, 97, 0, 0, 0, 0, 128, 0, 0, 0, 0,
18, 98, 0, 255, 255, 255, 255, 255, 255, 255, 127,
18, 99, 0, 0, 0, 0, 0, 0, 0, 0, 128,
0
],
'Int64 encode'
);
# is_deeply fails to compare int64 properly
my $decoded = decode($bson);
for my $k ( qw/a b c/ ) {
is( $decoded->{$k}, $h{$k}, "key $k" );
}
};
# Mixed ints
subtest mix_ints => sub {
%h = ( a => Math::BigInt->new('2147483648'), b => 1, c => -20 );
my $bson = encode( \%h );
# is_deeply fails to compare int64 properly
cmp_deeply(
[ unpack "C*", $bson ],
[
30, 0, 0, 0, 18, 97, 0, 0, 0, 0,
128, 0, 0, 0, 0, 16, 98, 0, 1, 0,
0, 0, 16, 99, 0, 236, 255, 255, 255, 0
],
'Mixints encode'
);
# is_deeply fails to compare int64 properly
my $decoded = decode($bson);
for my $k ( qw/a b c/ ) {
is( $decoded->{$k}, $h{$k}, "key $k" );
}
};
subtest boolean => sub {
plan tests => 6;
# Boolean true
%h = ( a => BSON::Bool->true );
my $bson = encode( \%h );
is_deeply(
t/lib/TestUtils.pm view on Meta::CPAN
};
my $json_codec = JSON::PP
->new
->ascii
->allow_bignum
->allow_blessed
->convert_blessed;
sub normalize_json {
my $decoded = $json_codec->decode(shift);
return $json_codec->encode($decoded);
}
sub to_extjson {
my $data = BSON->perl_to_extjson($_[0], { relaxed => $_[1] });
return $json_codec->encode($data);
}
sub to_myjson {
local $ENV{BSON_EXTJSON} = 0;
return $json_codec->encode( shift );
( run in 1.739 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )