Data structure serialization with static typing. Song is to JSON as Swift is to Javascript.
Swift 4.0
Add dependency to Package.swift
.package(url: "https://github.com/blanu/Song", from: "0.0.0")
Or check out directly
git clone https://github.com/blanu/Song
cd Song
If checked out directly
swift test
The tests cover encoding and decoding primitive types, Foundation types, arrays, dictionaries, structs, and classes.
- Enums are not yet supported.
- Decoding is not yet supported.
You can use Song in your application the same way you would use a JSON encoder.
Structs and classes must adopt the Codable protocol. All fields must also be of Codable types. Most primitive types and Foundation types already adopt this protocol.
struct ExampleStruct: Codable {
let value: String
}
let example = ExampleStruct(value: "example string")
let song = Song()
let result: Data = try? song.encode(ex)
For this example, we will just print it as a UTF8 string.
NSLog("\(String(bytes: result!, encoding: .utf8)!)")
The result will be the following string:
let value: ExampleStruct = ExampleStruct(value: "example string")
Notice that the string printed is the same as the Swift code you used to instantiate the struct originally. This is the purpose of Song. It serializes data structures as Swift code and parses Swift code into data structures.
- swift-ast - Swift syntax parser and generator
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests.
SemVer is used for versioning. For the versions available, see the tags on this repository.
- Dr. Brandon Wiley - Concept and initial work - Operator Foundation
This project is licensed under the GPLv3 License - see the LICENSE.md file for details
Song is inspired by Enso and conversations with William R. Cook.