Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bytes-sgx
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Markus Becker
bytes-sgx
Commits
7b63fa03
Commit
7b63fa03
authored
9 years ago
by
Jamie Turner
Browse files
Options
Downloads
Patches
Plain Diff
Add resume() method to ByteBuf that restores prior write position.
parent
d2b4cc38
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/buf/byte.rs
+8
-0
8 additions, 0 deletions
src/buf/byte.rs
test/test_byte_buf.rs
+9
-0
9 additions, 0 deletions
test/test_byte_buf.rs
with
17 additions
and
0 deletions
src/buf/byte.rs
+
8
−
0
View file @
7b63fa03
...
...
@@ -88,6 +88,14 @@ impl ByteBuf {
buf
}
/// Flips the buffer back to mutable, resetting the write position
/// to the byte after the previous write.
pub
fn
resume
(
mut
self
)
->
MutByteBuf
{
self
.pos
=
self
.lim
;
self
.lim
=
self
.cap
;
MutByteBuf
{
buf
:
self
}
}
pub
fn
read_slice
(
&
mut
self
,
dst
:
&
mut
[
u8
])
->
usize
{
let
len
=
cmp
::
min
(
dst
.len
(),
self
.remaining
());
let
cnt
=
len
as
u32
;
...
...
This diff is collapsed.
Click to expand it.
test/test_byte_buf.rs
+
9
−
0
View file @
7b63fa03
...
...
@@ -47,4 +47,13 @@ pub fn test_byte_buf_read_write() {
let
mut
dst
=
[
0
;
7
];
assert_eq!
(
7
,
buf
.read
(
&
mut
dst
[
..
])
.unwrap
());
assert_eq!
(
b"goodbye"
,
&
dst
);
let
mut
buf
=
buf
.resume
();
assert_eq!
(
13
,
buf
.remaining
());
buf
.write
(
&
b" have fun"
[
..
])
.unwrap
();
assert_eq!
(
4
,
buf
.remaining
());
let
buf
=
buf
.flip
();
assert_eq!
(
buf
.bytes
(),
b"hello world goodbye have fun"
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment