DataCodingStrategy
public enum DataCodingStrategy : RawRepresentable
Enum representing the various encoding/decoding strategy pairs for Date
s.
Set these on a MongoClient
, MongoDatabase
, or MongoCollection
so that the strategies will be applied when
converting Data
s between their BSON representations and their representations in (non BSONDocument
) Codable
types.
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.org-
Declaration
Swift
public typealias RawValue = (encoding: BSONEncoder.DataEncodingStrategy, decoding: BSONDecoder.DataDecodingStrategy)
-
Encode/decode the
Data
by deferring to its default encoding implementations.Note: The default encoding implementation attempts to encode the
Data
as a[UInt8]
, but because BSON does not support integer types besidesInt32
orInt64
, it actually gets encoded to BSON as an[Int32]
. This results in a space inefficient storage of theData
(using 4 bytes of BSON storage per byte of data).Declaration
Swift
case deferredToData
-
Encode/decode the
Data
to/from a BSON binary type (default).Declaration
Swift
case binary
-
Encode the
Data
to/from a base64 encoded string.Declaration
Swift
case base64
-
Encode the
Data
by using the givenencodeFunc
. Decode theData
by using the givendecodeFunc
. IfencodeFunc
does not encode a value, an empty document will be encoded in its place.Declaration
Swift
case custom(encodeFunc: (Data, Encoder) throws -> Void, decodeFunc: (Decoder) throws -> Data)
-
Declaration
Swift
public init?(rawValue: RawValue)
-
Declaration
Swift
public var rawValue: RawValue { get }