mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-25 11:18:27 +08:00
firmware: migrate mgmt_proto to new libio.
This commit is contained in:
parent
0c1caf0744
commit
e292c8ab65
@ -154,12 +154,12 @@ impl<T: AsRef<[u8]>> Read for Cursor<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: AsMut<[u8]>> Write for Cursor<T> {
|
||||
impl<'a> Write for Cursor<&'a mut [u8]> {
|
||||
type WriteError = !;
|
||||
type FlushError = !;
|
||||
|
||||
fn write(&mut self, buf: &[u8]) -> result::Result<usize, Self::WriteError> {
|
||||
let data = &mut self.inner.as_mut()[self.pos..];
|
||||
let data = &mut self.inner[self.pos..];
|
||||
let len = buf.len().min(data.len());
|
||||
data[..len].copy_from_slice(&buf[..len]);
|
||||
self.pos += len;
|
||||
@ -173,7 +173,7 @@ impl<T: AsMut<[u8]>> Write for Cursor<T> {
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl<T: ::alloc::Vec<[u8]>> Write for Cursor<T> {
|
||||
impl Write for Cursor<::alloc::Vec<u8>> {
|
||||
type WriteError = !;
|
||||
type FlushError = !;
|
||||
|
||||
|
@ -11,6 +11,6 @@ path = "lib.rs"
|
||||
byteorder = { version = "1.0", default-features = false }
|
||||
cslice = { version = "0.3" }
|
||||
log = { version = "0.4", default-features = false, optional = true }
|
||||
io = { path = "../libio", features = ["byteorder"] }
|
||||
io = { path = "../libio", features = ["byteorder", "alloc"] }
|
||||
std_artiq = { path = "../libstd_artiq", features = ["alloc"] }
|
||||
dyld = { path = "../libdyld" }
|
||||
|
@ -1,5 +1,7 @@
|
||||
#![no_std]
|
||||
#![feature(alloc)]
|
||||
|
||||
extern crate alloc;
|
||||
extern crate byteorder;
|
||||
extern crate cslice;
|
||||
#[cfg(feature = "log")]
|
||||
|
@ -1,9 +1,10 @@
|
||||
use std::vec::Vec;
|
||||
use std::io::{self, Read, Write};
|
||||
use {ReadExt, WriteExt};
|
||||
use alloc::vec::Vec;
|
||||
#[cfg(feature = "log")]
|
||||
use log;
|
||||
|
||||
use io::{Read, Write, Error, Result};
|
||||
use io::proto::{ProtoRead, ProtoWrite};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Request {
|
||||
GetLog,
|
||||
@ -40,9 +41,10 @@ pub enum Reply<'a> {
|
||||
}
|
||||
|
||||
impl Request {
|
||||
pub fn read_from(reader: &mut Read) -> io::Result<Request> {
|
||||
pub fn read_from<T: Read>(reader: &mut T) -> Result<Request, T::ReadError> {
|
||||
#[cfg(feature = "log")]
|
||||
fn read_log_level_filter(reader: &mut Read) -> io::Result<log::LevelFilter> {
|
||||
fn read_log_level_filter<T: Read>(reader: &mut T) ->
|
||||
Result<log::LevelFilter, T::ReadError> {
|
||||
Ok(match reader.read_u8()? {
|
||||
0 => log::LevelFilter::Off,
|
||||
1 => log::LevelFilter::Error,
|
||||
@ -50,8 +52,7 @@ impl Request {
|
||||
3 => log::LevelFilter::Info,
|
||||
4 => log::LevelFilter::Debug,
|
||||
5 => log::LevelFilter::Trace,
|
||||
_ => return Err(io::Error::new(io::ErrorKind::InvalidData,
|
||||
"invalid log level"))
|
||||
_ => return Err(Error::Unrecognized)
|
||||
})
|
||||
}
|
||||
|
||||
@ -73,13 +74,13 @@ impl Request {
|
||||
4 => Request::Hotswap(reader.read_bytes()?),
|
||||
5 => Request::Reboot,
|
||||
8 => Request::DebugAllocator,
|
||||
_ => return Err(io::Error::new(io::ErrorKind::InvalidData, "unknown request type"))
|
||||
_ => return Err(Error::Unrecognized)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Reply<'a> {
|
||||
pub fn write_to(&self, writer: &mut Write) -> io::Result<()> {
|
||||
pub fn write_to<T: Write>(&self, writer: &mut T) -> Result<(), T::WriteError> {
|
||||
match *self {
|
||||
Reply::Success => {
|
||||
writer.write_u8(1)?;
|
||||
|
Loading…
Reference in New Issue
Block a user