There are many questions asking about converting Data to an \[UInt8\]. I would like to do the opposite. Convert from [UInt8] to Data.
I looked at the initializers, and these seem to be the most promising:
- init(elements: Sequence)
- init(bytes: UnsafeRawPointer, count: Int)
- init(repeating: UInt8, count: Int)
The problem with #1, is that it takes in any sequence, not just [UInt8]. Therefore, it doesn't give me much confidence that it'll encode my data exactly as I want.
The problem with #2, is that I'm not sure how to convert from [UInt8] to UnsafeRawPointer. Also the unsafe part makes me think this is not the correct approach.
The problem with #3, is that it only allows me to repeat the same exact byte, multiple times. My data contains different bytes.
How do I convert from [UInt8] to Data?
