ByteReader

public protocol ByteReader : AnyObject

A type that contains functions for reading Data byte-by-byte.

  • Size of the data (in bytes).

    Declaration

    Swift

    var size: Int { get }
  • Data which is being read.

    Declaration

    Swift

    var data: Data { get }
  • Offset to a byte in the data which will be read next.

    Declaration

    Swift

    var offset: Int { get set }
  • Creates an instance for reading bytes from the data.

    Declaration

    Swift

    init(data: Data)
  • Reads a byte and returns it, advancing by one position.

    Declaration

    Swift

    func byte() -> UInt8
  • Reads count bytes and returns them as a [UInt8] array, advancing by count positions.

    Declaration

    Swift

    func bytes(count: Int) -> [UInt8]
  • int(fromBytes:) Default implementation

    Reads fromBytes bytes and returns them as a Int number, advancing by fromBytes positions.

    Default Implementation

    Reads fromBytes bytes by either using uint64(fromBytes:) or uint32(fromBytes:) depending on the platform’s integer bit width, converts the result to Int, and returns it, advancing by fromBytes positions.

    Declaration

    Swift

    func int(fromBytes count: Int) -> Int
  • Reads fromBytes bytes and returns them as a UInt64 number, advancing by fromBytes positions.

    Declaration

    Swift

    func uint64(fromBytes count: Int) -> UInt64
  • Reads fromBytes bytes and returns them as a UInt32 number, advancing by fromBytes positions.

    Declaration

    Swift

    func uint32(fromBytes count: Int) -> UInt32
  • Reads fromBytes bytes and returns them as a UInt16 number, advancing by fromBytes positions.

    Declaration

    Swift

    func uint16(fromBytes count: Int) -> UInt16
  • init(_:) Extension method

    Creates an instance for reading bytes by using the data and the offset of the specified BitReader.

    Declaration

    Swift

    public init(_ bitReader: BitReader)
  • bytesLeft Extension method

    Amount of bytes left to read.

    Declaration

    Swift

    public var bytesLeft: Int { get }
  • bytesRead Extension method

    Amount of bytes that were already read.

    Declaration

    Swift

    public var bytesRead: Int { get }
  • isFinished Extension method

    True, if the offset points at any position after the last byte in data, which generally means that all data has been read.

    Declaration

    Swift

    public var isFinished: Bool { get }