Skip to content

Commit

Permalink
Make binary label format (_010101) translate back from assembly to wh…
Browse files Browse the repository at this point in the history
…itespace, so it round trips better.
  • Loading branch information
CensoredUsername committed Dec 12, 2024
1 parent 9acc85f commit f7d1fe1
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,17 @@ impl fmt::Display for Label {

impl<'a> From<&'a [u8]> for Label {
fn from(buffer: &[u8]) -> Label {
let mut buffer = Vec::from(buffer);
buffer.push(0);
Label {bits: 0, buffer: buffer}
if buffer.starts_with(b"_") && buffer[1..].iter().all(|&x| x == b'1' || x == b'0') {
let mut label = Label::new();
for character in buffer[1..].iter() {
label.push(*character == b'1');
}
label
} else {
let mut buffer = Vec::from(buffer);
buffer.push(0);
Label {bits: 0, buffer: buffer}
}
}
}

Expand Down

0 comments on commit f7d1fe1

Please sign in to comment.