Input
A type for managing BSON parsing state. Most users of this module should not need to interact with it directly.
@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 Input
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.
protocol Decoder
@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.
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 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 struct Document
The Document
type models the “universal” BSON DSL.
@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 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 List
@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 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 Sendable
init(_ source: ArraySlice<UInt8>)
Creates a parsing input view over the given source
data, and initializes its index
to the start index of the source
.
var index: Int
var remaining: ArraySlice<UInt8> { get }
Returns a slice of the input from the current index
to the end of the input. Accessing this property does not affect the current index
.
let source: ArraySlice<UInt8>
func expected(_ expectation: BSON.InputError.Expectation) -> BSON.InputError
Creates an InputError
with appropriate context for the specified expectation.
func finish() throws
Asserts that there is no input remaining.
mutating func next() -> UInt8?
Consumes and returns a single byte from this parsing input.
mutating func parse<Frame>(_: Frame.Type) throws -> ArraySlice<UInt8> where Frame : BSON.BufferFrameType
mutating func parse(as _: UnixMillisecond.Type = UnixMillisecond.self) throws -> UnixMillisecond
mutating func parse(as _: BSON.Decimal128.Type = BSON.Decimal128.self) throws -> BSON.Decimal128
mutating func parse(as _: BSON.Identifier.Type = BSON.Identifier.self) throws -> BSON.Identifier
Parses a MongoDB object identifier.
mutating func parse(as _: BSON.Regex.Type = BSON.Regex.self) throws -> BSON.Regex
mutating func parse(as _: String.Type = String.self) throws -> String
Parses a null-terminated string.
mutating func parse(as _: Bool.Type = Bool.self) throws -> Bool
Parses a boolean.
mutating func parse<View>(as _: View.Type = View.self) throws -> View where View : BSON.BufferTraversable
Parses a traversable BSON element. The output is typically opaque, which allows decoders to skip over regions of a BSON document.
mutating func parse<LittleEndian>(as _: LittleEndian.Type = LittleEndian.self) throws -> LittleEndian where LittleEndian : FixedWidthInteger
Parses a little-endian integer.
@discardableResult mutating func parse(through byte: UInt8) throws -> Range<Int>
Advances the current index until encountering the specified byte
. After this method returns, index
points to the byte after the matched byte.
mutating func parse(variant: BSON.AnyType) throws -> BSON.AnyValue
Parses a variant BSON value, assuming it is of the specified variant
type.