CodingStorage

public protocol CodingStorage

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

  • Accesses the meta at the given coding path.

    You may not expect that you already stored a meta at codingPath. However you may expect, that the path is filled up to codingPath[0..<codingPath.endIndex-1].

    Declaration

    Swift

    subscript(codingPath: [CodingKey]) -> Meta { get set }
  • Returns whether a meta is stored at the coding path.

    If a placeholder was requested for this path, return false.

    If this function returns true for a certain path, it must be safe to subscript to this path.

    Declaration

    Swift

    func storesMeta(at codingPath: [CodingKey]) -> Bool
  • Stores a new meta at the coding path.

    If there’s currently a placeholder stored at the given path, replace the placeholder.

    Throw CodingStorageErrors:

    • alreadyStoringValueAtThisCodingPath if the storage already stores a meta at the given coding path
    • pathNotFilled if there is no meta present for codingPath[0..<lastIndex-1]

    Declaration

    Swift

    func store(meta: Meta, at codingPath: [CodingKey]) throws
  • Store a placeholder at the coding path.

    Throw CodingStorageErrors:

    • alreadyStoringValueAtThisCodingPath if the storage already stores a meta at the given coding path
    • pathNotFilled if there is no meta present for codingPath[0..<lastIndex-1]

    Declaration

    Swift

    func storePlaceholder(at codingPath: [CodingKey]) throws
  • Remove the meta at the given coding path.

    Return nil, if a placeholder is stored at the path. Do also remove the placeholder.

    Throw CodingStorageErrors:

    • noMetaStoredAtThisCodingPath if no meta is stored at this coding path.

    Declaration

    Swift

    func remove(at codingPath: [CodingKey]) throws -> Meta?
  • Return a CodingStoreage an new (super) encoder/decoder can work on.

    This new storage needs to be able to coop with coding paths for which values are stored in the storage fork is called on, but not in them teirselves.

    This means, that it is legitimate to call store(… at: [a, b, c]) on the storage returned by this function, if [a, b, c] was passed to fork, although there are no metas stored for [], [a] and [a, b] in the returned stroage. Accessing paths below the given coding path may fail.

    Declaration

    Swift

    func fork(at codingPath: [CodingKey]) -> CodingStorage