BSONEncoder

public class BSONEncoder

BSONEncoder facilitates the encoding of Encodable values into BSON.

  • Enum representing the various strategies for encoding Dates.

    As per the BSON specification, the default strategy is to encode Dates as BSON datetime objects.

    See also

    bsonspec.org
    See more

    Declaration

    Swift

    public enum DateEncodingStrategy
  • Enum representing the various strategies for encoding UUIDs.

    As per the BSON specification, the default strategy is to encode UUIDs as BSON binary types with the UUID subtype.

    See also

    bsonspec.org
    See more

    Declaration

    Swift

    public enum UUIDEncodingStrategy
  • Enum representing the various strategies for encoding Datas.

    As per the BSON specification, the default strategy is to encode Datas as BSON binary types with the generic binary subtype.

    See also

    bsonspec.org
    See more

    Declaration

    Swift

    public enum DataEncodingStrategy
  • The strategy to use for encoding Dates with this instance.

    Declaration

    Swift

    public var dateEncodingStrategy: DateEncodingStrategy
  • The strategy to use for encoding UUIDs with this instance.

    Declaration

    Swift

    public var uuidEncodingStrategy: UUIDEncodingStrategy
  • The strategy to use for encoding Datas 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.