alephao/swift-rlp
Recursive Length Prefix encoding written in Swift
Library Usage
RLP is available through Swift Package Manager.
Adding RLP 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: "1.0.0")
],
targets: [
.target(
name: "MyTarget",
dependencies: [
.product(name: "RLP", package: "swift-rlp")
]
),
]Encoding
import RLP
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 RLP
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
> 0x83646F67Decoding
$ swift run cli decode 0x83646F67
> string("dog")License
RLP is released under an MIT license. See LICENSE for more information.
Package Metadata
Repository: alephao/swift-rlp
Stars: 24
Forks: 4
Open issues: 0
Default branch: main
Primary language: swift
License: MIT
Topics: encoding, ethereum, ios, macos, rlp, swift
README: README.md