Skip to content
This repository was archived by the owner on Dec 15, 2021. It is now read-only.

Commit 6b25d2d

Browse files
author
Alex Helfet
committed
Drop heapless to support rust stable.
See: #11 (comment)
1 parent d62dd29 commit 6b25d2d

File tree

5 files changed

+27
-42
lines changed

5 files changed

+27
-42
lines changed

Cargo.lock

Lines changed: 0 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ chrono = "^0.4"
1414
clap = "^2.14.0"
1515
env_logger = "^0.4.3"
1616
error-chain = "^0.11.0"
17-
heapless = "^0.2.1"
1817
libc = "^0.2.17"
1918
log = "^0.3.8"
2019
ref_slice = "^1.1.0"

src/decoder.rs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Parse ITM packets from bytes and streams.
22
33
use error::{Error, ErrorKind, Result};
4-
use heapless::Vec as HVec;
54
use packet::{self, Packet, Instrumentation};
65
use std::io::{self, Cursor, Read};
76

@@ -39,27 +38,30 @@ impl<R: Read> Decoder<R> {
3938
match header & 0b111 {
4039
0b001|0b010|0b011 => {
4140
// Instrumentation packet.
42-
let mut ud = Instrumentation {
43-
payload: HVec::new(),
44-
port: header >> 3,
45-
};
46-
47-
let payload_size =
41+
let payload_len =
4842
match header & 0b11 {
4943
0b01 => 1,
5044
0b10 => 2,
5145
0b11 => 4,
5246
_ => unreachable!(), // Contradicts match on last 3 bits.
5347
};
54-
ud.payload.resize_default(payload_size)
55-
.expect("payload_size <= payload.capacity");
56-
match self.inner.read_exact(&mut *ud.payload) {
57-
Err(ref e) if e.kind() == io::ErrorKind::UnexpectedEof =>
58-
return Err(Error::from(ErrorKind::EofDuringPacket)),
59-
Err(e) => return Err(Error::from(e)),
60-
Ok(_) => (),
48+
49+
let mut ud = Instrumentation {
50+
payload: [0; packet::MAX_PAYLOAD_SIZE],
51+
payload_len: payload_len,
52+
port: header >> 3,
6153
};
6254

55+
{ // Scope the mutable borrow on buf to satisfy borrow checker.
56+
let buf = &mut ud.payload[0..payload_len];
57+
match self.inner.read_exact(buf) {
58+
Err(ref e) if e.kind() == io::ErrorKind::UnexpectedEof =>
59+
return Err(Error::from(ErrorKind::EofDuringPacket)),
60+
Err(e) => return Err(Error::from(e)),
61+
Ok(_) => (),
62+
};
63+
}
64+
6365
Ok(Packet {
6466
header: header,
6567
kind: packet::Kind::Instrumentation(ud),
@@ -95,7 +97,7 @@ mod tests {
9597
let p = decode_one(&[0x01, 0x11]);
9698
match p.kind {
9799
Kind::Instrumentation(ref i) => {
98-
assert_eq!(*i.payload, [0x11]);
100+
assert_eq!(i.payload(), [0x11]);
99101
},
100102
_ => panic!()
101103
}
@@ -106,7 +108,7 @@ mod tests {
106108
let p = decode_one(&[0x02, 0x11, 0x12]);
107109
match p.kind {
108110
Kind::Instrumentation(ref i) => {
109-
assert_eq!(*i.payload, [0x11, 0x12]);
111+
assert_eq!(i.payload(), [0x11, 0x12]);
110112
},
111113
_ => panic!()
112114
}
@@ -117,7 +119,7 @@ mod tests {
117119
let p = decode_one(&[0x03, 0x11, 0x12, 0x13, 0x14]);
118120
match p.kind {
119121
Kind::Instrumentation(ref i) => {
120-
assert_eq!(*i.payload, [0x11, 0x12, 0x13, 0x14]);
122+
assert_eq!(i.payload(), [0x11, 0x12, 0x13, 0x14]);
121123
},
122124
_ => panic!()
123125
}
@@ -128,15 +130,15 @@ mod tests {
128130
let p = decode_one(&[0b00000_001, 0x11]);
129131
match p.kind {
130132
Kind::Instrumentation(ref i) => {
131-
assert_eq!(i.port, 0);
133+
assert_eq!(i.port(), 0);
132134
},
133135
_ => panic!()
134136
}
135137

136138
let p = decode_one(&[0b11111_001, 0x11]);
137139
match p.kind {
138140
Kind::Instrumentation(ref i) => {
139-
assert_eq!(i.port, 31);
141+
assert_eq!(i.port(), 31);
140142
},
141143
_ => panic!()
142144
}

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090

9191
#[macro_use]
9292
extern crate error_chain;
93-
extern crate heapless;
9493
#[allow(unused_imports)] // No logging yet.
9594
#[macro_use]
9695
extern crate log;

src/packet.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Defines ITM packets and their possible contents.
22
3-
use heapless::Vec as HVec;
4-
53
pub const MAX_PAYLOAD_SIZE: usize = 4;
64

75
/// Represents a complete received packet.
@@ -41,8 +39,11 @@ pub enum Kind {
4139
/// Contents of an Instrumentation packet, with data from a software application
4240
#[derive(Debug)]
4341
pub struct Instrumentation {
44-
/// Data in this packet.
45-
pub(crate) payload: HVec<u8, [u8; MAX_PAYLOAD_SIZE]>,
42+
/// Contains the data in this packet.
43+
pub(crate) payload: [u8; MAX_PAYLOAD_SIZE],
44+
45+
/// The length of `payload` that contains the relevant data.
46+
pub(crate) payload_len: usize,
4647

4748
/// Stimulus port this packet was sent from.
4849
pub(crate) port: u8,
@@ -51,7 +52,7 @@ pub struct Instrumentation {
5152
impl Instrumentation {
5253
/// Data in this packet.
5354
pub fn payload(&self) -> &[u8] {
54-
&*self.payload
55+
&self.payload[0..self.payload_len]
5556
}
5657

5758
/// Stimulus port this packet was sent from.

0 commit comments

Comments
 (0)