Skip to content

DOCSP-44433: Compare BSON::Binary objects #142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions source/data-formats/bson.txt
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,16 @@ specific to the specification:
``BSON::Binary``
~~~~~~~~~~~~~~~~

Use ``BSON::Binary`` objects to store arbitrary binary data. The ``Binary``
objects can be constructed from binary strings as follows:
Use ``BSON::Binary`` objects to store arbitrary binary data. You can construct
``Binary`` objects from binary strings, as shown in the following code:

.. code-block:: ruby

BSON::Binary.new("binary_string")
# => <BSON::Binary:0x47113101192900 type=generic data=0x62696e6172795f73...>

By default, ``Binary`` objects are created with BSON binary subtype 0
(``:generic``). The subtype can be explicitly specified to indicate that
(``:generic``). You can explicitly specify the subtype to indicate that
the bytes encode a particular type of data:

.. code-block:: ruby
Expand All @@ -247,8 +247,8 @@ the bytes encode a particular type of data:
Valid subtypes are ``:generic``, ``:function``, ``:old``, ``:uuid_old``,
``:uuid``, ``:md5`` and ``:user``.

The data and the subtype can be retrieved from ``Binary`` instances using
``data`` and ``type`` attributes, as follows:
You can use the ``data`` and ``type`` attributes to retrieve a
``Binary`` object's data and the subtype, as shown in the following code:

.. code-block:: ruby

Expand All @@ -258,6 +258,10 @@ The data and the subtype can be retrieved from ``Binary`` instances using
binary.type
=> :user

You can compare ``Binary`` objects by using the ``<=>`` operator, which allows
you to sort objects that have the same binary subtype. To compare ``Binary`` objects,
ensure that you install v5.0.2 or later of the BSON library.

.. note::

``BSON::Binary`` objects always store the data in ``BINARY`` encoding,
Expand Down
Loading