BSONEncoder
public class BSONEncoder
BSONEncoder
facilitates the encoding of Encodable
values into BSON.
-
Enum representing the various strategies for encoding
Date
s.As per the BSON specification, the default strategy is to encode
Date
s as BSON datetime objects.See also
bsonspec.orgDeclaration
Swift
public enum DateEncodingStrategy
-
Enum representing the various strategies for encoding
UUID
s.As per the BSON specification, the default strategy is to encode
UUID
s as BSON binary types with the UUID subtype.See also
bsonspec.orgDeclaration
Swift
public enum UUIDEncodingStrategy
-
Enum representing the various strategies for encoding
Data
s.As per the BSON specification, the default strategy is to encode
Data
s as BSON binary types with the generic binary subtype.See also
bsonspec.orgDeclaration
Swift
public enum DataEncodingStrategy
-
The strategy to use for encoding
Date
s with this instance.Declaration
Swift
public var dateEncodingStrategy: DateEncodingStrategy
-
The strategy to use for encoding
UUID
s with this instance.Declaration
Swift
public var uuidEncodingStrategy: UUIDEncodingStrategy
-
The strategy to use for encoding
Data
s with this instance.Declaration
Swift
public var dataEncodingStrategy: DataEncodingStrategy
-
Contextual user-provided information for use during encoding.
Declaration
Swift
public var userInfo: [CodingUserInfoKey : Any]
-
Initializes
self
.Declaration
Swift
public init(options: CodingStrategyProvider? = nil)
-
Encodes the given top-level value and returns its BSON representation.
Throws
EncodingError
if any value throws an error during encoding.Declaration
Swift
public func encode<T>(_ value: T) throws -> BSONDocument where T : Encodable
Parameters
value
The value to encode.
Return Value
A new
BSONDocument
containing the encoded BSON data. -
Encodes the given top-level optional value and returns its BSON representation. Returns nil if the value is nil or if it contains no data.
Throws
EncodingError
if any value throws an error during encoding.Declaration
Swift
public func encode<T>(_ value: T?) throws -> BSONDocument? where T : Encodable
Parameters
value
The value to encode.
Return Value
A new
BSONDocument
containing the encoded BSON data, or nil if there is no data to encode. -
Encodes the given array of top-level values and returns an array of their BSON representations.
Throws
EncodingError
if any value throws an error during encoding.Declaration
Swift
public func encode<T>(_ values: [T]) throws -> [BSONDocument] where T : Encodable
Parameters
values
The values to encode.
Return Value
A new
[Document]
containing the encoded BSON data. -
Encodes the given array of top-level optional values and returns an array of their BSON representations. Any value that is nil or contains no data will be mapped to nil.
Throws
EncodingError
if any value throws an error during encoding.Declaration
Swift
public func encode<T>(_ values: [T?]) throws -> [BSONDocument?] where T : Encodable
Parameters
values
The values to encode.
Return Value
A new
[Document?]
containing the encoded BSON data. Any value that is nil or contains no data will be mapped to nil.