From 5eddff1fdc481a7d78adde24596fe8f9f6c46f83 Mon Sep 17 00:00:00 2001 From: Damiaan Dufaux Date: Mon, 31 Jul 2017 15:26:20 +0200 Subject: [PATCH] Encode Optionals --- MsgPack/Encoder.swift | 2 +- Playground.playground/Contents.swift | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/MsgPack/Encoder.swift b/MsgPack/Encoder.swift index 5c76007..e05c173 100644 --- a/MsgPack/Encoder.swift +++ b/MsgPack/Encoder.swift @@ -46,7 +46,7 @@ extension MsgPack.Serialiser: SingleValueEncodingContainer { } func encodeNil() throws { - throw Error.notImplemented + storage = .nil } func encode(_ value: Bool) throws { diff --git a/Playground.playground/Contents.swift b/Playground.playground/Contents.swift index cbd6840..c140377 100644 --- a/Playground.playground/Contents.swift +++ b/Playground.playground/Contents.swift @@ -1,9 +1,17 @@ //: Playground - noun: a place where people can play import MsgPack +import Foundation -var number: UInt16 = 0x0906 +var number: UInt16? = 0x0906 -let data = try Encoder().encode(number) +let encoder = Encoder() + +let data = try encoder.encode(number) data[1] data[2] + +number = nil + +let data2 = try encoder.encode(number) +data2[0]