Code Monkey home page Code Monkey logo

song's Introduction

Song

Data structure serialization with static typing. Song is to JSON as Swift is to Javascript.

Getting Started

Prerequisites

Swift 4.0

Installing

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

Running the tests

If checked out directly

swift test

Encoding and decoding tests

The tests cover encoding and decoding primitive types, Foundation types, arrays, dictionaries, structs, and classes.

Limitations

  • Enums are not yet supported.
  • Decoding is not yet supported.

Deployment

You can use Song in your application the same way you would use a JSON encoder.

Define your data structures

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")

Create and use an encoder

let song = Song()
let result: Data = try? song.encode(ex)

Use the encoded data

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.

Built With

  • swift-ast - Swift syntax parser and generator

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests.

Versioning

SemVer is used for versioning. For the versions available, see the tags on this repository.

Authors

License

This project is licensed under the GPLv3 License - see the LICENSE.md file for details

Acknowledgments

Song is inspired by Enso and conversations with William R. Cook.

song's People

Contributors

consuelita avatar cryptosax avatar blanu avatar rnscully avatar bragelbytes avatar zunkworks avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.