BinaryDecoder

public struct BinaryDecoder

A BinaryDecoder holds a buffer and allows for extraction of values from said buffer. This keeps track of what has been read from the buffer, and what is still pending for reading to allow the buffer to be read like a tape.

This is a required component to make the Deserializable protocol work. Currently, defining a custom Location types requires some exposure of this object. This should only be interacted with by the generated code delivered to you from your Mappedin rep.

  • Read a value out of the buffer under the current cursor. The cursor will be advanced and an initialized value will be returned. If there is not sufficient space in the buffer a nil value will be returned.

    let foo = try buffer.pull(Int32.self)
    

    Declaration

    Swift

    mutating public func pull<DeserializableType: Deserializable>(
        _ type: DeserializableType.Type) throws -> DeserializableType
  • This will pull an array of values from the Buffer, and advance the cursor until all values have been read. The length of the array is read from the buffer itself.

    let foo = try buffer.pull([Int32].self)
    

    Declaration

    Swift

    mutating public func pull<DeserializableType: Deserializable>(
        _ type: [DeserializableType].Type) throws -> [DeserializableType]
  • This will pull an optional value from the buffer, this is identical to pull but will only pull a value after reading a flag from the buffer indicating if the optional value is present or not.

    let foo = try buffer.pull(Int32?.self)
    

    Declaration

    Swift

    mutating public mutating func pull<DeserializableType>(_ type: DeserializableType?.Type) throws -> DeserializableType? where DeserializableType : Deserializable
  • Pull a value the BinaryDecoder, this is a bit nicer to use since it will infer the type rather then you having to explicitly supply it.

    let foo: UInt32 = try buffer.pullValue()
    

    Declaration

    Swift

    mutating public mutating func pullValue<DeserializableType>() throws -> DeserializableType where DeserializableType : Deserializable
  • Pull a array of values the BinaryDecoder, this is a bit nicer to use since it will infer the type rather then you having to explicitly supply it.

    let foo: [UInt32] = try buffer.pullValue()
    

    Declaration

    Swift

    mutating public mutating func pullValue<DeserializableType>() throws -> [DeserializableType] where DeserializableType : Deserializable