The test code has utility extensions for converting bytes to and from hex strings. However, the hexString computed property only returned half the bytes it should because it uses Array.init(unsafeUnitializedCapacity:_:) and set the array count to the number of bytes, rather than double the number of bytes, which is the required number of hexadecimal characters in the resulting string.
Modifications:
Return the correct count in array initializer in DataProtocol.hexString.
Add trivial test to roundtrip Data through the two hex string utilities.
Result:
DataProtocol.hexString: String now returns a hex string for all the bytes.
Motivation:
The test code has utility extensions for converting bytes to and from hex strings. However, the
hexString
computed property only returned half the bytes it should because it usesArray.init(unsafeUnitializedCapacity:_:)
and set the array count to the number of bytes, rather than double the number of bytes, which is the required number of hexadecimal characters in the resulting string.Modifications:
DataProtocol.hexString
.Data
through the two hex string utilities.Result:
DataProtocol.hexString: String
now returns a hex string for all the bytes.