Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
0796c1c3
Commit
0796c1c3
authored
Jan 20, 2012
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
encoding/varint: deleted WriteXvarint
Fixes #2748. R=rsc, r, r CC=golang-dev
https://golang.org/cl/5557072
parent
6923f6d1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
41 deletions
+8
-41
src/pkg/encoding/binary/varint.go
src/pkg/encoding/binary/varint.go
+0
-17
src/pkg/encoding/binary/varint_test.go
src/pkg/encoding/binary/varint_test.go
+8
-24
No files found.
src/pkg/encoding/binary/varint.go
View file @
0796c1c3
...
...
@@ -98,14 +98,6 @@ func Varint(buf []byte) (int64, int) {
return
x
,
n
}
// WriteUvarint encodes x and writes the result to w.
func
WriteUvarint
(
w
io
.
Writer
,
x
uint64
)
error
{
var
buf
[
MaxVarintLen64
]
byte
n
:=
PutUvarint
(
buf
[
:
],
x
)
_
,
err
:=
w
.
Write
(
buf
[
0
:
n
])
return
err
}
var
overflow
=
errors
.
New
(
"binary: varint overflows a 64-bit integer"
)
// ReadUvarint reads an encoded unsigned integer from r and returns it as a uint64.
...
...
@@ -129,15 +121,6 @@ func ReadUvarint(r io.ByteReader) (uint64, error) {
panic
(
"unreachable"
)
}
// WriteVarint encodes x and writes the result to w.
func
WriteVarint
(
w
io
.
Writer
,
x
int64
)
error
{
ux
:=
uint64
(
x
)
<<
1
if
x
<
0
{
ux
=
^
ux
}
return
WriteUvarint
(
w
,
ux
)
}
// ReadVarint reads an encoded unsigned integer from r and returns it as a uint64.
func
ReadVarint
(
r
io
.
ByteReader
)
(
int64
,
error
)
{
ux
,
err
:=
ReadUvarint
(
r
)
// ok to continue in presence of error
...
...
src/pkg/encoding/binary/varint_test.go
View file @
0796c1c3
...
...
@@ -25,9 +25,9 @@ func TestConstants(t *testing.T) {
}
func
testVarint
(
t
*
testing
.
T
,
x
int64
)
{
buf
1
:=
make
([]
byte
,
MaxVarintLen64
)
n
:=
PutVarint
(
buf
1
[
:
]
,
x
)
y
,
m
:=
Varint
(
buf
1
[
0
:
n
])
buf
:=
make
([]
byte
,
MaxVarintLen64
)
n
:=
PutVarint
(
buf
,
x
)
y
,
m
:=
Varint
(
buf
[
0
:
n
])
if
x
!=
y
{
t
.
Errorf
(
"Varint(%d): got %d"
,
x
,
y
)
}
...
...
@@ -35,15 +35,7 @@ func testVarint(t *testing.T, x int64) {
t
.
Errorf
(
"Varint(%d): got n = %d; want %d"
,
x
,
m
,
n
)
}
var
buf2
bytes
.
Buffer
err
:=
WriteVarint
(
&
buf2
,
x
)
if
err
!=
nil
{
t
.
Errorf
(
"WriteVarint(%d): %s"
,
x
,
err
)
}
if
n
!=
buf2
.
Len
()
{
t
.
Errorf
(
"WriteVarint(%d): got n = %d; want %d"
,
x
,
buf2
.
Len
(),
n
)
}
y
,
err
=
ReadVarint
(
&
buf2
)
y
,
err
:=
ReadVarint
(
bytes
.
NewBuffer
(
buf
))
if
err
!=
nil
{
t
.
Errorf
(
"ReadVarint(%d): %s"
,
x
,
err
)
}
...
...
@@ -53,9 +45,9 @@ func testVarint(t *testing.T, x int64) {
}
func
testUvarint
(
t
*
testing
.
T
,
x
uint64
)
{
buf
1
:=
make
([]
byte
,
MaxVarintLen64
)
n
:=
PutUvarint
(
buf
1
[
:
]
,
x
)
y
,
m
:=
Uvarint
(
buf
1
[
0
:
n
])
buf
:=
make
([]
byte
,
MaxVarintLen64
)
n
:=
PutUvarint
(
buf
,
x
)
y
,
m
:=
Uvarint
(
buf
[
0
:
n
])
if
x
!=
y
{
t
.
Errorf
(
"Uvarint(%d): got %d"
,
x
,
y
)
}
...
...
@@ -63,15 +55,7 @@ func testUvarint(t *testing.T, x uint64) {
t
.
Errorf
(
"Uvarint(%d): got n = %d; want %d"
,
x
,
m
,
n
)
}
var
buf2
bytes
.
Buffer
err
:=
WriteUvarint
(
&
buf2
,
x
)
if
err
!=
nil
{
t
.
Errorf
(
"WriteUvarint(%d): %s"
,
x
,
err
)
}
if
n
!=
buf2
.
Len
()
{
t
.
Errorf
(
"WriteUvarint(%d): got n = %d; want %d"
,
x
,
buf2
.
Len
(),
n
)
}
y
,
err
=
ReadUvarint
(
&
buf2
)
y
,
err
:=
ReadUvarint
(
bytes
.
NewBuffer
(
buf
))
if
err
!=
nil
{
t
.
Errorf
(
"ReadUvarint(%d): %s"
,
x
,
err
)
}
...
...
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