Skip to content

Commit

Permalink
Add read methods that can take an UInt8
Browse files Browse the repository at this point in the history
  • Loading branch information
Cosmo committed Oct 4, 2019
1 parent 062849d commit 70e13b9
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Sources/BinaryKit/Binary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ public struct Binary {
return result
}

public mutating func readBits(_ quantitiy: UInt8) throws -> Int {
return try readBits(Int(quantitiy))
}

/// Returns the `UInt8`-value of the next byte and
/// increments the reading cursor by 1 byte.
public mutating func readByte() throws -> UInt8 {
Expand All @@ -152,6 +156,10 @@ public struct Binary {
return try getBytes(range: byteCursor..<(byteCursor + quantitiy))
}

public mutating func readBytes(_ quantitiy: UInt8) throws -> [UInt8] {
return try readBytes(Int(quantitiy))
}

/// Returns a `String` of the next n-bytes (`quantitiy`) and
/// increments the reading cursor by n-bytes.
public mutating func readString(quantitiyOfBytes quantitiy: Int, encoding: String.Encoding = .utf8) throws -> String {
Expand Down

0 comments on commit 70e13b9

Please sign in to comment.