mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
12 lines
328 B
Swift
12 lines
328 B
Swift
|
|
internal extension FixedWidthInteger {
|
|
|
|
init?(fromBigEndianBytes bytes: [UInt8]) {
|
|
guard bytes.count == MemoryLayout<Self>.size else { return nil }
|
|
self = bytes.reduce(0) { ($0 << 8) | Self($1) }
|
|
}
|
|
|
|
var bigEndianBytes: [UInt8] {
|
|
return withUnsafeBytes(of: bigEndian) { [UInt8]($0) }
|
|
}
|
|
}
|