Skip to content

Commit a6c3fd4

Browse files
committed
Add varints officially.
1 parent 416e75e commit a6c3fd4

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

README.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ QmRJzsvyCQyizr73Gmms8ZRtvNxmgqumxc2KUp71dfEmoj # sha256 in base58
2222
EiAsJrRraP/Gj/mbRTwdMEE0E0ItcGSDv6D5il6IYmbnrg== # sha256 in base64
2323
```
2424

25-
## format
25+
## Format
2626

2727
```
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>
2929
```
3030

3131
Binary example (only 4 bytes for simplicity):
@@ -37,18 +37,26 @@ fn code dig size hash digest
3737
sha1 4 bytes 4 byte sha1 digest
3838
```
3939

40-
> Why have digest size as a separate byte?
40+
> Why have digest size as a separate number?
4141
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.
4743

4844
> Why isn't the size first?
4945
5046
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.
5147

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.
59+
5260
## Implementations:
5361

5462
- [go-multihash](//github.com/jbenet/go-multihash)

0 commit comments

Comments
 (0)