LsbBitWriter

public final class LsbBitWriter : BitWriter

A type that contains functions for writing Data bit-by-bit and byte-by-byte using “LSB 0” bit numbering scheme.

  • Data which contains the writer’s output (the last byte, that is currently being written, is not included).

    Declaration

    Swift

    public private(set) var data: Data { get }
  • True, if a bit pointer is aligned to a byte boundary.

    Declaration

    Swift

    public var isAligned: Bool { get }
  • Creates an instance for writing bits and bytes.

    Declaration

    Swift

    public init()
  • Writes a bit, advancing by one bit position.

    Precondition

    The bit must be either 0 or 1.

    Declaration

    Swift

    public func write(bit: UInt8)
  • Writes an unsigned number, advancing by bitsCount bit positions.

    This method may be useful for writing numbers, that would cause an integer overflow crash if converted to Int.

    Note

    The number will be truncated if the bitsCount is less than the amount of bits required to fully represent the value of number.

    Note

    Bits of the number are processed using the same bit-numbering scheme as of the writer (i.e. “LSB 0”).

    Precondition

    Parameter bitsCount must be in the 0...UInt.bitWidth range.

    Declaration

    Swift

    public func write(unsignedNumber: UInt, bitsCount: Int)
  • Writes a byte, advancing by one byte position.

    Precondition

    The writer must be aligned.

    Declaration

    Swift

    public func append(byte: UInt8)
  • Aligns a bit pointer to a byte boundary, i.e. moves the bit pointer to the first bit of the next byte, filling all skipped bit positions with zeros. If the writer is already aligned, then does nothing.

    Declaration

    Swift

    public func align()