Multicodec
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.