Swift implementation of the multicodec specification
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"), ]), )
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 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.