diff --git a/MsgPack/Decoder.swift b/MsgPack/Decoder.swift index 48bb657..2dba09c 100644 --- a/MsgPack/Decoder.swift +++ b/MsgPack/Decoder.swift @@ -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 { diff --git a/Playground.playground/Contents.swift b/Playground.playground/Contents.swift index b0cae1d..bef399e 100644 --- a/Playground.playground/Contents.swift +++ b/Playground.playground/Contents.swift @@ -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(value: T) throws -> T { + return try decoder.decode(T.self, from: encoder.encode(value)) +} + +var x: UInt64? = nil +try roundtrip(value: false)