Skip to content

📝 Multicodecs is the ruby implementation of multiformats/multicodec, a canonical table of of codecs used by various multiformats

Notifications You must be signed in to change notification settings

SleeplessByte/ruby-multicodec

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multicodecs

Build Status Gem Version MIT license Maintainability

Canonical table of of codecs used by various multiformats

Multicodecs is the ruby implementation of multiformats/multicodec.

🙌🏽 This is called multicodecs instead of the singular form, to stay consistent with the multihashes gem, which was forced to take a different name has multihash was already taken, which is also the case for multibase and others. In the future, this might be renamed to multiformats-codec, with a backwards-compatible interface.

Installation

Add this line to your application's Gemfile:

gem 'multicodecs', require: false

Or if you want to autoload the last known table:

gem 'multicodecs'

Or if you want the PORO without any values:

gem 'multicodecs', require: 'multicodecs/bare'

And then execute:

$ bundle

Or install it yourself as:

$ gem install multicodecs

Usage

This is just a codec, not a protocol. This means that this gem only provides a nice-to-use mapping from the [single source of truth][table] to a PORO. It also allows you to bring your own values.

require 'multicodecs'

Multicodecs['identity']
# => #<struct Multicodecs::Registration code=0, name="identity", tag="multihash">

Multicodecs[0x12]
# => #<struct Multicodecs::Registration code=18, name="sha2-256", tag="multihash">

Multicodecs.find_by(name: 'protobuf')
# => #<struct Multicodecs::Registration code=80, name="protobuf", tag="serialization">

You can register your own values

Multicodecs.register(code: 0x12345, name: 'xxx', tag: 'vendor')
# => #<struct Multicodecs::Registration code=74565, name="xxx", tag="vendor">

Convenience methods exist:

  • Multicodecs.names: returns all the known names
  • Multicodecs.codes: returns all the known codes
  • Multicodecs.find_by(code: nil, name: nil): same as []
  • Multicodecs.fetch_by!(code: nil, name: nil): same as [] but errors if not found
  • Multicodecs.load_csv(csv, radix: 16): loads table.csv like data

Related

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Updating the table

The Rakefile provides an easy way of updating the table.csv, using a rake command.

rake update
# => updated lib/table.csv

Contributing

Bug reports and pull requests are welcome on GitHub at SleeplessByte/ruby-multicodec. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in this project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

About

📝 Multicodecs is the ruby implementation of multiformats/multicodec, a canonical table of of codecs used by various multiformats

Resources

Stars

Watchers

Forks

Packages

No packages published