Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
ld
go-ld-prime
Commits
b39b96a0
Unverified
Commit
b39b96a0
authored
May 25, 2021
by
Eric Myhre
Committed by
GitHub
May 25, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #176 from ipld/multicodec-registry-listing
Add enumerate methods to the multicodec registries.
parents
723e44d5
401e218a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
0 deletions
+52
-0
multicodec/defaultRegistry.go
multicodec/defaultRegistry.go
+32
-0
multicodec/registry.go
multicodec/registry.go
+20
-0
No files found.
multicodec/defaultRegistry.go
View file @
b39b96a0
...
...
@@ -53,6 +53,22 @@ func LookupEncoder(indicator uint64) (ipld.Encoder, error) {
return
DefaultRegistry
.
LookupEncoder
(
indicator
)
}
// ListEncoders returns a list of multicodec indicators for which an ipld.Encoder is registered.
// The list is in no particular order.
// It is a shortcut to the ListEncoders method on the global DefaultRegistry.
//
// Be judicious about trying to use this function outside of debugging.
// Because the global default registry is global and easily modified,
// and can be changed by any of the transitive dependencies of your program,
// its contents are not particularly stable.
// In particular, it is not recommended to make any behaviors of your program conditional
// based on information returned by this function -- if your program needs conditional
// behavior based on registred codecs, you may want to consider taking more explicit control
// and using your own non-default registry.
func
ListEncoders
()
[]
uint64
{
return
DefaultRegistry
.
ListEncoders
()
}
// RegisterDecoder updates the global DefaultRegistry a map a multicodec indicator number to the given ipld.Decoder function.
// The decoder functions registered can be subsequently looked up using LookupDecoder.
// It is a shortcut to the RegisterDecoder method on the global DefaultRegistry.
...
...
@@ -83,3 +99,19 @@ func RegisterDecoder(indicator uint64, decodeFunc ipld.Decoder) {
func
LookupDecoder
(
indicator
uint64
)
(
ipld
.
Decoder
,
error
)
{
return
DefaultRegistry
.
LookupDecoder
(
indicator
)
}
// ListDecoders returns a list of multicodec indicators for which an ipld.Decoder is registered.
// The list is in no particular order.
// It is a shortcut to the ListDecoders method on the global DefaultRegistry.
//
// Be judicious about trying to use this function outside of debugging.
// Because the global default registry is global and easily modified,
// and can be changed by any of the transitive dependencies of your program,
// its contents are not particularly stable.
// In particular, it is not recommended to make any behaviors of your program conditional
// based on information returned by this function -- if your program needs conditional
// behavior based on registred codecs, you may want to consider taking more explicit control
// and using your own non-default registry.
func
ListDecoders
()
[]
uint64
{
return
DefaultRegistry
.
ListDecoders
()
}
multicodec/registry.go
View file @
b39b96a0
...
...
@@ -60,6 +60,16 @@ func (r *Registry) LookupEncoder(indicator uint64) (ipld.Encoder, error) {
return
encodeFunc
,
nil
}
// ListEncoders returns a list of multicodec indicators for which an ipld.Encoder is registered.
// The list is in no particular order.
func
(
r
*
Registry
)
ListEncoders
()
[]
uint64
{
encoders
:=
make
([]
uint64
,
0
,
len
(
r
.
encoders
))
for
e
:=
range
r
.
encoders
{
encoders
=
append
(
encoders
,
e
)
}
return
encoders
}
// RegisterDecoder updates a simple map of multicodec indicator number to ipld.Decoder function.
// The decoder functions registered can be subsequently looked up using LookupDecoder.
func
(
r
*
Registry
)
RegisterDecoder
(
indicator
uint64
,
decodeFunc
ipld
.
Decoder
)
{
...
...
@@ -81,3 +91,13 @@ func (r *Registry) LookupDecoder(indicator uint64) (ipld.Decoder, error) {
}
return
decodeFunc
,
nil
}
// ListDecoders returns a list of multicodec indicators for which an ipld.Decoder is registered.
// The list is in no particular order.
func
(
r
*
Registry
)
ListDecoders
()
[]
uint64
{
decoders
:=
make
([]
uint64
,
0
,
len
(
r
.
decoders
))
for
d
:=
range
r
.
decoders
{
decoders
=
append
(
decoders
,
d
)
}
return
decoders
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment