From 068bbe87dc15bce1a8c09a2af387b736ffee503a Mon Sep 17 00:00:00 2001 From: Damiaan Dufaux Date: Wed, 2 Aug 2017 22:05:36 +0200 Subject: [PATCH] Fix Double decoding bug --- MsgPack/Decoder.swift | 4 ++-- Playground.playground/Contents.swift | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/MsgPack/Decoder.swift b/MsgPack/Decoder.swift index f7ae951..48bb657 100644 --- a/MsgPack/Decoder.swift +++ b/MsgPack/Decoder.swift @@ -142,8 +142,8 @@ struct MsgPckSingleValueDecodingContainer: SingleValueDecodingContainer { guard decoder.storage[base] == FormatID.float64.rawValue else { throw Error.invalidFormat(decoder.storage[base]) } - let bitPattern: UInt64 = decoder.storage.read(at: base + 1) - return .init(bitPattern) + let bitPattern: UInt64 = decoder.storage.bigEndianInteger(at: base + 1) + return .init(bitPattern: bitPattern) } func decode(_ type: String.Type) throws -> String { diff --git a/Playground.playground/Contents.swift b/Playground.playground/Contents.swift index 38e5849..b0cae1d 100644 --- a/Playground.playground/Contents.swift +++ b/Playground.playground/Contents.swift @@ -40,5 +40,5 @@ for byte in encodedGraph { let decoder = Decoder() -let int8 = try encoder.encode(Int8(-57)) -try decoder.decode(Int8.self, from: int8) +let int8 = try encoder.encode(Double(-10)) +try decoder.decode(Double.self, from: int8)