multicodecs 0.2.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.vscode/settings.json +7 -0
- data/CHANGELOG.md +6 -0
- data/README.md +5 -7
- data/lib/multicodecs/bare.rb +8 -4
- data/lib/multicodecs/registry.rb +38 -3
- data/lib/multicodecs/version.rb +1 -1
- data/lib/table.csv +586 -460
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf3dc42c444e7e1b15dfe8fd6687e5d32956fa86b46bcabb4609733bf05ff5f3
|
4
|
+
data.tar.gz: ffc283a7ee473362b89cadaf90841a967c5340fcdb36047f046af120da42c432
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b19f680c406fbabb5918243f6b959681d845dfe2416a334561c2c7cf059bb02c9edb58390cebba81fdb99a5d5c3385ad925d5d6380785210ba1298d8a3c79b1
|
7
|
+
data.tar.gz: 9b8d9da86ecf101230e4778a3c349b69f19a7856e4e04c88bc56f9c0868770118f93912059eb0d58d275c7f8e61a079b587e59134683c4ea74851f9ade5e724d
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -58,20 +58,20 @@ also allows you to bring your own values.
|
|
58
58
|
require 'multicodecs'
|
59
59
|
|
60
60
|
Multicodecs['identity']
|
61
|
-
# =>
|
61
|
+
# => 0x0 identity (multihash/permanent): raw binary
|
62
62
|
|
63
63
|
Multicodecs[0x12]
|
64
|
-
# =>
|
64
|
+
# => 0x12 sha2-256 (multihash/permanent): (no description)
|
65
65
|
|
66
66
|
Multicodecs.find_by(name: 'protobuf')
|
67
|
-
# =>
|
67
|
+
# => 0x50 protobuf (serialization/draft): Protocol Buffers
|
68
68
|
```
|
69
69
|
|
70
70
|
You can `register` your own values
|
71
71
|
|
72
72
|
```ruby
|
73
|
-
Multicodecs.register(code: 0x12345, name: 'xxx', tag: 'vendor')
|
74
|
-
# =>
|
73
|
+
Multicodecs.register(code: 0x12345, name: 'xxx', tag: 'vendor', status: 'draft', description: nil)
|
74
|
+
# => 0x12345 xxx (vendor/draft): (no description)
|
75
75
|
```
|
76
76
|
|
77
77
|
Convenience methods exist:
|
@@ -141,5 +141,3 @@ mailing lists is expected to follow the [code of conduct][git-self-coc].
|
|
141
141
|
[web-coc]: http://contributor-covenant.org
|
142
142
|
[web-mit]: https://opensource.org/licenses/MIT
|
143
143
|
[web-rubygems]: https://rubygems.org
|
144
|
-
|
145
|
-
|
data/lib/multicodecs/bare.rb
CHANGED
@@ -8,14 +8,18 @@ module Multicodecs
|
|
8
8
|
|
9
9
|
def load_csv(csv, radix: 16)
|
10
10
|
csv.each do |row|
|
11
|
-
name
|
12
|
-
tag
|
13
|
-
code
|
11
|
+
name = row['name'] || row[0]
|
12
|
+
tag = row['tag'] || row[1]
|
13
|
+
code = row['code'] || row[2]
|
14
|
+
status = row['status'] || row[3]
|
15
|
+
description = row['description'] || row[4]
|
14
16
|
|
15
17
|
Multicodecs.register(
|
16
18
|
name: name.strip,
|
17
19
|
tag: tag.strip,
|
18
|
-
code: code.strip.to_i(16)
|
20
|
+
code: code.strip.to_i(16),
|
21
|
+
status: status.strip,
|
22
|
+
description: description&.strip
|
19
23
|
)
|
20
24
|
end
|
21
25
|
end
|
data/lib/multicodecs/registry.rb
CHANGED
@@ -13,7 +13,28 @@ module Multicodecs
|
|
13
13
|
REGISTRATIONS_PER_TAG = AutoHashCollection.new
|
14
14
|
# rubocop:enable Style/MutableConstant
|
15
15
|
|
16
|
-
Registration
|
16
|
+
class Registration
|
17
|
+
STATUS_DRAFT = 'draft'
|
18
|
+
STATUS_PERMANENT = 'permanent'
|
19
|
+
|
20
|
+
attr_reader :code, :tag, :name, :status, :description
|
21
|
+
|
22
|
+
def initialize(code:, name:, tag:, status:, description:)
|
23
|
+
self.code = code
|
24
|
+
self.name = name
|
25
|
+
self.tag = tag
|
26
|
+
self.status = status
|
27
|
+
self.description = description
|
28
|
+
end
|
29
|
+
|
30
|
+
def permanent?
|
31
|
+
status == STATUS_PERMANENT
|
32
|
+
end
|
33
|
+
|
34
|
+
def draft?
|
35
|
+
status == STATUS_DRAFT
|
36
|
+
end
|
37
|
+
|
17
38
|
def hash
|
18
39
|
name.hash
|
19
40
|
end
|
@@ -28,6 +49,18 @@ module Multicodecs
|
|
28
49
|
def eql?(other)
|
29
50
|
other.is_a?(Registration) && other.name == name
|
30
51
|
end
|
52
|
+
|
53
|
+
def to_s
|
54
|
+
"0x#{code.to_s(16)}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def inspect
|
58
|
+
"#{to_s} #{name} (#{tag}/#{status}): #{description || '(no description)'}"
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
attr_writer :code, :tag, :name, :status, :description
|
31
64
|
end
|
32
65
|
|
33
66
|
module_function
|
@@ -36,8 +69,8 @@ module Multicodecs
|
|
36
69
|
find_by(code: entry, name: entry)
|
37
70
|
end
|
38
71
|
|
39
|
-
def register(
|
40
|
-
Registration.new(
|
72
|
+
def register(name:, tag:, **kwargs)
|
73
|
+
Registration.new(name: name, tag: tag, **kwargs).tap do |registration|
|
41
74
|
Multicodecs::REGISTRATIONS[name] = registration
|
42
75
|
Multicodecs::REGISTRATIONS_PER_TAG[tag] << registration
|
43
76
|
end
|
@@ -51,6 +84,8 @@ module Multicodecs
|
|
51
84
|
end
|
52
85
|
end
|
53
86
|
|
87
|
+
alias find_by! fetch_by!
|
88
|
+
|
54
89
|
def find_by(code: nil, name: nil)
|
55
90
|
Multicodecs::REGISTRATIONS.values.find do |v|
|
56
91
|
v == code || v == name
|
data/lib/multicodecs/version.rb
CHANGED