BSON-XS

 view release on metacpan or  search on metacpan

bson/bson-decimal128.c  view on Meta::CPAN

bson_decimal128_to_string (const bson_decimal128_t *dec,        /* IN  */
                           char                    *str)        /* OUT */
{
   uint32_t COMBINATION_MASK = 0x1f;   /* Extract least significant 5 bits */
   uint32_t EXPONENT_MASK = 0x3fff;    /* Extract least significant 14 bits */
   uint32_t COMBINATION_INFINITY = 30; /* Value of combination field for Inf */
   uint32_t COMBINATION_NAN = 31;      /* Value of combination field for NaN */
   uint32_t EXPONENT_BIAS = 6176;      /* decimal128 exponent bias */

   char *str_out = str;                /* output pointer in string */
   char significand_str[35];           /* decoded significand digits */


   /* Note: bits in this routine are referred to starting at 0, */
   /* from the sign bit, towards the coefficient. */
   uint32_t high;                    /* bits 0 - 31 */
   uint32_t midh;                    /* bits 32 - 63 */
   uint32_t midl;                    /* bits 64 - 95 */
   uint32_t low;                     /* bits 96 - 127 */
   uint32_t combination;             /* bits 1 - 5 */
   uint32_t biased_exponent;         /* decoded biased exponent (14 bits) */
   uint32_t significand_digits = 0;  /* the number of significand digits */
   uint32_t significand[36] = { 0 }; /* the base-10 digits in the significand */
   uint32_t *significand_read = significand; /* read pointer into significand */
   int32_t exponent;                 /* unbiased exponent */
   int32_t scientific_exponent;      /* the exponent if scientific notation is
                                      * used */
   bool is_zero = false;             /* true if the number is zero */

   uint8_t significand_msb;          /* the most signifcant significand bits (50-46) */
   _bson_uint128_t significand128;   /* temporary storage for significand decoding */

bson/bson-iter.c  view on Meta::CPAN


/*
 *--------------------------------------------------------------------------
 *
 * _bson_iter_next_internal --
 *
 *       Internal function to advance @iter to the next field and retrieve
 *       the key and BSON type before error-checking.
 *
 * Return:
 *       true if an element was decoded, else false.
 *
 * Side effects:
 *       @key and @bson_type are set.
 *
 *       If the return value is false:
 *        - @iter is invalidated: @iter->raw is NULLed
 *        - @unsupported is set to true if the bson type is unsupported
 *        - otherwise if the BSON is corrupt, @iter->err_off is nonzero
 *        - otherwise @bson_type is set to BSON_TYPE_EOD
 *

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.

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.386 second using v1.01-cache-2.11-cpan-26ccb49234f )