Ecoji-Swift

July 12, 2020 ยท View on GitHub

CocoaPods Compatible Swift Package Manager compatible

A Swift 5 implementation of the Ecoji encoding standard.

Provides a library for encoding and decoding data as a base-1024 sequence of emojis

Visit ecoji.io to try Ecoji in your browser.

Install

  pod 'Ecoji'

Usage

Works a lot like a JSONEncoder/Decoder

Encoding

Encode is implemented for Data or String inputs

import Ecoji
let encoder = EcojiEncoder()
let emojiString = encoder.encode(from: "Hello World!")
print(emojiString)
// "๐Ÿฏ๐Ÿ”ฉ๐Ÿš—๐ŸŒท๐Ÿ‰๐Ÿ‘‡๐Ÿฆ’๐Ÿ•Š๐Ÿ‘ก๐Ÿ“ขโ˜•โ˜•"

Decoding

You can decode into Data like this:

let decoder = EcojiDecoder()
do {
  let data = try decoder.decode(string: "๐Ÿฏ๐Ÿ”ฉ๐Ÿš—๐ŸŒท๐Ÿ‰๐Ÿ‘‡๐Ÿฆ’๐Ÿ•Š๐Ÿ‘ก๐Ÿ“ขโ˜•โ˜•"
  print(data)
  // "12 bytes"
} catch let err as DecodingError {
  print(err)
}

Theres also a convenience method for reconstruction utf strings from the data:

let decoder = EcojiDecoder()
do {
  let data = try decoder.decodeToString(string: "๐Ÿฏ๐Ÿ”ฉ๐Ÿš—๐ŸŒท๐Ÿ‰๐Ÿ‘‡๐Ÿฆ’๐Ÿ•Š๐Ÿ‘ก๐Ÿ“ขโ˜•โ˜•"
  print(data)
  // "Hello World!"
} catch let err as DecodingError {
  print(err)
}

TODO:

  • Decode/Encode
  • Tests
  • Linux compatibility
  • swift package manager
  • cocoa pod

Contribution

PRs welcome!

check test cases with swift test

License

Like the rust implementation this program is licensed under either of

at your option.