You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+16-8Lines changed: 16 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,10 +22,10 @@ QmRJzsvyCQyizr73Gmms8ZRtvNxmgqumxc2KUp71dfEmoj # sha256 in base58
22
22
EiAsJrRraP/Gj/mbRTwdMEE0E0ItcGSDv6D5il6IYmbnrg== # sha256 in base64
23
23
```
24
24
25
-
## format
25
+
## Format
26
26
27
27
```
28
-
<1-byte hash function code><1-byte digest size in bytes><hash function output>
28
+
<varint hash function code><varint digest size in bytes><hash function output>
29
29
```
30
30
31
31
Binary example (only 4 bytes for simplicity):
@@ -37,18 +37,26 @@ fn code dig size hash digest
37
37
sha1 4 bytes 4 byte sha1 digest
38
38
```
39
39
40
-
> Why have digest size as a separate byte?
40
+
> Why have digest size as a separate number?
41
41
42
-
Because you end up with a function code really meaning "function-and-digest-size-code". Makes using custom digest sizes annoying, and is less flexible.
43
-
44
-
> What if we need more?
45
-
46
-
Let's decide that when we have 128 hash functions or digest sizes.
42
+
Because otherwise you end up with a function code really meaning "function-and-digest-size-code". Makes using custom digest sizes annoying, and is less flexible.
47
43
48
44
> Why isn't the size first?
49
45
50
46
Because aesthetically I prefer the code first. You already have to write your stream parsing code to understand that a single byte already means "a length in bytes more to skip". Reversing these doesn't buy you much.
51
47
48
+
> Why varints?
49
+
50
+
So that we have no limitation on functions or lengths.
51
+
52
+
> What kind of varints?
53
+
54
+
An Most Significant Bit unsigned varint, as defined by the [multiformats/unsigned-varint](https://github.com/multiformats/unsigned-varint).
55
+
56
+
> Don't we have to agree on a table of functions?
57
+
58
+
Yes, but we already have to agree on functions, so this is not hard. The table even leaves some room for custom function codes.
0 commit comments