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-cidutil
Commits
8fca9c23
Commit
8fca9c23
authored
Aug 10, 2018
by
Kevin Atkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allocate bytes.Buffer directly on the stack.
parent
2bc018ba
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
7 deletions
+7
-7
format.go
format.go
+7
-7
No files found.
format.go
View file @
8fca9c23
...
...
@@ -36,7 +36,7 @@ used. For Cid version 1 the multibase prefix is included.
// documented in the FormatRef constant
func
Format
(
fmtStr
string
,
base
mb
.
Encoding
,
cid
*
Cid
)
(
string
,
error
)
{
p
:=
cid
.
Prefix
()
out
:=
new
(
bytes
.
Buffer
)
var
out
bytes
.
Buffer
var
err
error
encoder
,
err
:=
mb
.
NewEncoder
(
base
)
if
err
!=
nil
{
...
...
@@ -59,19 +59,19 @@ func Format(fmtStr string, base mb.Encoding, cid *Cid) (string, error) {
case
'B'
:
// base code
out
.
WriteByte
(
byte
(
base
))
case
'v'
:
// version string
fmt
.
Fprintf
(
out
,
"cidv%d"
,
p
.
Version
)
fmt
.
Fprintf
(
&
out
,
"cidv%d"
,
p
.
Version
)
case
'V'
:
// version num
fmt
.
Fprintf
(
out
,
"%d"
,
p
.
Version
)
fmt
.
Fprintf
(
&
out
,
"%d"
,
p
.
Version
)
case
'c'
:
// codec name
out
.
WriteString
(
codecToString
(
p
.
Codec
))
case
'C'
:
// codec code
fmt
.
Fprintf
(
out
,
"%d"
,
p
.
Codec
)
fmt
.
Fprintf
(
&
out
,
"%d"
,
p
.
Codec
)
case
'h'
:
// hash fun name
out
.
WriteString
(
hashToString
(
p
.
MhType
))
case
'H'
:
// hash fun code
fmt
.
Fprintf
(
out
,
"%d"
,
p
.
MhType
)
fmt
.
Fprintf
(
&
out
,
"%d"
,
p
.
MhType
)
case
'L'
:
// hash length
fmt
.
Fprintf
(
out
,
"%d"
,
p
.
MhLength
)
fmt
.
Fprintf
(
&
out
,
"%d"
,
p
.
MhLength
)
case
'm'
,
'M'
:
// multihash encoded in base %b
out
.
WriteString
(
encode
(
encoder
,
cid
.
Hash
(),
fmtStr
[
i
]
==
'M'
))
case
'd'
,
'D'
:
// hash digest encoded in base %b
...
...
@@ -89,7 +89,7 @@ func Format(fmtStr string, base mb.Encoding, cid *Cid) (string, error) {
case
'S'
:
// cid string without base prefix
out
.
WriteString
(
encode
(
encoder
,
cid
.
Bytes
(),
true
))
case
'P'
:
// prefix
fmt
.
Fprintf
(
out
,
"cidv%d-%s-%s-%d"
,
fmt
.
Fprintf
(
&
out
,
"cidv%d-%s-%s-%d"
,
p
.
Version
,
codecToString
(
p
.
Codec
),
hashToString
(
p
.
MhType
),
...
...
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