MessagePacker
MessagePacker copied to clipboard
Unexpected behavior of implementation of UnkeyedDecodingContainer.decodeIfPresent(_:) method
Let's take array of optional integers:
let values = [ 1, nil, 2 ]
Then encode it:
var container = encoder.unkeyedContainer()
try values.forEach {
try container.encode($0)
}
The result matches expectation. Then decode it:
var values: [Int?] = .init()
var container = try decoder.unkeyedContainer()
for _ in 0..<3 {
values.append(try container.decodeIfPresent(Int.self))
}
The resulting array is [ 1, nil, nil ], but must be [ 1, nil, 2 ]. This behavior is incorrect (see documentation).
As I see in debugger container doesn't increment .contentIndex. It remains 1.
MessagePacker 0.4.7, MacOS 13.2.1, Xcode 14.2.