Serializer

public struct Serializer

Serializes dictionary data to CSV document data.

Note

You should create a new Serializer dictionary you serialize.
  • The callback that will be called with each row that is serialized.

    Declaration

    Swift

    public var onRow: ([UInt8])throws -> ()
  • Creates a new Serializer instance.

    Declaration

    Swift

    public init(onRow: @escaping ([UInt8])throws -> ())

    Parameters

    onRow

    The callback that will be called with each row that is serialized.

  • Serializes a dictionary to CSV document data. Usually this will be a dictionary of type `[BytesRepresentable: [BytesRepresentable]], but it can be any type you conform to the proper protocols.

    You can pass multiple dictionaries of the same structure into this method. The headers will only be serialized the first time it is called.

    Note

    When you pass a dictionary into this method, each value collection is expect to contain the same / number of elements, and will crash with index out of bounds if that assumption is broken.

    Declaration

    Swift

    public mutating func serialize<Data>(_ data: Data) -> Result<Void, ErrorList> where
        Data: KeyedCollection, Data.Key: BytesRepresentable, Data.Value: Collection, Data.Value.Element: BytesRepresentable,
        Data.Value.Index: Strideable, Data.Value.Index.Stride: SignedInteger

    Parameters

    data

    The dictionary (or other object) to parse.

    Return Value

    A Result instance with a .failure case with all the errors from the the .onRow callback calls. If there are no errors, the result will be a .success case.