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

Commit d70a1d4

Browse files
author
Alex Helfet
committed
Added itm::decoder::from_slice(), inspired by serde_json::from_slice().
1 parent 5303d4a commit d70a1d4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/decoder.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use error::{Error, ErrorKind, Result};
44
use heapless::Vec as HVec;
55
use packet::{self, Packet, Instrumentation};
6-
use std::io::Read;
6+
use std::io::{Cursor, Read};
77

88
/// Parses ITM packets.
99
pub struct Decoder<R: Read> {
@@ -63,3 +63,9 @@ impl<R: Read> Decoder<R> {
6363
}
6464

6565
// TODO: Parse tests.
66+
/// Decode a single packet from a slice of bytes.
67+
pub fn from_slice(s: &[u8]) -> Result<Packet> {
68+
let mut d = Decoder::new(Cursor::new(Vec::from(s)));
69+
d.read_packet()
70+
}
71+

0 commit comments

Comments
 (0)