Swiftpack.co - swift-libp2p/swift-multicodec as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by swift-libp2p.
swift-libp2p/swift-multicodec 0.0.7
Swift implementation of the multicodec specification
⭐️ 2
🕓 9 weeks ago
iOS macOS
.package(url: "https://github.com/swift-libp2p/swift-multicodec.git", from: "0.0.7")

Multicodec

Swift Package Manager compatible Build & Test (macos and linux)

Swift implementation of the multicodec specification

Table of Contents

Install

Include the following dependency in your Package.swift file

let package = Package(
    ...
    dependencies: [
        ...
        .package(url: "https://github.com/swift-libp2p/swift-multicodec.git", .from("0.0.1"))
    ],
    ...
    .target(
        name: "...",
        dependencies: [
            ...
            .product(name: "Multicodec", package: "swift-multicodec"),
        ]),
)

Usage

Example


import Multicodec

let prefixedProtobuf = addPrefix(.protobuf, protobuf)
// prefixedProtobuf 0x50...

// The multicodec codec values can be accessed directly:
print(Codecs.DAG_CBOR.code) //113

// To get the string representation and description of a codec (e.g. for error messages):
print(Codecs(113).name)        // dag-cbor
print(Codecs(113).description) // optional("MerkleDAG cbor")

API

This package conforms to the JS-Multicodec API outlined here

The ground truth for codec values is the multicodec default table

Updating the Codec Values

Updating the Codec enum is done by running the following command at the projects root directory...

swift run update-codecs

Contributing

Contributions are welcomed! This code is very much a proof of concept. I can guarantee you there's a better / safer way to accomplish the same results. Any suggestions, improvements, or even just critques, are welcome!

Let's make this code better together! 🤝

Credits

Big thanks to work done by the js-multicodec team for writing clear code with documentation and tests that made porting this library to Swift relatively painless.

License

MIT © 2022 Breth Inc.

GitHub

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

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