BSON_VECTOR_PACKED_BIT_VIEW_T(3)
π 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: thebson_tMUST be valid for the entire lifetime of the view. And it is an error to modify thatbson_twhile 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
π COPYRIGHT π
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
- epel 10: libbson-devel 2.5.6-1.el10_3 Β· Apache-2.0 AND ISC AND MIT AND Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms