BSON::Bytes(3pm)

πŸ“¦
version 1.12.2 Β· 5 versions
, in debian bookworm, ubuntu jammy, ubuntu noble

πŸ’– BSON::Bytes πŸ’–

okay bestie, welcome to BSON::Bytes β€” it's a BSON type wrapper for binary byte strings, and it's from the User Contributed Perl Documentation section of the manual (so yeah, BSON::Bytes(3pm), we know her πŸ’…).


✨ VERSION ✨

version v1.12.2 β€” this is the one, no cap πŸŽ€


✨ SYNOPSIS ✨

like, here's the whole vibe in four lines:

use BSON::Types ':all';

$bytes = bson_bytes( $bytestring );
$bytes = bson_bytes( $bytestring, $subtype );

that's it. that's the whole thing. she's efficient πŸ¦‹


✨ DESCRIPTION ✨

so basically? this module is a BSON type wrapper for binary data β€” and the binary data in question is represented as a string of bytes. that's the whole job. iconic, honestly. πŸ‘‘


✨ ATTRIBUTES ✨

🌸 data

a scalar, and you gotta interpret it as bytes. (like, if you've got "character" data, you should encode it to bytes first, bestie β€” don't just yeet your text in there raw.) it defaults to the empty string. 🫢

🌸 subtype

a numeric BSON subtype, and it's gotta live between 0 and 255. defaults to 0, and honestly you generally should not be messing with it. oh and also β€” subtypes 128 to 255 are the "user-defined" ones. iykyk ✨


✨ METHODS ✨

πŸ¦‹ TO_JSON

returns a Base64 encoded string that's equivalent to the data attribute. slay.

BUT β€” and this is the plot twist β€” if the BSON_EXTJSON option is true, then instead it'll be compatible with MongoDB's extended JSON format (link: https://github.com/mongodb/specifications/blob/master/source/extended-json.rst), which represents it as a document like this:

{"$binary" : { "base64": "<base64 data>", "subType" : "<type>"} }

see how it's giving structured? πŸ’…


✨ OVERLOADING ✨

the stringification operator ("") is overloaded to return the binary data, and fallback overloading is enabled. periodt. πŸ’–


✨ AUTHORS ✨

these are the legends who made it happen 🫢

  • David Golden <david@mongodb.com>
  • Stefan G. <minimalist@lavabit.com>

This software is Copyright (c) 2020 by Stefan G. and MongoDB, Inc.

This is free software, licensed under:

The Apache License, Version 2.0, January 2004

so yeah, go wild, it's free software 🌈


okay that's the whole page, bestie!! this was rendered by perl v5.30.3 back on 2020-08-14, and that's your official BSON::Bytes(3pm) sign-off β€” love u, go encode some bytes, mwah πŸ’œπŸ§šβ€β™€οΈ

πŸ“¦ where this page comes from