Stream Helper Methods in Swift

The stream classes and stream classes extensions provide all the methods necessary for encoding and decoding Ice types. The Slice to Swift compiler generates additional stream helper classes required to encode and decode sequences and dictionaries, more concretely it generates a sequence helper for each sequence of a complex type, and it generates a dictionary helper for each dictionary type, sequences of built-in types are directly encoded and decoded using the OutputStream and InputStream methods. We will use the following Slice definitions to demonstrate the language mapping:

Slice
module M
{
    sequence<...> Seq;
    dictionary<...> Dict;
}

The Slice compiler generates the corresponding helper methods shown below:

Swift
/// Helper class to read and write Seq sequence values from Ice.InputStream and Ice.OutputStream.
public struct SeqHelper {
    /// Read a Seq sequence from the stream.
    public static func read(from istr: Ice.InputStream) throws -> Seq { ... }
    /// Read an optional Seq? sequence from the stream.
    public static func read(from istr: Ice.InputStream, tag: Swift.Int32) throws -> Seq? { ... }
    /// Wite a Seq sequence to the stream.
    public static func write(to ostr: Ice.OutputStream, value v: Seq) { ... }
    /// Wite an optional Seq? sequence to the stream.
    public static func write(to ostr: Ice.OutputStream,  tag: Swift.Int32, value v: Seq?) { ... }
}


/// Helper class to read and write Dict dictionary values from Ice.InputStream and Ice.OutputStream.
public struct DictHelper {
    /// Read a Dict dictionary from the stream.
    public static func read(from istr: Ice.InputStream) throws -> Dict { ... }
    /// Read an optional Dict? dictionary from the stream.
    public static func read(from istr: Ice.InputStream, tag: Swift.Int32) throws -> Dict? { ... }
    /// Wite a Dict dictionary to the stream.
    public static func write(to ostr: Ice.OutputStream, value v: Dict) { ... }
    /// Wite an optional Dict? dictionary to the stream.
    public static func write(to ostr: Ice.OutputStream, tag: Swift.Int32, value v: Dict?) { ... }
}

The SeqHelper provides read and write methods for extracting and inserting Seq sequence values, likewise, the DictHelper provides read and write methods for extracting and inserting Dict dictionary values.

See Also