@@ -4,23 +4,23 @@ import (
4
4
mh "github.com/multiformats/go-multihash"
5
5
)
6
6
7
- type Format interface {
7
+ type Builder interface {
8
8
Sum (data []byte ) (* Cid , error )
9
9
GetCodec () uint64
10
- WithCodec (uint64 ) Format
10
+ WithCodec (uint64 ) Builder
11
11
}
12
12
13
- type FormatV0 struct {}
13
+ type V0Builder struct {}
14
14
15
- type FormatV1 struct {
15
+ type V1Builder struct {
16
16
Codec uint64
17
17
HashFun uint64
18
18
HashLen int // HashLen <= 0 means the default length
19
19
}
20
20
21
- func PrefixToFormat (p Prefix ) Format {
21
+ func PrefixToBuilder (p Prefix ) Builder {
22
22
if p .Version == 0 {
23
- return FormatV0 {}
23
+ return V0Builder {}
24
24
}
25
25
mhLen := p .MhLength
26
26
if p .MhType == mh .ID {
@@ -29,7 +29,7 @@ func PrefixToFormat(p Prefix) Format {
29
29
if mhLen < 0 {
30
30
mhLen = 0
31
31
}
32
- return FormatV1 {
32
+ return V1Builder {
33
33
Codec : p .Codec ,
34
34
HashFun : p .MhType ,
35
35
HashLen : mhLen ,
@@ -40,7 +40,7 @@ func (p Prefix) GetCodec() uint64 {
40
40
return p .Codec
41
41
}
42
42
43
- func (p Prefix ) WithCodec (c uint64 ) Format {
43
+ func (p Prefix ) WithCodec (c uint64 ) Builder {
44
44
if c == p .Codec {
45
45
return p
46
46
}
@@ -51,26 +51,26 @@ func (p Prefix) WithCodec(c uint64) Format {
51
51
return p
52
52
}
53
53
54
- func (p FormatV0 ) Sum (data []byte ) (* Cid , error ) {
54
+ func (p V0Builder ) Sum (data []byte ) (* Cid , error ) {
55
55
hash , err := mh .Sum (data , mh .SHA2_256 , - 1 )
56
56
if err != nil {
57
57
return nil , err
58
58
}
59
59
return NewCidV0 (hash ), nil
60
60
}
61
61
62
- func (p FormatV0 ) GetCodec () uint64 {
62
+ func (p V0Builder ) GetCodec () uint64 {
63
63
return DagProtobuf
64
64
}
65
65
66
- func (p FormatV0 ) WithCodec (c uint64 ) Format {
66
+ func (p V0Builder ) WithCodec (c uint64 ) Builder {
67
67
if c == DagProtobuf {
68
68
return p
69
69
}
70
- return FormatV1 {Codec : c , HashFun : mh .SHA2_256 }
70
+ return V1Builder {Codec : c , HashFun : mh .SHA2_256 }
71
71
}
72
72
73
- func (p FormatV1 ) Sum (data []byte ) (* Cid , error ) {
73
+ func (p V1Builder ) Sum (data []byte ) (* Cid , error ) {
74
74
mhLen := p .HashLen
75
75
if mhLen <= 0 {
76
76
mhLen = - 1
@@ -82,11 +82,11 @@ func (p FormatV1) Sum(data []byte) (*Cid, error) {
82
82
return NewCidV1 (p .Codec , hash ), nil
83
83
}
84
84
85
- func (p FormatV1 ) GetCodec () uint64 {
85
+ func (p V1Builder ) GetCodec () uint64 {
86
86
return p .Codec
87
87
}
88
88
89
- func (p FormatV1 ) WithCodec (c uint64 ) Format {
89
+ func (p V1Builder ) WithCodec (c uint64 ) Builder {
90
90
p .Codec = c
91
91
return p
92
92
}
0 commit comments