From c92a7028eb8be0b7e03d4201a3d4eeb2bc6ebebf Mon Sep 17 00:00:00 2001 From: Damiaan Dufaux Date: Thu, 3 Aug 2017 11:59:10 +0200 Subject: [PATCH] Fix String decoding --- MsgPack/Decoder.swift | 3 ++- MsgPackTests/MsgPackTests.swift | 2 +- Playground.playground/Contents.swift | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/MsgPack/Decoder.swift b/MsgPack/Decoder.swift index ba20d65..4f4b126 100644 --- a/MsgPack/Decoder.swift +++ b/MsgPack/Decoder.swift @@ -146,7 +146,8 @@ struct MsgPckSingleValueDecodingContainer: SingleValueDecodingContainer { return .init(bitPattern: bitPattern) } - mutating func decode(_ type: String.Type) throws -> String { + func decode(_ type: String.Type) throws -> String { + var base = self.base return try Format.string(from: &decoder.storage, base: &base) } diff --git a/MsgPackTests/MsgPackTests.swift b/MsgPackTests/MsgPackTests.swift index 72a2955..e8a5ee0 100644 --- a/MsgPackTests/MsgPackTests.swift +++ b/MsgPackTests/MsgPackTests.swift @@ -121,7 +121,7 @@ class MsgPackTests: XCTestCase { func testExample() { do { - print("roundtrip:", try roundtrip(value: Simple(a: false, b: false))) + print("roundtrip:", try roundtrip(value: "Simple 🎁")) } catch { print(error) } diff --git a/Playground.playground/Contents.swift b/Playground.playground/Contents.swift index cab1dbe..48ae97b 100644 --- a/Playground.playground/Contents.swift +++ b/Playground.playground/Contents.swift @@ -50,4 +50,5 @@ struct Simple: Codable { } try roundtrip(value: -56.4) +try roundtrip(value: "Hello world 😎") try roundtrip(value: Simple(a: true, b: false, c: true, d: false, e: nil))