Swiftpack.co - alephao/swift-rlp as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by alephao.
alephao/swift-rlp v0.0.6
Recursive Length Prefix encoding written in Swift
⭐️ 23
🕓 4 weeks ago
iOS macOS
.package(url: "https://github.com/alephao/swift-rlp.git", from: "v0.0.6")

SwiftRLP

Swift 5.9.2 Version

This is a simple, pure Swift implementation of Recursive Length Prefix Encoding, a serialisation method for encoding arbitrarily structured binary data (byte arrays).

RLP Encoding is used in Ethereum. You can read more about it here:

Library Usage

SwiftRLP is available through Swift Package Manager.

Adding SwiftRLP as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
  .package(url: "https://github.com/alephao/swift-rlp.git", from: "0.0.6")
],
targets: [
    .target(
      name: "MyTarget",
      dependencies: [
        .product(name: "SwiftRLP", package: "swift-rlp")
      ]
    ),
]

Encoding

import SwiftRLP

let encoder = RLPEncoder()

// String Encoding
try encoder.encode(.string("dog"))
try encoder.encode(string: "dog")

// Array Encoding
try encoder.encode(.array(["d", "o", "g"]))

Decoding

import SwiftRLP

let encodedData = try RLPEncoder().encode(string: "dog")

let decoder = RLPDecoder()
try decoder.decode(from: encodedData) // RLPValue.string("dog")

CLI

Currently, the CLI is only available via source code. To use it, clone this repo and run:

Encoding

$ swift run cli encode dog
> 0x83646F67

Decoding

$ swift run cli decode 0x83646F67
> string("dog")

License

SwiftRLP is released under an MIT license. See LICENSE for more information.

GitHub

link
Stars: 23
Last commit: 4 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

v0.0.6
4 weeks ago

Complete Remake

  • Instead of using the RLP.encode static func, now you need to c reate an RLPEncoder or RLPDecoder to encode/decode.
  • Added a cli utility

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics