Description
The table has four columns, ignoring the human-readable description:
- Name
- Tag (multihash/ipld/multiaddr/serialization/etc)
- Code (i.e. integer value)
- Status (draft/permanent)
Downstreams like go-ipfs want to be able to enumerate some of these known codes. For example, to tell the user what ipld codecs are supported, they'd rather not hard-code this list as it may grow over time.
One option is to indeed tell downstreams to hard-code the sets of multicodecs they support. This can be reasonable if the list is small or won't change much over time, and especially if explicit support needs to be added for more multicodecs, e.g. by implementing more IPLD codecs with their Encode/Decode interface.
Another option is to expose an API here. The internal mechanics could be code-generated, so they don't worry me. The API is the trickier bit. Below are some options:
-
Exported lists, such as
var TagMultihash = []Code{...}
. A set of these lists for Tag, and perhaps another for Status. -
A single exported list with all fields, such as:
type TaggedCode struct {
Code // inherits String method
Tag string // or perhaps an enum-like integer
Status string // or perhaps "Draft bool"
}
var AllCodes = []TaggedCode{...}
If the user wants a filter in this scenario, such as by Tag, they would iterate over the list and filter as necessary.
- A query-like API, such as:
func ListCodes(byTag, byStatus string, fn func(Code) bool) { ... }
Internally, this would have to use a mechanism like option 1 or 2, so it doesn't actually help a ton. Another major drawback is you'd have to iterate over the entire list to know the number of them.
--
I think that, if we want to do this, options 1 or 2 seem best. I lean towards a minimal version of number 1 - expose slice variables for each of the tags, as that seems to be what the vast majority of users will want to filter by.