fix: make data io::Read
This commit is contained in:
parent
77b3680ff8
commit
910c75ad12
3 changed files with 56 additions and 2 deletions
20
.devcontainer/devcontainer.json
Normal file
20
.devcontainer/devcontainer.json
Normal file
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"image": "gcr.io/crosvm-infra/crosvm_dev:latest",
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"rust-lang.rust-analyzer",
|
||||
"tamasfe.even-better-toml",
|
||||
"esbenp.prettier-vscode",
|
||||
"ms-python.vscode-pylance",
|
||||
"foxundermoon.shell-format",
|
||||
"timonwong.shellcheck"
|
||||
]
|
||||
}
|
||||
},
|
||||
"runArgs": [
|
||||
// Allow a higher PID limit since we launch a lot of test processes.
|
||||
"--pids-limit=4096"
|
||||
],
|
||||
"updateContentCommand": "git config --global --add safe.directory '*' && git submodule update --init"
|
||||
}
|
23
.devcontainer/with_kvm/devcontainer.json
Normal file
23
.devcontainer/with_kvm/devcontainer.json
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"image": "gcr.io/crosvm-infra/crosvm_dev:latest",
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"rust-lang.rust-analyzer",
|
||||
"tamasfe.even-better-toml",
|
||||
"esbenp.prettier-vscode",
|
||||
"ms-python.vscode-pylance",
|
||||
"foxundermoon.shell-format",
|
||||
"timonwong.shellcheck"
|
||||
]
|
||||
}
|
||||
},
|
||||
"runArgs": [
|
||||
// Allow access to the kvm device so we can run VMs for testing
|
||||
"--device=/dev/kvm",
|
||||
"--group-add=kvm",
|
||||
// Allow a higher PID limit since we launch a lot of test processes.
|
||||
"--pids-limit=4096"
|
||||
],
|
||||
"updateContentCommand": "git config --global --add safe.directory '*' && git submodule update --init"
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use bytes::Buf;
|
||||
use std::fmt;
|
||||
use std::io;
|
||||
use std::io::ErrorKind;
|
||||
|
@ -318,10 +319,9 @@ impl<T: WireFormat> WireFormat for io::Result<T> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
impl io::Read for Data {
|
||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
self.0.read(buf)
|
||||
self.0.reader().read(buf)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -848,4 +848,15 @@ mod test {
|
|||
.expect("failed to decode value")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_io_read_for_data() {
|
||||
let mut data =
|
||||
Data(vec![0x8b, 0xad, 0xf0, 0x0d, 0x0d, 0xf0, 0xad, 0x8b]);
|
||||
let mut buf = [0; 8];
|
||||
|
||||
let _ = io::Read::read_exact(&mut data, &mut buf);
|
||||
|
||||
assert_eq!(buf, [0x8b, 0xad, 0xf0, 0x0d, 0x0d, 0xf0, 0xad, 0x8b]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue