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
8b9ff390
Unverified
Commit
8b9ff390
authored
Jul 23, 2020
by
Whyrusleeping
Committed by
GitHub
Jul 23, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #109 from ipfs/feat/optimize-prefix
feat: optimize cid.Prefix
parents
85cd3087
f7cb4c91
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
5 deletions
+22
-5
cid.go
cid.go
+22
-5
No files found.
cid.go
View file @
8b9ff390
...
...
@@ -518,12 +518,29 @@ func (c Cid) Loggable() map[string]interface{} {
// Prefix builds and returns a Prefix out of a Cid.
func
(
c
Cid
)
Prefix
()
Prefix
{
dec
,
_
:=
mh
.
Decode
(
c
.
Hash
())
// assuming we got a valid multiaddr, this will not error
if
c
.
Version
()
==
0
{
return
Prefix
{
MhType
:
mh
.
SHA2_256
,
MhLength
:
32
,
Version
:
0
,
Codec
:
DagProtobuf
,
}
}
offset
:=
0
version
,
n
,
_
:=
uvarint
(
c
.
str
[
offset
:
])
offset
+=
n
codec
,
n
,
_
:=
uvarint
(
c
.
str
[
offset
:
])
offset
+=
n
mhtype
,
n
,
_
:=
uvarint
(
c
.
str
[
offset
:
])
offset
+=
n
mhlen
,
_
,
_
:=
uvarint
(
c
.
str
[
offset
:
])
return
Prefix
{
MhType
:
dec
.
Cod
e
,
MhLength
:
dec
.
Length
,
Version
:
c
.
V
ersion
()
,
Codec
:
c
.
Type
()
,
MhType
:
mhtyp
e
,
MhLength
:
int
(
mhlen
)
,
Version
:
v
ersion
,
Codec
:
c
odec
,
}
}
...
...
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