BSON_VECTOR_PACKED_BIT_VIEW_T(3)

πŸ“¦
version 2.5.6 Β· 3 versions
, in epel 10

πŸ’… NAME πŸ’…

bson_vector_packed_bit_view_t β€” ok so bestie, this is a reference to mutable, non-owned BSON Binary data that's holding a valid Vector of packed_bit element type ✨ (and yeah, this whole page lives in the libbson manual, mwah πŸ’–)


✨ SYNOPSIS ✨

#include <bson/bson.h>

typedef struct bson_vector_packed_bit_view_t {
   /*< private >*/
} bson_vector_packed_bit_view_t;

πŸ¦‹ DESCRIPTION πŸ¦‹

So bson_vector_packed_bit_view_t is this struct that acts as an opaque reference to a block of memory β€” and that memory has already been validated as a packed_bit vector, which is honestly iconic of it πŸ‘‘

It's meant to be passed by value, and you can literally just discard it whenever you want, no strings attached 🫢. The contents of the struct? Consider those private, bestie. Don't go poking around in there.

🚨 Okay this part is important, so listen: the bson_t MUST be valid for the entire lifetime of the view. And it is an error to modify that bson_t while you're using the view. Like, do not do that. Fr fr. 😭

🌸 EXAMPLE 🌸

// Fill a new vector with individual boolean elements
{
    static const bool bool_values[] = {true, false, true, true, false};
    const size_t bool_values_count = sizeof bool_values / sizeof bool_values[0];

    bson_vector_packed_bit_view_t view;
    BSON_ASSERT (BSON_APPEND_VECTOR_PACKED_BIT_UNINIT (&doc, "from_bool", bool_values_count, &view));
    BSON_ASSERT (bson_vector_packed_bit_view_pack_bool (view, bool_values, bool_values_count, 0));
}

// Fill another new vector with packed bytes
{
    static const uint8_t packed_bytes[] = {0xb0};
    const size_t unused_bits_count = 3;
    const size_t packed_values_count = sizeof packed_bytes * 8 - unused_bits_count;

    bson_vector_packed_bit_view_t view;
    BSON_ASSERT (BSON_APPEND_VECTOR_PACKED_BIT_UNINIT (&doc, "from_packed", packed_values_count, &view));
    BSON_ASSERT (bson_vector_packed_bit_view_write_packed (view, packed_bytes, sizeof packed_bytes, 0));
}

// Compare both vectors. They match exactly.
{
    bson_iter_t from_bool_iter, from_packed_iter;
    BSON_ASSERT (bson_iter_init_find (&from_bool_iter, &doc, "from_bool"));
    BSON_ASSERT (bson_iter_init_find (&from_packed_iter, &doc, "from_packed"));
    BSON_ASSERT (bson_iter_binary_equal (&from_bool_iter, &from_packed_iter));
}

Like, the way both of those end up matching exactly? That's the whole slay of it πŸ’…βœ¨


πŸ‘€ SEE ALSO: πŸ‘€

  • bson_append_vector_packed_bit_uninit()
  • bson_vector_packed_bit_const_view_t

🫢 AUTHOR 🫢

MongoDB, Inc


2009-present, MongoDB, Inc.


✨ that's the whole page bestie, version 2.5.6, dated Oct 09, 2026 β€” go forth and pack those bits, ily, bye πŸ’–πŸ¦‹πŸŒ·

πŸ“¦ where this page comes from