Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
472e191a
Commit
472e191a
authored
May 15, 2009
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ByteBuffer.WriteByte
R=r DELTA=17 (10 added, 0 deleted, 7 changed) OCL=28860 CL=28862
parent
8203a4cb
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
7 deletions
+17
-7
bytebuffer.go
src/lib/io/bytebuffer.go
+7
-0
bytebuffer_test.go
src/lib/io/bytebuffer_test.go
+10
-7
No files found.
src/lib/io/bytebuffer.go
View file @
472e191a
...
@@ -74,6 +74,13 @@ func (b *ByteBuffer) Write(p []byte) (n int, err os.Error) {
...
@@ -74,6 +74,13 @@ func (b *ByteBuffer) Write(p []byte) (n int, err os.Error) {
return
n
,
nil
return
n
,
nil
}
}
// WriteByte appends the byte c to the buffer.
// Because Write never fails and WriteByte is not part of the
// io.Writer interface, it does not need to return a value.
func
(
b
*
ByteBuffer
)
WriteByte
(
c
byte
)
{
b
.
Write
([]
byte
{
c
});
}
// Read reads the next len(p) bytes from the buffer or until the buffer
// Read reads the next len(p) bytes from the buffer or until the buffer
// is drained. The return value n is the number of bytes read; err is always nil.
// is drained. The return value n is the number of bytes read; err is always nil.
func
(
b
*
ByteBuffer
)
Read
(
p
[]
byte
)
(
n
int
,
err
os
.
Error
)
{
func
(
b
*
ByteBuffer
)
Read
(
p
[]
byte
)
(
n
int
,
err
os
.
Error
)
{
...
...
src/lib/io/bytebuffer_test.go
View file @
472e191a
...
@@ -101,20 +101,23 @@ func TestBasicOperations(t *testing.T) {
...
@@ -101,20 +101,23 @@ func TestBasicOperations(t *testing.T) {
}
}
check
(
t
,
"TestBasicOperations (4)"
,
&
buf
,
"a"
);
check
(
t
,
"TestBasicOperations (4)"
,
&
buf
,
"a"
);
n
,
err
=
buf
.
Write
(
data
[
1
:
26
]);
buf
.
WriteByte
(
data
[
1
]);
if
n
!=
25
{
check
(
t
,
"TestBasicOperations (5)"
,
&
buf
,
"ab"
);
n
,
err
=
buf
.
Write
(
data
[
2
:
26
]);
if
n
!=
24
{
t
.
Errorf
(
"wrote 25 bytes, but n == %d
\n
"
,
n
);
t
.
Errorf
(
"wrote 25 bytes, but n == %d
\n
"
,
n
);
}
}
check
(
t
,
"TestBasicOperations (
5
)"
,
&
buf
,
string
(
data
[
0
:
26
]));
check
(
t
,
"TestBasicOperations (
6
)"
,
&
buf
,
string
(
data
[
0
:
26
]));
buf
.
Truncate
(
26
);
buf
.
Truncate
(
26
);
check
(
t
,
"TestBasicOperations (
6
)"
,
&
buf
,
string
(
data
[
0
:
26
]));
check
(
t
,
"TestBasicOperations (
7
)"
,
&
buf
,
string
(
data
[
0
:
26
]));
buf
.
Truncate
(
20
);
buf
.
Truncate
(
20
);
check
(
t
,
"TestBasicOperations (
7
)"
,
&
buf
,
string
(
data
[
0
:
20
]));
check
(
t
,
"TestBasicOperations (
8
)"
,
&
buf
,
string
(
data
[
0
:
20
]));
empty
(
t
,
"TestBasicOperations (
8
)"
,
&
buf
,
string
(
data
[
0
:
20
]),
make
([]
byte
,
5
));
empty
(
t
,
"TestBasicOperations (
9
)"
,
&
buf
,
string
(
data
[
0
:
20
]),
make
([]
byte
,
5
));
empty
(
t
,
"TestBasicOperations (
9
)"
,
&
buf
,
""
,
make
([]
byte
,
100
));
empty
(
t
,
"TestBasicOperations (
10
)"
,
&
buf
,
""
,
make
([]
byte
,
100
));
}
}
}
}
...
...
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