SwiftRLP

0.0.6

Recursive Length Prefix encoding written in Swift
alephao/swift-rlp

What's New

v0.0.6

2024-01-29T16:15:38Z

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

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.

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

Last updated: Sun Mar 24 2024 06:31:32 GMT-0900 (Hawaii-Aleutian Daylight Time)