Protocols
The following protocols are available globally.
-
CodingStorage is the central storing unit used by
MetaEncoder
as well asMetaDecoder
.CodingStorages store metas at coding paths (arrays of coding keys). Note that
[]
is also a valid path.The way how it stores them is implementation dependant and is correlated with the general abilities MetaSerialization can supply.
In general, a single MetaEncoder or MetaDecoder will store and remove metas in a strictly linear manner. This means that this workflow is followed:
store -> this workflow nested -> this workflow nested -> … -> this workflow nested -> remove
See moreDeclaration
Swift
public protocol CodingStorage
-
The core interface to specify MetaDecoder’s decoding. Implement this protocol to unwrap “primities” (these are usually the types you can represent directly in your serialization format).
A MetaDecoder will call
unwrap
for each meta in the meta tree before decoding takes place for it. There are actually two situations in which this happens. A MetaDecoder asks it’s unwrapper to unwrap a meta to a concrete type (like String, Int, etc.). It does so by callingunwrap
with a concrete type conforming toDecodable
.If you return nil in this method, the MetaDecoder will call
init(from:)` on the passed type.However, MetaDecoder will also try to unwrap metas to
NilMeta
,DecodingKeyedContainerMeta
andDecodingUnkeyedContainerMeta
. These options enables you to partially postpone the creation of the meta tree until the actual containers are known.Specifically, if keyed or unkeyed containers are requested for a meta from a MetaDecoder, before this meta is interpreted as keyed or unkeyed container and it is expected that it conforms to
DecodingKeyedContainerMeta
respectivelyDecodingUnkeyedContainerMeta
, the decoder callsunwrap
, with eigtherDecodingKeyedContainerMeta
orDecodingUnkeyedContainerMeta
for type. Ifunwrap
returns nil, the process continues with the original meta.With this, you may dynamically extend your meta tree. You don’t need to know which meta will be a keyed or unkeyed container before MetaDecoder does it’s work and don’t need meta implementations to conform to
Decoding(Un)KeyedContainerMeta
orNilMeta
if they could be seen as such containers or nil.For these three
See moreunwrap
variants (wheretype = NilMeta.Protocol
,type = DecodingKeyedContainerMeta.Protocol
ortype = DecodingUnkeyedContainerMeta.Protocol
), there are default implementations provided, that always return nil. If you don’t override these methods, a meta tree is expected to be “static”, which means that all container types and nil values need to be known beforedecode
on a MetaDecoder is called.Declaration
Swift
public protocol Unwrapper
-
The core interface to specify MetaEncoder’s encoding. Implement this protocol to set encoding “primities” (these are usually the types you can represent directly in your serialization format) and container implementations.
See moreDeclaration
Swift
public protocol MetaSupplier
-
References a value inside another container meta.
See moreDeclaration
Swift
public protocol ContainerElementReference
-
A protocol for encoded data that will only be written.
Please refer to the documentation of Representation for more information about usage.
However, this protocol gives you also more control about the encoding process, because you will have to instantiate a new MetaEncoder, that you may pack with more information, than TranslatingCoder can handle. For example you may provide a userInfo dictionary or an initial codingPath.
See moreDeclaration
Swift
public protocol EncodingRepresentation
-
A protocol for encoded data that will only be read.
Please refer to the documentation of Representation for more information about usage.
However, this protocol gives you also more control about the decoding process, because you will have to instantiate a new MetaDecoder, that you may pack with more information, than TranslatingCoder can handle. For example you may provide a userInfo dictionary or an initial codingPath.
See moreDeclaration
Swift
public protocol DecodingRepresentation
-
This protocol provides a blueprint for an intermediate encoder, that does simply delegate the task of encoding to a
See moreEncoder
.Declaration
Swift
public protocol IntermediateEncoder
-
This protocol provides a blueprint for an intermediate decoder, that does simply delegate the task of decoding to a Decoder.
See moreDeclaration
Swift
public protocol IntermediateDecoder
-
A container wrapping a certain value. This container is used at the meta or in between stage of encoding and decoding that MetaSerialization performs.
Declaration
Swift
public protocol Meta
-
Declaration
Swift
public protocol UnkeyedContainerMeta : DecodingUnkeyedContainerMeta, EncodingUnkeyedContainerMeta
-
Implement this protocol if a type is supported directly by the Translator.
MetaSerialization will throw an error, if a unwrapper does not support the implementing type directly.
See moreDeclaration
Swift
public protocol DirectlyDecodable : Decodable
-
Implement this protocol if a type is supported directly by the Translator.
MetaSerialization will throw an error, if a translator does not support your type directly.
See moreDeclaration
Swift
public protocol DirectlyEncodable : Encodable