mikeash.com pyblog/friday-qa-2017-07-28-a-binary-coder-for-swift.html commentshttp://www.mikeash.com/?page=pyblog/friday-qa-2017-07-28-a-binary-coder-for-swift.html#commentsmikeash.com Recent CommentsThu, 28 Mar 2024 17:48:10 GMTPyRSS2Gen-1.0.0http://blogs.law.harvard.edu/tech/rssArbi - 2017-09-08 06:46:23http://www.mikeash.com/?page=pyblog/friday-qa-2017-07-28-a-binary-coder-for-swift.html#commentsCurrently we are using object mapper for coding decoding json and mapping return data. Apple did us a big favor by introducing the decodable and encodable protocol.I love how detailed you have gotten with it . I really appreciate and I will use it once I upgrade to swift 4.0 and Xcode 9.63c6cd5ffc7acad4c4b72e541223a403Fri, 08 Sep 2017 06:46:23 GMTMaxim - 2017-09-01 15:27:14http://www.mikeash.com/?page=pyblog/friday-qa-2017-07-28-a-binary-coder-for-swift.html#commentsSorry it's me again, just browsed through the code on github and saw that you turn FixedWidthInteger to bigEndian. Does CFConvertFloatHostToSwapped convert floats to big endian as well?1d80b91f6776298e81acefff07ea383cFri, 01 Sep 2017 15:27:14 GMTMaxim - 2017-09-01 15:19:13http://www.mikeash.com/?page=pyblog/friday-qa-2017-07-28-a-binary-coder-for-swift.html#commentsHi Mike, thank you very much for the great article. Could you elaborate on CFConvertFloatHostToSwapped. Why exactly do you need it? I though it would imply the endianness of the machine but, there is no sign of changing ints to a particular endian in the example.d425a1788b378c2cc139eec71f10aca2Fri, 01 Sep 2017 15:19:13 GMTColin - 2017-08-31 05:01:03http://www.mikeash.com/?page=pyblog/friday-qa-2017-07-28-a-binary-coder-for-swift.html#commentsHuh. I actually need a binary coder. Thx! <br /> <br />I've got a vector drawing app, and to store raw stroke point data needs to be fast. I'm currently using messagepack, which is alright. But faster would always be better for this! <br /> <br />Any data on performance of your implementation? Looks like it could be pretty optimal, this approach...f5fc3486357c5f0eb34b2a27c259e08fThu, 31 Aug 2017 05:01:03 GMTmikeash - 2017-08-01 13:22:34http://www.mikeash.com/?page=pyblog/friday-qa-2017-07-28-a-binary-coder-for-swift.html#comments<b>David Waite:</b> I give you minus two points for missing the part of the article where I mention that, but plus five points for figuring out the problem and a solution, so good job overall!7a62e5577697e7aba515ba5f0d0218d4Tue, 01 Aug 2017 13:22:34 GMTDavid Waite - 2017-08-01 03:33:54http://www.mikeash.com/?page=pyblog/friday-qa-2017-07-28-a-binary-coder-for-swift.html#comments...aaaaand never mind, thats exactly what you did. I guess I may be publicly humiliated at your sole discretion now.4ab8c7dd02512350ac8169a597a83ce9Tue, 01 Aug 2017 03:33:54 GMTDavid Waite - 2017-08-01 03:25:01http://www.mikeash.com/?page=pyblog/friday-qa-2017-07-28-a-binary-coder-for-swift.html#commentsSimilar to how you are swapping host bytes for floating point and integer numbers to big-endian/network byte order, shouldn't you always encode Int as 64 bits, and error on decode if the platform cannot fit the number?6b6f7c30e30bbc391d79ef3e455ea4a9Tue, 01 Aug 2017 03:25:01 GMTmikeash - 2017-07-31 18:18:32http://www.mikeash.com/?page=pyblog/friday-qa-2017-07-28-a-binary-coder-for-swift.html#comments<b>Alan W:</b> Thanks, I fixed that too. Who would have thought that the one piece of code in this post that I just wrote for the article and didn't test would be full of errors. If only there was some sort of lesson in here for me.a0fe639a21138c4bdf206e8a96a08e75Mon, 31 Jul 2017 18:18:32 GMTAlan W - 2017-07-30 18:18:42http://www.mikeash.com/?page=pyblog/friday-qa-2017-07-28-a-binary-coder-for-swift.html#commentsI think that <br /> <br />&nbsp;&nbsp;&nbsp;&nbsp;<code>let roundtrippedCompany = try BinaryDecoder.decode(T.self, data: data)</code> <br /> <br />should be <br /> <br />&nbsp;&nbsp;&nbsp;&nbsp;<code>let roundtrippedCompany = try BinaryDecoder.decode(Company.self, data: data)</code> <br /> <br />It made a lot more sense when I saw that in the unit test. =)a7e8c0bc7224c52b393d7588fc755152Sun, 30 Jul 2017 18:18:42 GMTmikeash - 2017-07-29 18:27:19http://www.mikeash.com/?page=pyblog/friday-qa-2017-07-28-a-binary-coder-for-swift.html#comments<b>Svetoslav:</b> Yes indeed. I fixed it. Thanks!1b065230a0c00c056dd83ce63167c9fdSat, 29 Jul 2017 18:27:19 GMTSvetoslav - 2017-07-29 17:34:18http://www.mikeash.com/?page=pyblog/friday-qa-2017-07-28-a-binary-coder-for-swift.html#commentsThe line <br /><code> <br />&nbsp;&nbsp;&nbsp;&nbsp;let data = try BinaryEncoder.encode(original) <br /></code> <br />should be <br /><code> <br />&nbsp;&nbsp;&nbsp;&nbsp;let data = try BinaryEncoder.encode(company) <br /></code> <br />14425aaa35d505a99fe4979fa4476911Sat, 29 Jul 2017 17:34:18 GMT