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
⭐️ 1
🕓 3 weeks ago
iOS macOS
.package(url: "https://github.com/swift-libp2p/swift-multicodec.git", from: "0.0.7")


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

Swift implementation of the multicodec specification

Table of Contents


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"))
        name: "...",
        dependencies: [
            .product(name: "Multicodec", package: "swift-multicodec"),



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")


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


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! 🤝


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.


MIT © 2022 Breth Inc.


Stars: 1
Last commit: 3 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

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