MsbBitWriter
public final class MsbBitWriter : BitWriter
A type that contains functions for writing Data
bit-by-bit and byte-by-byte using “MSB 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
Thebit
must be either 0 or 1.Declaration
Swift
public func write(bit: UInt8)
-
Writes an unsigned
number
, advancing bybitsCount
bit positions.This method may be useful for writing numbers, that would cause an integer overflow crash if converted to
Int
.Note
Thenumber
will be truncated if thebitsCount
is less than the amount of bits required to fully represent the value ofnumber
.Note
Bits of thenumber
are processed using the same bit-numbering scheme as of the writer (i.e. “MSB 0”).Precondition
ParameterbitsCount
must be in the0...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()