serialize(type:)
BSON.Output.swift:59mutating func serialize(type: BSON.AnyType)
mutating func serialize(type: BSON.AnyType)
import BSONABI
Models the BSON type system and the binary interface of the BSON serialization format.
@frozen struct Output
@frozen enum BSON
The namespace for all BSON types.
@frozen enum AnyType
A BSON metatype. The raw value of this enumeration is the type code of the associated case in BSON’s ABI.
init(capacity: Int)
Create an empty output, reserving enough space for the specified number of bytes in the destination buffer.
init(preallocated destination: ArraySlice<UInt8>)
Create an output with a pre-allocated destination buffer. The buffer does not need to be empty, and existing data will not be cleared.
var destination: ArraySlice<UInt8>
subscript<Encoder>(as _: Encoder.Type) -> Encoder where Encoder : BSON.Encoder { mutating get set }
Temporarily rebinds this output’s storage buffer to an encoder of the specified type. This function does not add any headers or trailers; to emit a complete BSON frame, mutate through subscript(as:in:)
.
subscript<Encoder>(as _: Encoder.Type, in frame: BSON.DocumentFrame.Type) -> Encoder where Encoder : BSON.Encoder { mutating get set }
Temporarily rebinds this output’s storage buffer to an encoder of the specified type, bracketing it with the appropriate headers or trailers.
subscript(with key: BSON.Key) -> BSON.FieldEncoder { get set }
Temporarily rebinds this output’s storage buffer to a field encoder. Field encoding is always lazy, so the getter has no effects.
mutating func append(_ byte: UInt8)
Appends a single byte to the output destination.
mutating func append(_ bytes: some Sequence<UInt8>)
Appends a sequence of bytes to the output destination.
mutating func reserve(another bytes: Int)
Reserves another bytes
worth of capacity in the output destination, in addition to the bytes already present.
mutating func serialize(fields: some Sequence<(key: BSON.Key, value: BSON.AnyValue)>)
mutating func serialize(id: BSON.Identifier)
mutating func serialize(key: BSON.Key, value: BSON.AnyValue)
Serializes the raw type code of the given variant value, followed by the field key (with a trailing null byte), followed by the variant value itself.
mutating func serialize(variant: BSON.AnyValue)
Serializes the given variant value, without encoding its type.