2018-04-27 19:56:21 +08:00
|
|
|
import Foundation
|
|
|
|
|
|
|
|
public typealias Bytes = Array<UInt8>
|
|
|
|
|
|
|
|
extension Array where Element == UInt8 {
|
|
|
|
init (count bytes: Int) {
|
|
|
|
self.init(repeating: 0, count: bytes)
|
|
|
|
}
|
2018-04-27 21:40:01 +08:00
|
|
|
|
|
|
|
public var utf8String: String? {
|
2019-03-28 07:44:45 +08:00
|
|
|
return String(data: Data(self), encoding: .utf8)
|
2018-04-27 21:40:01 +08:00
|
|
|
}
|
2018-04-27 19:56:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
extension ArraySlice where Element == UInt8 {
|
|
|
|
var bytes: Bytes { return Bytes(self) }
|
|
|
|
}
|
|
|
|
|
|
|
|
public extension String {
|
|
|
|
var bytes: Bytes { return Bytes(self.utf8) }
|
|
|
|
}
|