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

tidy code generation, add KnownCodes, add Code.Tag method #59

Merged
merged 4 commits into from Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions code.go
Expand Up @@ -9,9 +9,7 @@ import (

//go:generate go run gen.go
//go:generate gofmt -w code_table.go
//go:generate go get golang.org/x/tools/cmd/stringer
//go:generate go run golang.org/x/tools/cmd/stringer -type=Code -linecomment
//go:generate go mod tidy
//go:generate go run golang.org/x/tools/cmd/stringer@v0.1.7 -type=Code -linecomment

// Code describes an integer reserved in the multicodec table, defined at
// github.com/multiformats/multicodec.
Expand Down Expand Up @@ -77,3 +75,14 @@ func (c *Code) Set(text string) error {
}
return fmt.Errorf("unknown multicodec: %q", text)
}

// Note that KnownCodes is a function backed by a code-generated slice.
// Later on, if the slice gets too large, we could codegen a packed form
// and only expand to a regular slice via a sync.Once.
// A function also makes it a bit clearer that the list should be read-only.

// KnownCodes returns a list of all codes registered in the multicodec table.
// The returned slice should be treated as read-only.
func KnownCodes() []Code {
return knownCodes
}