From 30255476781789df318a571622ab732681696139 Mon Sep 17 00:00:00 2001 From: Dustin Mierau Date: Wed, 29 Nov 2023 20:13:23 -0800 Subject: Further work on protocol. --- Hotline/Utility/DataExtensions.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'Hotline/Utility/DataExtensions.swift') diff --git a/Hotline/Utility/DataExtensions.swift b/Hotline/Utility/DataExtensions.swift index 3f7101b..caf26a9 100644 --- a/Hotline/Utility/DataExtensions.swift +++ b/Hotline/Utility/DataExtensions.swift @@ -6,6 +6,21 @@ enum Endianness { } extension Data { + init(_ val: UInt8) { + self.init() + self.appendUInt8(val) + } + + init(_ val: UInt16) { + self.init() + self.appendUInt16(val) + } + + init(_ val: UInt32) { + self.init() + self.appendUInt32(val) + } + func readUInt8(at offset: Int) -> UInt8? { guard offset >= 0, offset + MemoryLayout.size <= self.count else { return nil -- cgit