Document
The Document
type models the “universal” BSON DSL.
@frozen struct Document
It is expected that more-specialized BSON DSLs will wrap an instance of Document
.
The Document
type models the “universal” BSON DSL.
@frozen struct Document
It is expected that more-specialized BSON DSLs will wrap an instance of Document
.
import BSONABI
Models the BSON type system and the binary interface of the BSON serialization format.
@frozen enum BSON
The namespace for all BSON types.
@frozen struct List
protocol BufferFrame : BSON.BufferFrameType
A type that augments a BufferFrameType
conformance with a BSON metatype value. This is a derived protocol because it is sometimes useful to repurpose the BSON frame parsing machinery for additional (fictional) frame types that never appear in BSON data.
protocol BufferFrameType
A type that specifies the layout of a variable-length BSON view. Parsers use conforming types to decide how to interpret BSON length headers read from input data.
protocol BufferTraversable
A framed type that BSON parsers can traverse in constant time.
protocol Decoder
protocol Encoder<Frame>
protocol OutputStream
@frozen enum AnyType
A BSON metatype. The raw value of this enumeration is the type code of the associated case in BSON’s ABI.
@frozen enum AnyValue
Any BSON value.
@frozen struct BinaryBuffer<Element> where Element : BitwiseCopyable
A BinaryBuffer
is a typed view of an ArraySlice
as a densely-packed buffer of trivial Element
s. It’s a good idea to use something unpretentious like a tuple of fixed-width integers for the Element
type, to avoid unexpected padding behavior.
@frozen enum BinaryFrame
Specifies the interpretation of a length header attached to a binary
array.
@frozen struct BinarySubtype
A BSON binary metatype. This type’s public API performs canonicalization and therefore instances of this type are safe to compare.
@frozen struct BinarySubtypeError
The subtype byte of a binary array matched a reserved bit pattern.
@frozen struct BinaryView<Bytes> where Bytes : RandomAccessCollection, Bytes.Element == UInt8
A BSON binary array.
@frozen struct BinaryViewError
A binary view was sliced from a malformed storage buffer.
@frozen struct BooleanSubtypeError
A byte encoding a boolean value was not 0
or 1
.
@frozen struct Decimal128
An opaque IEEE 754-2008 decimal.
@frozen enum DocumentFrame
Specifies the interpretation of a length header attached to a document
, or a list
document.
@frozen struct FieldEncoder
A type that can serialize any BSON container element.
@frozen struct HeaderError<Frame> where Frame : BSON.BufferFrameType
@frozen struct Identifier
A MongoDB object reference. This type models a MongoDB ObjectId
.
@frozen struct Input
A type for managing BSON parsing state. Most users of this module should not need to interact with it directly.
@frozen struct InputError
A parser did not receive the expected amount of input.
@frozen enum IntegerOverflowError<Overflowed> where Overflowed : FixedWidthInteger
An overflow occurred while casting an integer value to a desired type.
@frozen struct Key
A BSON field key. This type wraps a rawValue
that is guaranteed to never contain null bytes. (Null bytes in a BSON field key can be exploited to perform SQL injection.)
@frozen struct Max
The MongoDB max-key. This type has a single state, and is isomorphic to Void
. It is mainly used by the decoding and encoding layers as an API landmark.
@frozen struct Min
The MongoDB min-key. This type has a single state, and is isomorphic to Void
. It is mainly used by the decoding and encoding layers as an API landmark.
@frozen struct Null
@frozen struct Output
@frozen struct Regex
A MongoDB regex.
@frozen struct Shape
An efficient interface for checking the shape of a list or binary array at run time.
@frozen struct ShapeError
A list had an invalid number of elements or a binary array had an invalid number of bytes.
@frozen struct Timestamp
@frozen struct TypeError
A variant code did not encode a valid BSON type.
@frozen struct TypecastError<Value>
A decoder failed to cast a variant to an expected value type.
@frozen enum UTF8Frame
Specifies the interpretation of a length header attached to UTF-8 string
.
@frozen struct UTF8View<Bytes> where Bytes : BidirectionalCollection, Bytes.Element == UInt8
A BSON UTF-8 string. This string is allowed to contain null bytes.
typealias BinaryArray = BinaryBuffer
typealias Millisecond = UnixMillisecond
protocol Copyable
A type whose values can be implicitly or explicitly copied.
protocol Equatable
A type that can be compared for value equality.
protocol Escapable
protocol ExpressibleByDictionaryLiteral
A type that can be initialized using a dictionary literal.
protocol Sendable
init()
Creates an empty document.
init(bytes: ArraySlice<UInt8>)
Stores the argument in bytes
unchanged.
init(dictionaryLiteral: (BSON.Key, BSON.AnyValue)...)
init(fields: some Collection<(key: BSON.Key, value: BSON.AnyValue)>)
Creates a document containing the given fields, making two passes over the list of fields in order to encode the output without reallocations. The order of the fields will be preserved.
init(key: BSON.Key, value: BSON.AnyValue)
Creates a document containing a single key-value pair.
init(list: BSON.List)
Rebinds the backing storage of this list to a BSON.Document
. This will cause the list to be interpreted as a document with keys numbered from 0 in base-10.
init(slicing bytes: ArraySlice<UInt8>)
Stores the argument in bytes
unchanged. Equivalent to init(bytes:)
.
var bytes: ArraySlice<UInt8> { get }
The raw data backing this document. This slice does not include the trailing null byte that typically appears after its inline field list.
var header: Int32 { get }
The length that would be encoded in this document’s prefixed header. Equal to size
.
var isEmpty: Bool { get }
Indicates if this document contains no fields.
var output: BSON.Output
var size: Int { get }
The size of this document when encoded with its header and trailing null byte. This is the same as the length encoded in the header itself.
static func == (a: `Self`, b: `Self`) -> Bool
Performs an exact byte-wise comparison on two documents. Does not parse or validate the operands. Documents with the same fields in different orders will compare unequal!
mutating func append(contentsOf other: `Self`)
func parse<CodingKey, T>(_ transform: (_ key: CodingKey, _ value: BSON.AnyValue) throws -> T) throws -> [T] where CodingKey : RawRepresentable, CodingKey.RawValue == String
Splits this document’s inline key-value pairs into an array.
func parse<CodingKey>(to decode: (CodingKey, BSON.AnyValue) throws -> ()) throws where CodingKey : RawRepresentable, CodingKey.RawValue == String
Parses this document into key-value pairs in order, yielding each key-value pair to the provided closure.
typealias Frame = BSON.DocumentFrame
init(_ bson: `Self`)
init(bson: `Self`)
static func != (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether two values are not equal.
import BSONDecoding
protocol BSONDecodable
A type that can be decoded from a BSON variant value backed by some type of storage not particular to the decoded type.
init(bson: BSON.AnyValue) throws
func parse(to decode: (_ field: BSON.FieldDecoder<BSON.Key>) throws -> ()) throws
Decorates the BSON.AnyValue
-yielding overload of this method with one that yields the key-value pairs as fields.
import BSONEncoding
protocol BSONEncodable
A type that can be encoded to a BSON variant value.
init<CodingKey>(_: CodingKey.Type = CodingKey.self, with encode: (inout BSON.DocumentEncoder<CodingKey>) throws -> ()) rethrows where CodingKey : RawRepresentable, CodingKey.RawValue == String
init<Encodable>(encoding fields: some Sequence<(key: BSON.Key, value: Encodable)>) where Encodable : BSONEncodable
init(encoding encodable: some BSONDocumentEncodable)
subscript<CodingKey>(_: CodingKey.Type) -> BSON.DocumentEncoder<CodingKey> where CodingKey : RawRepresentable, CodingKey.RawValue == String { mutating get set }
subscript(with key: some RawRepresentable<String>) -> BSON.FieldEncoder { get set }
func encode(to field: inout BSON.FieldEncoder)
import BSONReflection
protocol CustomStringConvertible
A type with a customized textual representation.
var description: String { get }
static func ~~ (lhs: `Self`, rhs: `Self`) -> Bool
Performs a type-aware equivalence comparison by parsing each operand and recursively comparing the elements. Returns false if either operand fails to parse.
func canonicalized() throws -> BSON.Document
Recursively parses and re-encodes this document, and any embedded documents (and list-documents) in its elements. The keys will not be changed or re-ordered.