Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(readme): improved usage examples #66

Merged
merged 1 commit into from
Apr 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,46 @@

go get github.com/multiformats/go-multicodec


## Type

`Code` describes an integer reserved in the multicodec table, defined at [multiformats/multicodec/table.csv](https://github.com/multiformats/multicodec/blob/master/table.csv).

```go
type Code uint64
```

## Usage

### Importing Code constant

```go
package main

import "github.com/multiformats/go-multicodec"

func main() {
_ = multicodec.Sha2_256
code := multicodec.Sha2_256 // Code
name := multicodec.Sha2_256.String()
}
```

The corresponding `name` value for each codec from the [multicodecs table](https://raw.githubusercontent.com/multiformats/multicodec/master/table.csv) can be accessed via its `String` method. For example, `multicodec.Sha2_256.String()` will return `sha2-256`.

### Code from string

```go
var multicodec.Code code
err := code.Set("libp2p-key")
```


### Code from uint64

```go
rawCode := multicodec.Code(0x55)
```

## Generator

To generate the constants yourself:
Expand Down