Protocols

The following protocols are available globally.

  • CodingStorage is the central storing unit used by MetaEncoder as well as MetaDecoder.

    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 more

    Declaration

    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 calling unwrap with a concrete type conforming to Decodable. If you return nil in this method, the MetaDecoder will callinit(from:)` on the passed type.

    However, MetaDecoder will also try to unwrap metas to NilMeta, DecodingKeyedContainerMeta and DecodingUnkeyedContainerMeta. 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 respectively DecodingUnkeyedContainerMeta, the decoder calls unwrap, with eigther DecodingKeyedContainerMeta or DecodingUnkeyedContainerMeta for type. If unwrap 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 or NilMeta if they could be seen as such containers or nil.

    For these three unwrap variants (where type = NilMeta.Protocol, type = DecodingKeyedContainerMeta.Protocol or type = 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 before decode on a MetaDecoder is called.

    See more

    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 more

    Declaration

    Swift

    public protocol MetaSupplier
  • References a value inside another container meta.

    See more

    Declaration

    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 more

    Declaration

    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 more

    Declaration

    Swift

    public protocol DecodingRepresentation
  • This protocol provides a blueprint for an intermediate encoder, that does simply delegate the task of encoding to a Encoder.

    See more

    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 more

    Declaration

    Swift

    public protocol IntermediateDecoder
  • A meta for a keyed collection of metas during encoding. The key is always a MetaCodingKey. How these keys are handled internal is left to the implementor.

    See more

    Declaration

    Swift

    public protocol EncodingKeyedContainerMeta : Meta
  • A meta for a keyed collection of metas during decoding. The key is always a MetaCodingKey. How these keys are handled internal is left to the implementor.

    See more

    Declaration

    Swift

    public protocol DecodingKeyedContainerMeta : Meta
  • 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
  • Protocol for metas indicating null/nil or no value contained. Please note that MetaSerializations NilMarker type is an default implementation of this protocol.

    Declaration

    Swift

    public protocol NilMeta : Meta
  • Declaration

    Swift

    public protocol UnkeyedContainerMeta : DecodingUnkeyedContainerMeta, EncodingUnkeyedContainerMeta
  • Declaration

    Swift

    public protocol EncodingUnkeyedContainerMeta : Meta
  • Declaration

    Swift

    public protocol DecodingUnkeyedContainerMeta : Meta
  • 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 more

    Declaration

    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 more

    Declaration

    Swift

    public protocol DirectlyEncodable : Encodable