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
dms3
go-cid
Commits
ad88cb11
Commit
ad88cb11
authored
Aug 09, 2018
by
Kevin Atkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename Format to Builder.
parent
88cd5dce
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
19 deletions
+18
-19
builder.go
builder.go
+15
-15
builder_test.go
builder_test.go
+2
-3
cid.go
cid.go
+1
-1
No files found.
format
.go
→
builder
.go
View file @
ad88cb11
...
...
@@ -4,23 +4,23 @@ import (
mh
"github.com/multiformats/go-multihash"
)
type
Format
interface
{
type
Builder
interface
{
Sum
(
data
[]
byte
)
(
*
Cid
,
error
)
GetCodec
()
uint64
WithCodec
(
uint64
)
Format
WithCodec
(
uint64
)
Builder
}
type
FormatV0
struct
{}
type
V0Builder
struct
{}
type
FormatV1
struct
{
type
V1Builder
struct
{
Codec
uint64
HashFun
uint64
HashLen
int
// HashLen <= 0 means the default length
}
func
PrefixTo
Format
(
p
Prefix
)
Format
{
func
PrefixTo
Builder
(
p
Prefix
)
Builder
{
if
p
.
Version
==
0
{
return
FormatV0
{}
return
V0Builder
{}
}
mhLen
:=
p
.
MhLength
if
p
.
MhType
==
mh
.
ID
{
...
...
@@ -29,7 +29,7 @@ func PrefixToFormat(p Prefix) Format {
if
mhLen
<
0
{
mhLen
=
0
}
return
FormatV1
{
return
V1Builder
{
Codec
:
p
.
Codec
,
HashFun
:
p
.
MhType
,
HashLen
:
mhLen
,
...
...
@@ -40,7 +40,7 @@ func (p Prefix) GetCodec() uint64 {
return
p
.
Codec
}
func
(
p
Prefix
)
WithCodec
(
c
uint64
)
Format
{
func
(
p
Prefix
)
WithCodec
(
c
uint64
)
Builder
{
if
c
==
p
.
Codec
{
return
p
}
...
...
@@ -51,7 +51,7 @@ func (p Prefix) WithCodec(c uint64) Format {
return
p
}
func
(
p
FormatV0
)
Sum
(
data
[]
byte
)
(
*
Cid
,
error
)
{
func
(
p
V0Builder
)
Sum
(
data
[]
byte
)
(
*
Cid
,
error
)
{
hash
,
err
:=
mh
.
Sum
(
data
,
mh
.
SHA2_256
,
-
1
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -59,18 +59,18 @@ func (p FormatV0) Sum(data []byte) (*Cid, error) {
return
NewCidV0
(
hash
),
nil
}
func
(
p
FormatV0
)
GetCodec
()
uint64
{
func
(
p
V0Builder
)
GetCodec
()
uint64
{
return
DagProtobuf
}
func
(
p
FormatV0
)
WithCodec
(
c
uint64
)
Format
{
func
(
p
V0Builder
)
WithCodec
(
c
uint64
)
Builder
{
if
c
==
DagProtobuf
{
return
p
}
return
FormatV1
{
Codec
:
c
,
HashFun
:
mh
.
SHA2_256
}
return
V1Builder
{
Codec
:
c
,
HashFun
:
mh
.
SHA2_256
}
}
func
(
p
FormatV1
)
Sum
(
data
[]
byte
)
(
*
Cid
,
error
)
{
func
(
p
V1Builder
)
Sum
(
data
[]
byte
)
(
*
Cid
,
error
)
{
mhLen
:=
p
.
HashLen
if
mhLen
<=
0
{
mhLen
=
-
1
...
...
@@ -82,11 +82,11 @@ func (p FormatV1) Sum(data []byte) (*Cid, error) {
return
NewCidV1
(
p
.
Codec
,
hash
),
nil
}
func
(
p
FormatV1
)
GetCodec
()
uint64
{
func
(
p
V1Builder
)
GetCodec
()
uint64
{
return
p
.
Codec
}
func
(
p
FormatV1
)
WithCodec
(
c
uint64
)
Format
{
func
(
p
V1Builder
)
WithCodec
(
c
uint64
)
Builder
{
p
.
Codec
=
c
return
p
}
format
_test.go
→
builder
_test.go
View file @
ad88cb11
...
...
@@ -10,7 +10,7 @@ func TestFormatV1(t *testing.T) {
data
:=
[]
byte
(
"this is some test content"
)
// Construct c1
format
:=
FormatV1
{
Codec
:
DagCBOR
,
HashFun
:
mh
.
SHA2_256
}
format
:=
V1Builder
{
Codec
:
DagCBOR
,
HashFun
:
mh
.
SHA2_256
}
c1
,
err
:=
format
.
Sum
(
data
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -35,7 +35,7 @@ func TestFormatV0(t *testing.T) {
data
:=
[]
byte
(
"this is some test content"
)
// Construct c1
format
:=
FormatV0
{}
format
:=
V0Builder
{}
c1
,
err
:=
format
.
Sum
(
data
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -55,4 +55,3 @@ func TestFormatV0(t *testing.T) {
t
.
Fatal
(
"prefixes mismatch"
)
}
}
cid.go
View file @
ad88cb11
...
...
@@ -445,7 +445,7 @@ func (c *Cid) Prefix() Prefix {
// and the Multihash length. It does not contains
// any actual content information.
// NOTE: The use -1 in MhLength to mean default length is deprecated,
// use the
PrefixV0 or PrefixV1
structures instead
// use the
V0Builder or V1Builder
structures instead
type
Prefix
struct
{
Version
uint64
Codec
uint64
...
...
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