{"action":"opened","issue":{"url":"https://api.github.com/repos/a2/MessagePack.swift/issues/36","repository_url":"https://api.github.com/repos/a2/MessagePack.swift","labels_url":"https://api.github.com/repos/a2/MessagePack.swift/issues/36/labels{/name}","comments_url":"https://api.github.com/repos/a2/MessagePack.swift/issues/36/comments","events_url":"https://api.github.com/repos/a2/MessagePack.swift/issues/36/events","html_url":"https://github.com/a2/MessagePack.swift/issues/36","id":183116569,"number":36,"title":"Any -> MessagePackValue conversion","user":{"login":"eliburke","id":2371768,"avatar_url":"https://avatars.githubusercontent.com/u/2371768?v=3","gravatar_id":"","url":"https://api.github.com/users/eliburke","html_url":"https://github.com/eliburke","followers_url":"https://api.github.com/users/eliburke/followers","following_url":"https://api.github.com/users/eliburke/following{/other_user}","gists_url":"https://api.github.com/users/eliburke/gists{/gist_id}","starred_url":"https://api.github.com/users/eliburke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eliburke/subscriptions","organizations_url":"https://api.github.com/users/eliburke/orgs","repos_url":"https://api.github.com/users/eliburke/repos","events_url":"https://api.github.com/users/eliburke/events{/privacy}","received_events_url":"https://api.github.com/users/eliburke/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-10-14T18:14:24Z","updated_at":"2016-10-14T18:14:24Z","closed_at":null,"body":"I am adding MsgPack support to [SWAMP](https://github.com/iscriptology/swamp). The SWAMP serializer protocol operates on an array of [Any], so I had to write code to recursively convert each item to the corresponding `MessagePackValue` variant. \r\n\r\nDo you have any interest in integrating this code, either as a standalone function, a ConvenienceInitializer, or an overload of pack() ? \r\n\r\nHeck it's a pretty small amount of code.. here it is if you don't want it in case someone else finds it useful: \r\n```\r\n    open func anyToMPValue(anyVal : Any) -> MessagePackValue? {\r\n        \r\n        switch(anyVal) {\r\n            \r\n        case is Bool:\r\n            print(\"Bool\")\r\n            return MessagePackValue(anyVal as! Bool)\r\n            \r\n        case is Int: // will not handle Int8, Int16, Int32, Int64\r\n            print(\"Int\")\r\n            return MessagePackValue(anyVal as! Int)\r\n            \r\n        case is UInt: // does not handle UInt8, UInt16, UInt32, UInt64\r\n            print(\"UInt\")\r\n            return MessagePackValue(anyVal as! UInt)\r\n            \r\n        case is Float:\r\n            print(\"Float\")\r\n            return MessagePackValue(anyVal as! Float)\r\n            \r\n        case is Double:\r\n            print(\"Double\")\r\n            return MessagePackValue(anyVal as! Double)\r\n            \r\n        case is String:\r\n            print(\"String\")\r\n            return MessagePackValue(anyVal as! String)\r\n            \r\n        case is Array<Any>:\r\n            print(\"Array\")\r\n            var mpArray = Array<MessagePackValue>()\r\n\r\n            let arrayVal = anyVal as! Array<Any>\r\n            for value in arrayVal {\r\n                if let mpValue = anyToMPValue(anyVal: value) {\r\n                    mpArray.append(mpValue)\r\n                } else {\r\n                    print(\"failed to convert\")\r\n                    print(value)\r\n                }\r\n            }\r\n            return MessagePackValue(mpArray)\r\n            \r\n        case is Dictionary<String, Any>:\r\n            print(\"Dictionary\")\r\n            var mpDict = [MessagePackValue : MessagePackValue]()\r\n\r\n            let dictVal = anyVal as! Dictionary<String, Any>\r\n            for (key,value) in dictVal {\r\n                let mpKey = MessagePackValue(key as! String)\r\n                if let mpValue = anyToMPValue(anyVal: value) {\r\n                    mpDict[mpKey] = mpValue\r\n                } else {\r\n                    print(\"failed to convert\")\r\n                    print(value)\r\n                }\r\n            }\r\n            return MessagePackValue(mpDict)\r\n            \r\n        case is Data:\r\n            print(\"Data\")\r\n            return MessagePackValue(anyVal as! Data)\r\n            \r\n        default:\r\n            print(\"Unknown type\")\r\n            return nil;\r\n        }\r\n    }\r\n```\r\n"}}
{"actor":{"display_login":"eliburke"}}