Skip to content

Commit

Permalink
refactor: copy c_char from libc instead of directly dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
negezor committed Apr 17, 2024
1 parent 9122e7a commit 2514d11
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions klickhouse/src/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ use crate::io::ClickhouseRead;
use crate::protocol::CompressionMethod;
use crate::{KlickhouseError, Result};

#[allow(non_camel_case_types)]
type c_char = i8;

pub async fn compress_block(block: Block, revision: u64) -> Result<(Vec<u8>, usize)> {
let mut raw = vec![];
block.write(&mut raw, revision).await?;
let raw_len = raw.len();
let mut compressed = Vec::<u8>::with_capacity(raw.len() + (raw.len() / 255) + 16 + 1);
let out_len = unsafe {
lz4::liblz4::LZ4_compress_default(
raw.as_ptr() as *const libc::c_char,
compressed.as_mut_ptr() as *mut libc::c_char,
raw.as_ptr() as *const c_char,
compressed.as_mut_ptr() as *mut c_char,
raw.len() as i32,
compressed.capacity() as i32,
)
Expand All @@ -42,8 +45,8 @@ pub fn decompress_block(data: &[u8], decompressed_size: u32) -> Result<Vec<u8>>

let out_len = unsafe {
lz4::liblz4::LZ4_decompress_safe(
data.as_ptr() as *const libc::c_char,
output.as_mut_ptr() as *mut libc::c_char,
data.as_ptr() as *const c_char,
output.as_mut_ptr() as *mut c_char,
data.len() as i32,
output.capacity() as i32,
)
Expand Down

0 comments on commit 2514d11

Please sign in to comment.