Fix Float decoding bug

This commit is contained in:
Damiaan Dufaux 2017-08-02 22:15:07 +02:00
parent 068bbe87dc
commit 101abe3e46
2 changed files with 8 additions and 3 deletions

View file

@ -135,7 +135,8 @@ struct MsgPckSingleValueDecodingContainer: SingleValueDecodingContainer {
guard decoder.storage[base] == FormatID.float32.rawValue else {
throw Error.invalidFormat(decoder.storage[base])
}
return decoder.storage.read(at: base + 1)
let bitPattern: UInt32 = decoder.storage.bigEndianInteger(at: base + 1)
return .init(bitPattern: bitPattern)
}
func decode(_ type: Double.Type) throws -> Double {

View file

@ -40,5 +40,9 @@ for byte in encodedGraph {
let decoder = Decoder()
let int8 = try encoder.encode(Double(-10))
try decoder.decode(Double.self, from: int8)
func roundtrip<T: Codable>(value: T) throws -> T {
return try decoder.decode(T.self, from: encoder.encode(value))
}
var x: UInt64? = nil
try roundtrip(value: false)