Closed swift-ci closed 5 years ago
cc @millenomi
This is now fixed in 4.2.4 by https://github.com/apple/swift-corelibs-foundation/pull/1958
import Foundation
let name: String = "my name"
let age: UInt32 = 100
let myData: Data = "helloworld".data(using: .utf8)!
let properties: [String: Any] = [
"name": name,
"age": age,
"data": myData
]
do {
// pack
let packedData = try PropertyListSerialization.data(fromPropertyList: properties, format: .binary, options: 0)
// unpack
let unpackedProps = try PropertyListSerialization.propertyList(from: packedData, options: [], format: nil)
guard let newProperties = unpackedProps as? [String: Any] else {
fatalError("error: not a dictionary type")
}
for item in newProperties {
print("# \(item.key) => \(item.value)")
}
print("name:", newProperties["name"] as! String)
print("age:", newProperties["age"] as! UInt32)
print("data:", String(data: newProperties["data"] as! Data, encoding: .utf8)!)
} catch {
print("serialize message error: \(error)")
exit(0)
}
$ ~/swift-4.2.4-RELEASE-ubuntu18.04/usr/bin/swift sr-8115.swift
# age => 100
# name => my name
# data => 10 bytes
name: my name
age: 100
data: helloworld
Attachment: Download
Environment
### Ubuntu 16.04 ``` java $ cat /etc/*release ``` DISTRIB_ID=Ubuntu DISTRIB_RELEASE=16.04 DISTRIB_CODENAME=xenial DISTRIB_DESCRIPTION="Ubuntu 16.04.4 LTS" NAME="Ubuntu" VERSION="16.04.4 LTS (Xenial Xerus)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 16.04.4 LTS" VERSION_ID="16.04" HOME_URL="http://www.ubuntu.com/" SUPPORT_URL="http://help.ubuntu.com/" BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/" VERSION_CODENAME=xenial UBUNTU_CODENAME=xenial ``` java $ swift --version ``` Swift version 4.1.2 (swift-4.1.2-RELEASE) Target: x86_64-unknown-linux-gnu ### macOS 10.14 Beta (18A314h) ``` java $ swift --version ``` Apple Swift version 4.2 (swiftlang-1000.0.16.7 clang-1000.10.25.3) Target: x86_64-apple-darwin18.0.0Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Foundation | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 997ac8a236abe1350659cdaa41a1c63fIssue Description:
the output result on my macOS:
the output result on Ubuntu server:
Problem here is the data decoded is "0 bytes"