TupleAdapter

public protocol TupleAdapter

This type describes an adapter that can encode and decode a value as a FoundationDB Tuple.

  • The type of value that this adapter encodes.

    Declaration

    Swift

    associatedtype ValueType
  • The tuple type codes that this adapter can read.

    Declaration

    Swift

    static var typeCodes: Set<UInt8> { get }
  • write(value:into:) Default implementation

    This method writes a value into a buffer.

    Default Implementation

    Declaration

    Swift

    static func write(value: ValueType, into buffer: inout Data)

    Parameters

    value

    The value to write.

    buffer

    The buffer to write into.

  • read(from:at:) Default implementation

    This method reads a value from a buffer.

    The implementation can assume that the type code is valid for this type, and that the offset is less than the length of the buffer.

    Throws

    If the data cannot be parsed, this should throw an exception.

    Default Implementation

    Declaration

    Swift

    static func read(from buffer: Data, at offset: Int) throws -> ValueType

    Parameters

    buffer

    The buffer to read from.

    offset

    The offset in the buffer to read from. This will be the position of the entry’s type code.

    Return Value

    The parsed value.

  • write(bytes:into:) Extension method

    This method writes a sequence of bytes into a buffer.

    Any zero bytes in the sequence will be replaced with a zero byte followed by 0xFF.

    An additional zero byte will be written at the end of the sequence.

    Declaration

    Swift

    public static func write<T>(bytes: T, into buffer: inout Data) where T : Sequence, T.Element == UInt8
  • readBytes(from:offset:) Extension method

    This method reads a sequence of bytes from a buffer.

    Any ocurrence of 0x00 followed by 0xFF will be replaced with 0x00. When this encounters a byte of 0x00 that is not followed by 0xFF, it will stop reading and return the array.

    Declaration

    Swift

    public static func readBytes(from buffer: Data, offset start: Data.Index) -> [UInt8]

    Parameters

    buffer

    The buffer we are reading from.

    offset

    The position to start reading from. This will be the index of the first byte in the sequence.

    Return Value

    The decoded bytes.

  • integerTypeCodes() Extension method

    The type codes that can represent fixed width integers.

    Declaration

    Swift

    public static func integerTypeCodes() -> Set<UInt8>
  • write(int:into:) Extension method

    Undocumented

    Declaration

    Swift

    public static func write<IntegerType>(int: IntegerType, into buffer: inout Data) where IntegerType : FixedWidthInteger
  • readBitPattern(from:at:) Extension method

    Undocumented

    Declaration

    Swift

    public static func readBitPattern(from buffer: Data, at offset: Int) throws -> UInt64