I'm encountering an issue unpacking a msgpack payload in Swift 3.
I'm getting a msgpack payload from an API and I'm using this library to unpack it. It used to work perfectly fine back in Swift 2 with the v1.2. I have created a sample payload as a byte array below.
do {
let arr: [UInt8] = [133, 164, 99, 111, 100, 101, 162, 79, 75, 164, 100, 97, 116, 97, 132, 171, 97, 99, 99, 101, 115, 115, 84, 111, 107, 101, 110, 218, 1, 60, 101, 121, 74, 104, 98, 71, 99, 105, 79, 105, 74, 73, 85, 122, 73, 49, 78, 105, 73, 115, 73, 110, 82, 53, 99, 67, 73, 54, 73, 107, 112, 88, 86, 67, 74, 57, 46, 101, 121, 74, 106, 98, 71, 108, 108, 98, 110, 81, 105, 79, 105, 74, 109, 78, 50, 89, 121, 78, 84, 108, 107, 89, 83, 49, 104, 78, 122, 82, 108, 76, 84, 82, 109, 78, 50, 81, 116, 79, 87, 85, 52, 79, 67, 48, 50, 90, 68, 89, 52, 77, 122, 89, 120, 90, 106, 107, 51, 78, 84, 103, 105, 76, 67, 74, 119, 90, 88, 74, 122, 98, 50, 52, 105, 79, 105, 74, 105, 77, 84, 82, 119, 98, 110, 90, 48, 98, 109, 53, 122, 97, 106, 99, 120, 99, 122, 86, 122, 99, 50, 70, 104, 90, 121, 73, 115, 73, 109, 82, 108, 100, 109, 108, 106, 90, 83, 73, 54, 73, 107, 81, 53, 82, 68, 100, 71, 81, 122, 99, 49, 76, 84, 73, 52, 78, 85, 89, 116, 78, 69, 70, 68, 82, 83, 48, 53, 82, 84, 77, 53, 76, 84, 65, 120, 79, 84, 81, 122, 78, 106, 104, 66, 77, 106, 107, 122, 81, 121, 73, 115, 73, 110, 82, 53, 99, 71, 85, 105, 79, 106, 73, 115, 73, 109, 86, 52, 99, 67, 73, 54, 77, 84, 81, 52, 77, 84, 73, 50, 77, 106, 73, 51, 77, 83, 119, 105, 97, 88, 78, 122, 73, 106, 111, 105, 84, 87, 57, 114, 98, 121, 49, 84, 90, 88, 74, 50, 97, 87, 78, 108, 73, 110, 48, 46, 103, 80, 99, 81, 120, 68, 65, 76, 119, 85, 105, 117, 57, 95, 110, 79, 80, 97, 114, 65, 71, 104, 45, 106, 71, 106, 119, 88, 83, 84, 54, 107, 118, 74, 76, 87, 105, 98, 107, 107, 100, 75, 89, 169, 101, 120, 112, 105, 114, 101, 115, 65, 116, 206, 88, 74, 68, 191, 166, 112, 101, 114, 115, 111, 110, 136, 169, 102, 105, 114, 115, 116, 78, 97, 109, 101, 165, 73, 115, 117, 114, 117, 166, 104, 97, 110, 100, 108, 101, 160, 162, 105, 100, 180, 98, 49, 52, 112, 110, 118, 116, 110, 110, 115, 106, 55, 49, 115, 53, 115, 115, 97, 97, 103, 168, 105, 109, 97, 103, 101, 85, 114, 108, 160, 170, 108, 97, 115, 116, 65, 99, 116, 105, 118, 101, 206, 88, 73, 169, 165, 168, 108, 97, 115, 116, 78, 97, 109, 101, 171, 78, 97, 110, 97, 121, 97, 107, 107, 97, 114, 97, 165, 112, 104, 111, 110, 101, 172, 43, 57, 52, 55, 55, 49, 51, 53, 52, 56, 53, 54, 168, 116, 104, 117, 109, 98, 85, 114, 108, 160, 172, 114, 101, 102, 114, 101, 115, 104, 84, 111, 107, 101, 110, 218, 1, 60, 101, 121, 74, 104, 98, 71, 99, 105, 79, 105, 74, 73, 85, 122, 73, 49, 78, 105, 73, 115, 73, 110, 82, 53, 99, 67, 73, 54, 73, 107, 112, 88, 86, 67, 74, 57, 46, 101, 121, 74, 106, 98, 71, 108, 108, 98, 110, 81, 105, 79, 105, 74, 109, 78, 50, 89, 121, 78, 84, 108, 107, 89, 83, 49, 104, 78, 122, 82, 108, 76, 84, 82, 109, 78, 50, 81, 116, 79, 87, 85, 52, 79, 67, 48, 50, 90, 68, 89, 52, 77, 122, 89, 120, 90, 106, 107, 51, 78, 84, 103, 105, 76, 67, 74, 119, 90, 88, 74, 122, 98, 50, 52, 105, 79, 105, 74, 105, 77, 84, 82, 119, 98, 110, 90, 48, 98, 109, 53, 122, 97, 106, 99, 120, 99, 122, 86, 122, 99, 50, 70, 104, 90, 121, 73, 115, 73, 109, 82, 108, 100, 109, 108, 106, 90, 83, 73, 54, 73, 107, 81, 53, 82, 68, 100, 71, 81, 122, 99, 49, 76, 84, 73, 52, 78, 85, 89, 116, 78, 69, 70, 68, 82, 83, 48, 53, 82, 84, 77, 53, 76, 84, 65, 120, 79, 84, 81, 122, 78, 106, 104, 66, 77, 106, 107, 122, 81, 121, 73, 115, 73, 110, 82, 53, 99, 71, 85, 105, 79, 106, 69, 115, 73, 109, 86, 52, 99, 67, 73, 54, 77, 84, 99, 53, 77, 106, 73, 49, 79, 84, 65, 51, 77, 83, 119, 105, 97, 88, 78, 122, 73, 106, 111, 105, 84, 87, 57, 114, 98, 121, 49, 84, 90, 88, 74, 50, 97, 87, 78, 108, 73, 110, 48, 46, 85, 50, 113, 81, 109, 50, 99, 111, 95, 101, 67, 120, 77, 56, 102, 68, 82, 116, 65, 105, 53, 72, 87, 117, 121, 103, 98, 110, 73, 88, 119, 112, 77, 87, 84, 95, 117, 87, 88, 55, 48, 100, 69, 171, 100, 101, 115, 99, 114, 105, 112, 116, 105, 111, 110, 178, 82, 101, 113, 117, 101, 115, 116, 32, 115, 117, 99, 99, 101, 115, 115, 102, 117, 108, 167, 109, 101, 115, 115, 97, 103, 101, 178, 82, 101, 113, 117, 101, 115, 116, 32, 115, 117, 99, 99, 101, 115, 115, 102, 117, 108, 167, 115, 117, 99, 99, 101, 115, 115, 195]
let data = Data(bytes: arr, count: arr.count)
let msgpack = try unpack(data)
print(msgpack)
} catch {
print("Unpacking failed: \(error)")
}
Like I mentioned earlier, the unpacking happened successfully without error in Swift 2. I was using the v1.2 of this library. Here I tested it again with a sample Xcode 7.3 project.
When I converted the project to Swift 3 and upgraded the library to v2.0 and ran it against the same payload, it would fail with the error invalidArgument. I can't figure out why. All I could pin point was the error was occurring within the unpackString
method.