BSON Values
Introduction
BsonValue represents BSON values and reads or writes complete document
frames.
For usage, type mapping, and input limits, see Reading and Writing BSON.
Truncated input is rejected as ParseError by the throwing decoder, or as an empty optional by the tolerant decoder.
Internal bounds errors and resource failures are not converted into malformed-input errors.
Text arguments accept String, StringEditor, and Core string literals directly, including when passed to
set() or append().
Stored text retains its value if the original editor is changed later.
Interface
-
struct BsonBinary
BSON binary payload and its subtype.
-
typedef text::StringMap<BsonValue> erbsland::data::bson::BsonDocument
A string-keyed BSON document.
-
class BsonFormatOptions
Extension point for BSON serialization settings.
-
class BsonOpaqueValue
Known BSON wire value preserved without executing or interpreting it.
-
class BsonParseOptions
Safety limits for parsing BSON.
Public Functions
-
inline constexpr BsonParseOptions &setMaximumInputLength(unit::ByteCount value) noexcept
Set the input byte limit.
-
inline constexpr BsonParseOptions &setMaximumNesting(unit::ItemCount value) noexcept
Set the nesting limit.
-
inline constexpr BsonParseOptions &setMaximumValueCount(unit::ItemCount value) noexcept
Set the value count limit.
-
inline constexpr unit::ByteCount maximumStringLength() const noexcept
Get the maximum byte length of one string or key.
-
inline constexpr BsonParseOptions &setMaximumStringLength(unit::ByteCount value) noexcept
Set the maximum byte length of one string or key.
-
inline constexpr BsonParseOptions &setMaximumInputLength(unit::ByteCount value) noexcept
-
enum class erbsland::data::bson::BsonType : uint8_t
Semantic types supported by a BSON value.
Values:
-
enumerator Null
Null.
-
enumerator Bool
Boolean.
-
enumerator Int32
Signed 32-bit integer.
-
enumerator Int64
Signed 64-bit integer.
-
enumerator Double
64-bit floating point.
-
enumerator Text
UTF-8 string.
-
enumerator Binary
Binary payload and subtype.
-
enumerator DateTime
UTC millisecond date/time.
-
enumerator Array
Ordered array.
-
enumerator Document
Named document fields.
-
enumerator Opaque
Known BSON type retained without interpretation.
-
enumerator Null
-
class BsonValue
A copy-on-write BSON value tree.
See: BSON Values
Public Functions
-
BsonValue(bool value)
Create a BSON Boolean value.
- Parameters:
value – The Boolean to store.
-
BsonValue(int32_t value)
Create a BSON signed 32-bit integer value.
- Parameters:
value – The signed 32-bit integer to store.
-
BsonValue(int64_t value)
Create a BSON signed 64-bit integer value.
- Parameters:
value – The signed 64-bit integer to store.
-
BsonValue(int8_t value)
Create a BSON signed 8-bit integer value.
- Parameters:
value – The signed 8-bit integer to store.
-
BsonValue(uint8_t value)
Create a BSON unsigned 8-bit integer value.
- Parameters:
value – The unsigned 8-bit integer to store.
-
BsonValue(int16_t value)
Create a BSON signed 16-bit integer value.
- Parameters:
value – The signed 16-bit integer to store.
-
BsonValue(uint16_t value)
Create a BSON unsigned 16-bit integer value.
- Parameters:
value – The unsigned 16-bit integer to store.
-
BsonValue(uint32_t value)
Create a BSON unsigned 32-bit integer value.
- Parameters:
value – The unsigned 32-bit integer to store.
-
BsonValue(uint64_t value)
Create a BSON unsigned 64-bit integer value.
- Parameters:
value – The unsigned 64-bit integer to store. Must fit in the BSON signed 64-bit range.
-
BsonValue(double value)
Create a BSON double-precision number value.
- Parameters:
value – The double-precision number to store.
-
BsonValue(text::String value)
Create a BSON text string value.
- Parameters:
value – The text string to store.
-
template<typename tText>
inline BsonValue(tText &&value) Create a text value from an implicitly convertible string, editor, or literal.
- Parameters:
value – The text to store.
-
BsonValue(BsonBinary value)
Create a BSON binary value with subtype value.
- Parameters:
value – The binary value with subtype to store.
-
BsonValue(mem::ByteBlock value)
Create a BSON binary byte string value.
- Parameters:
value – The binary byte string to store.
-
BsonValue(time::Timestamp value)
Create a BSON UTC date/time value.
- Parameters:
value – The UTC date/time to store.
-
BsonValue(BsonDocument value)
Create a BSON document value.
- Parameters:
value – The document to store.
-
BsonValue(BsonOpaqueValue value)
Create a BSON opaque wire value value.
- Parameters:
value – The opaque wire value to store.
-
BsonValue getOrThrow(unit::ItemIndex index) const
Get a child or throw.
- Throws:
err::OutOfRangeError – If the index does not identify an array element.
-
BsonValue getOrThrow(const text::String &key) const
Get a child or throw.
- Throws:
err::NotFoundError – If the requested key is absent.
-
std::optional<bool> getBool() const noexcept
Get a Boolean value.
-
std::optional<int64_t> getInteger() const noexcept
Get an exact signed integer across both BSON integer widths.
-
std::optional<double> getDouble() const noexcept
Get a floating-point value.
-
std::optional<BsonBinary> getBinary() const noexcept
Get a binary value and its subtype.
-
std::optional<BsonDocument> getDocument() const noexcept
Get a copy of a document.
-
std::optional<BsonOpaqueValue> getOpaque() const noexcept
Get an opaque value.
-
mem::ByteBlock toByteBlock(BsonFormatOptions options = {}) const
Serialize a document root to BSON.
This value must be a document root, and every contained value must be encodable as BSON.
Public Static Functions
-
static auto fromByteBlock(const mem::ByteBlock &bytes, BsonParseOptions options = {}) noexcept -> std::optional<BsonValue>
Parse one complete BSON document, returning no value on failure.
-
static auto fromByteBlockOrThrow(const mem::ByteBlock &bytes, BsonParseOptions options = {}) -> BsonValue
Parse one complete BSON document.
- Throws:
err::ParseError – For malformed or unsupported wire data.
-
BsonValue(bool value)