From e9c88e32e6ba9f7684ad2bbe4a6eeed10d075eb5 Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 14 May 2018 13:06:28 +0000 Subject: [PATCH] firmware: migrate moninj_proto to new libio. --- artiq/firmware/libdrtioaux/lib.rs | 2 +- artiq/firmware/libproto/mgmt_proto.rs | 2 +- artiq/firmware/libproto/moninj_proto.rs | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/artiq/firmware/libdrtioaux/lib.rs b/artiq/firmware/libdrtioaux/lib.rs index 9c26144ef..bed9bddf7 100644 --- a/artiq/firmware/libdrtioaux/lib.rs +++ b/artiq/firmware/libdrtioaux/lib.rs @@ -45,7 +45,7 @@ pub enum Packet { } impl Packet { - pub fn read_from(reader: &mut T) -> Result { + pub fn read_from(reader: &mut T) -> Result { Ok(match reader.read_u8()? { 0x00 => Packet::EchoRequest, 0x01 => Packet::EchoReply, diff --git a/artiq/firmware/libproto/mgmt_proto.rs b/artiq/firmware/libproto/mgmt_proto.rs index 44e6b09dc..569a24104 100644 --- a/artiq/firmware/libproto/mgmt_proto.rs +++ b/artiq/firmware/libproto/mgmt_proto.rs @@ -41,7 +41,7 @@ pub enum Reply<'a> { } impl Request { - pub fn read_from(reader: &mut T) -> Result { + pub fn read_from(reader: &mut T) -> Result { #[cfg(feature = "log")] fn read_log_level_filter(reader: &mut T) -> Result { diff --git a/artiq/firmware/libproto/moninj_proto.rs b/artiq/firmware/libproto/moninj_proto.rs index de233d3c0..32a833a97 100644 --- a/artiq/firmware/libproto/moninj_proto.rs +++ b/artiq/firmware/libproto/moninj_proto.rs @@ -1,5 +1,5 @@ -use std::io::{self, Read, Write}; -use {ReadExt, WriteExt}; +use io::{Read, Write, Error, Result}; +use io::proto::{ProtoRead, ProtoWrite}; #[derive(Debug)] pub enum HostMessage { @@ -15,7 +15,7 @@ pub enum DeviceMessage { } impl HostMessage { - pub fn read_from(reader: &mut Read) -> io::Result { + pub fn read_from(reader: &mut T) -> Result { Ok(match reader.read_u8()? { 0 => HostMessage::Monitor { enable: if reader.read_u8()? == 0 { false } else { true }, @@ -31,13 +31,13 @@ impl HostMessage { channel: reader.read_u32()?, overrd: reader.read_u8()? }, - _ => return Err(io::Error::new(io::ErrorKind::InvalidData, "unknown packet type")) + _ => return Err(Error::Unrecognized) }) } } impl DeviceMessage { - pub fn write_to(&self, writer: &mut Write) -> io::Result<()> { + pub fn write_to(&self, writer: &mut T) -> Result<(), T::WriteError> { match *self { DeviceMessage::MonitorStatus { channel, probe, value } => { writer.write_u8(0)?;