From f919dde67fb267fe07ae29aaf26487e8eefe182c Mon Sep 17 00:00:00 2001 From: tyb0807 Date: Thu, 2 Jan 2025 19:40:46 +0100 Subject: [PATCH] Decoder can take byte buffer instead of mmap + offset (#261) --- Cargo.lock | 1 - rs/compression/Cargo.toml | 1 - rs/compression/src/compression.rs | 3 +-- rs/compression/src/noc/noc.rs | 9 +++------ 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 48d58145..5edf8126 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -482,7 +482,6 @@ dependencies = [ "bitvec", "env_logger", "log", - "memmap2", "tempdir", "utils", ] diff --git a/rs/compression/Cargo.toml b/rs/compression/Cargo.toml index 7e171d60..bef3812f 100644 --- a/rs/compression/Cargo.toml +++ b/rs/compression/Cargo.toml @@ -8,6 +8,5 @@ anyhow.workspace = true bitvec = "1" env_logger.workspace = true log.workspace = true -memmap2.workspace = true tempdir.workspace = true utils.workspace = true diff --git a/rs/compression/src/compression.rs b/rs/compression/src/compression.rs index 652930a5..bd5fe1b8 100644 --- a/rs/compression/src/compression.rs +++ b/rs/compression/src/compression.rs @@ -2,7 +2,6 @@ use std::fs::File; use std::io::BufWriter; use anyhow::Result; -use memmap2::Mmap; pub trait IntSeqEncoder { /// Creates an encoder @@ -23,7 +22,7 @@ pub trait IntSeqEncoder { pub trait IntSeqDecoderIterator: Iterator { /// Creates a decoder - fn new_decoder(mmap: &Mmap, offset: usize, size: usize) -> Self + fn new_decoder(encoded_data: &[u8]) -> Self where Self: Sized; diff --git a/rs/compression/src/noc/noc.rs b/rs/compression/src/noc/noc.rs index 3bb012da..fdde20ba 100644 --- a/rs/compression/src/noc/noc.rs +++ b/rs/compression/src/noc/noc.rs @@ -2,9 +2,8 @@ use std::fs::File; use std::io::{BufWriter, Write}; use anyhow::Result; -use memmap2::Mmap; use utils::io::wrap_write; -use utils::mem::{get_ith_val_from_raw_ptr, transmute_u8_to_slice}; +use utils::mem::get_ith_val_from_raw_ptr; use crate::compression::{IntSeqDecoderIterator, IntSeqEncoder}; @@ -56,11 +55,9 @@ pub struct PlainDecoderIterator { } impl IntSeqDecoderIterator for PlainDecoderIterator { - fn new_decoder(mmap: &Mmap, offset: usize, size: usize) -> Self { - let slice = &mmap[offset..offset + size * size_of::()]; - let encoded_data = transmute_u8_to_slice::(slice); + fn new_decoder(encoded_data: &[u8]) -> Self { Self { - size, + size: encoded_data.len(), cur_index: 0, encoded_data_ptr: encoded_data.as_ptr() as *const u64, }