Skip to content

Commit 60b2884

Browse files
committed
Use lz4_flex instead of lz-fear
1 parent f93934f commit 60b2884

File tree

3 files changed

+16
-46
lines changed

3 files changed

+16
-46
lines changed

Cargo.lock

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

bytecode/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ license = "MIT"
1111
[dependencies]
1212
bincode = "1.1"
1313
bitflags = "1.1"
14-
lz-fear = "0.1"
14+
lz4_flex = "0.4"
1515
num-bigint = { version = "0.3", features = ["serde"] }
1616
num-complex = { version = "0.3", features = ["serde"] }
1717
serde = { version = "1.0", features = ["derive"] }

bytecode/src/bytecode.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -721,18 +721,21 @@ impl<C: Constant> CodeObject<C> {
721721
impl CodeObject<ConstantData> {
722722
/// Load a code object from bytes
723723
pub fn from_bytes(data: &[u8]) -> Result<Self, Box<dyn std::error::Error>> {
724-
let reader = lz_fear::framed::LZ4FrameReader::new(data)?;
725-
Ok(bincode::deserialize_from(reader.into_read())?)
724+
// TODO: PR to lz4_flex to make it not panic
725+
if data.len() < 4 {
726+
return Err(
727+
std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "bad bytecode").into(),
728+
);
729+
}
730+
let raw_bincode = lz4_flex::decompress_size_prepended(data)?;
731+
let data = bincode::deserialize(&raw_bincode)?;
732+
Ok(data)
726733
}
727734

728735
/// Serialize this bytecode to bytes.
729736
pub fn to_bytes(&self) -> Vec<u8> {
730737
let data = bincode::serialize(&self).expect("CodeObject is not serializable");
731-
let mut out = Vec::new();
732-
lz_fear::framed::CompressionSettings::default()
733-
.compress_with_size_unchecked(data.as_slice(), &mut out, data.len() as u64)
734-
.unwrap();
735-
out
738+
lz4_flex::compress_prepend_size(&data)
736739
}
737740
}
738741

0 commit comments

Comments
 (0)