MetaDecoder
open class MetaDecoder : Decoder
A Decoder that decodes from a Meta instead from a concrete format.
-
Declaration
Swift
public let userInfo: [CodingUserInfoKey : Any] -
Declaration
Swift
open var codingPath: [CodingKey]
-
A StorageAccessor to this decoder’s private storage
Declaration
Swift
open var storage: CodingStorage
-
Initalizes a new MetaDecoder with the given values.
Declaration
Swift
public init(at codingPath: [CodingKey] = [], with userInfo: [CodingUserInfoKey : Any] = [:], unwrapper: Unwrapper, storage: CodingStorage = LinearCodingStack())Parameters
codingPathThe coding path this decoder will start at.
userInfoadditional information to provide context during decoding.
unwrapperThe
Unwrapperthe decoder will use to unwrap metas. If options contains the.dynamicallyUnwindMetaTreeoption, this unwrapper needs to conform toContainerUnwrapperadditionally. If it does not, this initalizer will crash.storageA empty CodingStorage that should be used to store metas.
-
Unwraps a meta to a real value using
unwrapper.unwrapand callingtype.init(from:)ifunwrapper.unwrapreturned nil.Throws
DecodingError and CodingStorageErrorDeclaration
Swift
open func unwrap<D: Decodable>(_ meta: Meta? = nil, toType type: D.Type, for key: CodingKey? = nil) throws -> DParameters
metathe Meta to unwrap, if you pass nil, the meta at this decoders current coding path will be used.
typeThe type to unwrap to
keyThe key at which meta should be decoded. This decoders coding path is extended with this key.
-
Checks whether the given meta represents a nil meta. Tries to dynamically unwrap meta if specified.
Declaration
Swift
open func representsNil(meta passedMeta: Meta) -> Bool
-
Create a new KeyedDecodingContainer for the given meta, if it is a DecodingKeyedContainerMeta.
If it is not, throw DecodingError.typeMissmatch.
Declaration
Swift
public func container<Key>(keyedBy keyType: Key.Type, for passedMeta: Meta, at codingPath: [CodingKey]) throws -> KeyedDecodingContainer<Key> where Key : CodingKey -
Declaration
Swift
open func decodingContainer<Key>(keyedBy keyType: Key.Type, for keyedMeta: DecodingKeyedContainerMeta, at codingPath: [CodingKey]) throws -> KeyedDecodingContainer<Key> where Key : CodingKey -
Create a new UnkeyedDecodingContainer for the given meta, if it is a DecodingUnkeyedContainerMeta.
If it is not, throw DecodingError.typeMissmatch.
Declaration
Swift
public func unkeyedContainer(for passedMeta: Meta, at codingPath: [CodingKey]) throws -> UnkeyedDecodingContainer -
Declaration
Swift
open func unkeyedDecodingContainer(for unkeyedMeta: DecodingUnkeyedContainerMeta, at codingPath: [CodingKey]) throws -> UnkeyedDecodingContainer -
Create a new SingleValueDecodingContainer for the given meta.
Declaration
Swift
open func singleValueContainer(for meta: Meta, at codingPath: [CodingKey]) throws -> SingleValueDecodingContainer
-
Creates a new decoder that decodes the given meta. This decoder can for example be used as super decoder.
Declaration
Swift
open func decoder(for meta: Meta, at codingPath: [CodingKey]) throws -> Decoder -
Creates a new decoder with the given storage.
This method serves as delegate for decoder(for:, at:)‘s default implementation.
Declaration
Swift
open func decoderImplementation(storage: CodingStorage, at codingPath: [CodingKey]) throws -> Decoder -
Declaration
Swift
func container<Key>(keyedBy keyType: Key.Type) throws -> KeyedDecodingContainer<Key> where Key : CodingKey -
Declaration
Swift
func unkeyedContainer() throws -> UnkeyedDecodingContainer -
Declaration
Swift
func singleValueContainer() throws -> SingleValueDecodingContainer -
Decodes a value of type D from the given meta tree.
Use this method rather than directly calling Decodable.init(from:). init(from:) will not detect types that are directly supported by the unwrapper.
There are some conditions
metaand the metas contained inmeta(refered to as “the meta tree”) must meet:- Any metas that should be seen as nil values by the decoder (for which
decodeNilon e.g.KeyedDecodingContainershould return true) must conform toNilMeta. If you didn’t set the
MetaDecoder.Options.dynamicallyUnwindMetaTreeoption on this decoder, all metas that can be seen as keyed or unkeyed containers must conform toDecodingKeyedContainerMeta/DecodingUnkeyedContainerMeta, othwise these containers can not be detected. Alternatively consider setting.dynamicallyUnwindMetaTreeand implementing the required container unwraping inunwrapof yourUnwrapperimplementation.Throws
Aside from any errors that are thrown of unwrapper.unwrap and anyDecodingErrorthat has been thrown by another entity, this function will throwMetaDecoder.Errors.decodingHasNotSucceededif the decoding could not succeed. In general, this error will never be thrown in code running unter the debug (and not the release) configuration. Instead the call will fail with an assertion failure. Such an error usually indicates an invalid decoder implementation or a missuse of a decoder.
Declaration
Swift
func decode<D>(type: D.Type, from meta: Meta) throws -> D where D : DecodableParameters
typeThe type that should decoded.
metaThe meta tree the decoder should decode from.
- Any metas that should be seen as nil values by the decoder (for which
-
Declaration
Swift
enum Errors : Error
View on GitHub
MetaDecoder Class Reference