Add zstd-safe intermediate crate

zstd-safe provides a low-level safe rust API on top of zstd-sys.
This commit is contained in:
Alexandre Bury 2017-06-04 17:49:40 -07:00
parent 662e6494b9
commit c74083bd41
20 changed files with 1966 additions and 1019 deletions

4
.gitmodules vendored
View file

@ -1,3 +1,3 @@
[submodule "zstd"]
path = zstd-sys/zstd
[submodule "zstd-safe/zstd-sys/zstd"]
path = zstd-safe/zstd-sys/zstd
url = https://github.com/facebook/zstd

View file

@ -15,7 +15,7 @@ travis-ci = { repository = "gyscos/zstd-rs" }
[dependencies]
libc = "0.2"
zstd-sys = { path="zstd-sys", version = "1.2", default-features = false }
zstd-safe = { path="zstd-safe", version = "1.2", default-features = false }
tokio-io = { version = "0.1", optional = true }
futures = { version = "0.1", optional = true }
@ -26,6 +26,6 @@ quickcheck = "0.4"
[features]
default = ["legacy"]
legacy = ["zstd-sys/legacy"]
bindgen = ["zstd-sys/bindgen"]
legacy = ["zstd-safe/legacy"]
bindgen = ["zstd-safe/bindgen"]
tokio = ["tokio-io", "futures", "partial-io/quickcheck", "partial-io/tokio"]

View file

@ -1,25 +1,7 @@
use libc::c_void;
use parse_code;
use std::io;
use zstd_sys;
struct EncoderContext {
c: *mut zstd_sys::ZSTD_CCtx,
}
impl Default for EncoderContext {
fn default() -> Self {
EncoderContext { c: unsafe { zstd_sys::ZSTD_createCCtx() } }
}
}
impl Drop for EncoderContext {
fn drop(&mut self) {
let code = unsafe { zstd_sys::ZSTD_freeCCtx(self.c) };
parse_code(code).unwrap();
}
}
use zstd_safe;
/// Allows to compress independently multiple blocks of data.
///
@ -27,7 +9,7 @@ impl Drop for EncoderContext {
/// The compressed blocks are still completely independent.
#[derive(Default)]
pub struct Compressor {
context: EncoderContext,
context: zstd_safe::CCtx,
dict: Vec<u8>,
}
@ -40,7 +22,7 @@ impl Compressor {
/// Creates a new zstd compressor, using the given dictionary.
pub fn with_dict(dict: Vec<u8>) -> Self {
Compressor {
context: EncoderContext::default(),
context: zstd_safe::create_cctx(),
dict: dict,
}
}
@ -52,17 +34,12 @@ impl Compressor {
pub fn compress_to_buffer(&mut self, source: &[u8],
destination: &mut [u8], level: i32)
-> io::Result<usize> {
let code = unsafe {
zstd_sys::ZSTD_compress_usingDict(self.context.c,
destination.as_mut_ptr() as
*mut c_void,
destination.len(),
source.as_ptr() as *mut c_void,
source.len(),
self.dict.as_ptr() as
*mut c_void,
self.dict.len(),
level)
let code = {
zstd_safe::compress_using_dict(&mut self.context,
destination,
source,
&self.dict[..],
level)
};
parse_code(code)
}
@ -70,7 +47,7 @@ impl Compressor {
/// Compresses a block of data and returns the compressed result.
pub fn compress(&mut self, data: &[u8], lvl: i32) -> io::Result<Vec<u8>> {
// We allocate a big buffer, slightly larger than the input data.
let buffer_len = unsafe { zstd_sys::ZSTD_compressBound(data.len()) };
let buffer_len = zstd_safe::compress_bound(data.len());
let mut buffer = Vec::with_capacity(buffer_len);
unsafe {
// Use all capacity.

View file

@ -1,32 +1,14 @@
use libc::c_void;
use parse_code;
use std::io;
use zstd_sys;
struct DecoderContext {
c: *mut zstd_sys::ZSTD_DCtx,
}
impl Default for DecoderContext {
fn default() -> Self {
DecoderContext { c: unsafe { zstd_sys::ZSTD_createDCtx() } }
}
}
impl Drop for DecoderContext {
fn drop(&mut self) {
let code = unsafe { zstd_sys::ZSTD_freeDCtx(self.c) };
parse_code(code).unwrap();
}
}
use zstd_safe;
/// Allows to decompress independently multiple blocks of data.
///
/// This reduces memory usage compared to calling `decompress` multiple times.
#[derive(Default)]
pub struct Decompressor {
context: DecoderContext,
context: zstd_safe::DCtx,
dict: Vec<u8>,
}
@ -39,7 +21,7 @@ impl Decompressor {
/// Creates a new zstd decompressor, using the given dictionary.
pub fn with_dict(dict: Vec<u8>) -> Self {
Decompressor {
context: DecoderContext::default(),
context: zstd_safe::create_dctx(),
dict: dict,
}
}
@ -51,17 +33,11 @@ impl Decompressor {
pub fn decompress_to_buffer(&mut self, source: &[u8],
destination: &mut [u8])
-> io::Result<usize> {
let code = unsafe {
let destination_ptr = destination.as_mut_ptr() as *mut c_void;
let source_ptr = source.as_ptr() as *const c_void;
let dict_ptr = self.dict.as_ptr() as *const c_void;
zstd_sys::ZSTD_decompress_usingDict(self.context.c,
destination_ptr,
destination.len(),
source_ptr,
source.len(),
dict_ptr,
self.dict.len())
let code = {
zstd_safe::decompress_using_dict(&mut self.context,
destination,
source,
&self.dict)
};
parse_code(code)
}

View file

@ -14,13 +14,12 @@
//! [`Encoder::with_dictionary`]: ../struct.Encoder.html#method.with_dictionary
//! [`Decoder::with_dictionary`]: ../struct.Decoder.html#method.with_dictionary
use libc::{c_uint, c_void};
use parse_code;
use std::fs;
use std::io::{self, Read};
use std::path;
use zstd_sys;
use zstd_safe;
/// Train a dictionary from a big continuous chunk of data.
///
@ -37,15 +36,10 @@ pub fn from_continuous(sample_data: &[u8], sample_sizes: &[usize],
let mut result = Vec::with_capacity(max_size);
unsafe {
let result_ptr = result.as_mut_ptr() as *mut c_void;
let sample_ptr = sample_data.as_ptr() as *const c_void;
let code = zstd_sys::ZDICT_trainFromBuffer(result_ptr,
result.capacity(),
sample_ptr,
sample_sizes.as_ptr(),
sample_sizes.len() as
c_uint);
let written = try!(parse_code(code));
result.set_len(max_size);
let written = parse_code(zstd_safe::train_from_buffer(&mut result,
sample_data,
sample_sizes))?;
result.set_len(written);
}
Ok(result)

View file

@ -28,7 +28,7 @@ extern crate libc;
#[cfg(test)]
extern crate partial_io;
extern crate zstd_sys;
extern crate zstd_safe;
pub mod stream;
@ -43,8 +43,6 @@ extern crate futures;
#[cfg(all(test, feature = "tokio"))]
extern crate quickcheck;
use std::ffi::CStr;
use std::io;
#[doc(no_inline)]
pub use stream::{Decoder, Encoder, decode_all, encode_all};
@ -54,15 +52,13 @@ pub use stream::{Decoder, Encoder, decode_all, encode_all};
/// Returns the number of bytes written if the code represents success,
/// or the error message otherwise.
fn parse_code(code: libc::size_t) -> Result<usize, io::Error> {
unsafe {
if zstd_sys::ZSTD_isError(code) == 0 {
Ok(code as usize)
} else {
let msg = CStr::from_ptr(zstd_sys::ZSTD_getErrorName(code));
let error = io::Error::new(io::ErrorKind::Other,
msg.to_str().unwrap().to_string());
Err(error)
}
if zstd_safe::is_error(code) == 0 {
Ok(code as usize)
} else {
let msg = zstd_safe::get_error_name(code);
let error = io::Error::new(io::ErrorKind::Other,
msg.to_str().unwrap().to_string());
Err(error)
}
}

View file

@ -1,27 +1,9 @@
use libc::c_void;
use parse_code;
use std::io::{self, Read};
#[cfg(feature = "tokio")]
use tokio_io::AsyncRead;
use zstd_sys;
struct DecoderContext {
s: *mut zstd_sys::ZSTD_DStream,
}
impl Default for DecoderContext {
fn default() -> Self {
DecoderContext { s: unsafe { zstd_sys::ZSTD_createDStream() } }
}
}
impl Drop for DecoderContext {
fn drop(&mut self) {
let code = unsafe { zstd_sys::ZSTD_freeDStream(self.s) };
parse_code(code).unwrap();
}
}
use zstd_safe;
/// Extra bit of information that is stored along `RefillBuffer` state.
/// It describes the context in which refill was requested.
@ -56,7 +38,7 @@ pub struct Decoder<R: Read> {
// we already read everything in the buffer up to that point
offset: usize,
// decompression context
context: DecoderContext,
context: zstd_safe::DStream,
// `true` if we should stop after the first frame.
single_frame: bool,
@ -84,14 +66,11 @@ impl<R: Read> Decoder<R> {
/// The dictionary must be the same as the one used during compression.
pub fn with_dictionary(reader: R, dictionary: &[u8]) -> io::Result<Self> {
let buffer_size = unsafe { zstd_sys::ZSTD_DStreamInSize() };
let buffer_size = zstd_safe::dstream_in_size();
let context = DecoderContext::default();
parse_code(unsafe {
zstd_sys::ZSTD_initDStream_usingDict(context.s,
dictionary.as_ptr() as *const c_void,
dictionary.len())
})?;
let mut context = zstd_safe::create_dstream();
parse_code(zstd_safe::init_dstream_using_dict(&mut context,
dictionary))?;
let decoder = Decoder {
reader: reader,
@ -107,13 +86,13 @@ impl<R: Read> Decoder<R> {
// Prepares the context for another stream, whith minimal re-allocation.
fn reinit(&mut self) -> io::Result<()> {
parse_code(unsafe { zstd_sys::ZSTD_resetDStream(self.context.s) })?;
parse_code(zstd_safe::reset_dstream(&mut self.context))?;
Ok(())
}
/// Recommendation for the size of the output buffer.
pub fn recommended_output_size() -> usize {
unsafe { zstd_sys::ZSTD_DStreamOutSize() }
zstd_safe::dstream_out_size()
}
/// Acquire a reference to the underlying reader.
@ -140,10 +119,8 @@ impl<R: Read> Decoder<R> {
// Attemps to refill the input buffer.
//
// Returns the number of bytes read.
fn refill_buffer(&mut self, in_buffer: &mut zstd_sys::ZSTD_inBuffer)
-> io::Result<usize> {
fn refill_buffer(&mut self) -> io::Result<usize> {
// At this point it's safe to discard anything in `self.buffer`.
// (in_buffer HAS to point to self.buffer)
// We need moar data!
// Make a nice clean buffer
@ -159,8 +136,6 @@ impl<R: Read> Decoder<R> {
}
self.offset = 0;
in_buffer.pos = 0;
in_buffer.size = read;
// If we can't read anything, it means input is exhausted.
Ok(read)
@ -182,12 +157,11 @@ impl<R: Read> Decoder<R> {
///
/// It returns true if read operation should be stopped and false otherwise
fn handle_refill(&mut self, hint: RefillBufferHint,
in_buffer: &mut zstd_sys::ZSTD_inBuffer,
out_buffer: &mut zstd_sys::ZSTD_outBuffer)
out_buffer: &mut zstd_safe::OutBuffer)
-> Result<bool, io::Error> {
// refilled = false if we reached the end of the input.
let refilled = match self.refill_buffer(in_buffer) {
let refilled = match self.refill_buffer() {
Err(ref err) if out_buffer.pos > 0 &&
err.kind() == io::ErrorKind::WouldBlock => {
// The underlying reader was blocked, but we've already
@ -234,13 +208,17 @@ impl<R: Read> Decoder<R> {
/// This function handles Active state in the read operation - main read loop.
///
/// It returns true if read operation should be stopped and false otherwise
fn handle_active(&mut self, in_buffer: &mut zstd_sys::ZSTD_inBuffer,
out_buffer: &mut zstd_sys::ZSTD_outBuffer)
fn handle_active(&mut self, out_buffer: &mut zstd_safe::OutBuffer)
-> Result<bool, io::Error> {
let mut in_buffer = zstd_safe::InBuffer {
src: &self.buffer,
pos: self.offset,
};
// As long as we can keep writing...
while out_buffer.pos < out_buffer.size {
if in_buffer.pos == in_buffer.size {
while out_buffer.pos < out_buffer.dst.len() {
if in_buffer.pos == in_buffer.src.len() {
self.state =
DecoderState::RefillBuffer(RefillBufferHint::None);
// refill buffer and continue reading
@ -248,11 +226,10 @@ impl<R: Read> Decoder<R> {
}
// Let's use the hint from ZSTD to detect end of frames.
let is_end_of_frame = unsafe {
let code =
zstd_sys::ZSTD_decompressStream(self.context.s,
out_buffer as *mut zstd_sys::ZSTD_outBuffer,
in_buffer as *mut zstd_sys::ZSTD_inBuffer);
let is_end_of_frame = {
let code = zstd_safe::decompress_stream(&mut self.context,
out_buffer,
&mut in_buffer);
let res = parse_code(code)?;
res == 0
};
@ -268,7 +245,7 @@ impl<R: Read> Decoder<R> {
return Ok(true);
}
if in_buffer.pos == in_buffer.size {
if in_buffer.pos == in_buffer.src.len() {
let hint = if is_end_of_frame {
// If the frame is over, it's fine to stop there.
RefillBufferHint::EndOfFrame
@ -289,17 +266,8 @@ impl<R: Read> Read for Decoder<R> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
// Self-contained buffer pointer, size and offset
let mut in_buffer = zstd_sys::ZSTD_inBuffer {
src: self.buffer.as_ptr() as *const c_void,
size: self.buffer.len(),
pos: self.offset,
};
let mut out_buffer = zstd_sys::ZSTD_outBuffer {
dst: buf.as_mut_ptr() as *mut c_void,
size: buf.len(),
pos: 0,
};
let mut out_buffer = zstd_safe::OutBuffer { dst: buf, pos: 0 };
loop {
let should_stop = match self.state {
@ -307,13 +275,9 @@ impl<R: Read> Read for Decoder<R> {
return Ok(0);
}
DecoderState::RefillBuffer(action) => {
self.handle_refill(action,
&mut in_buffer,
&mut out_buffer)?
}
DecoderState::Active => {
self.handle_active(&mut in_buffer, &mut out_buffer)?
self.handle_refill(action, &mut out_buffer)?
}
DecoderState::Active => self.handle_active(&mut out_buffer)?,
};
if should_stop {
break;

View file

@ -1,31 +1,11 @@
#[cfg(feature = "tokio")]
use futures::Poll;
use libc::c_void;
use parse_code;
use std::io::{self, Write};
#[cfg(feature = "tokio")]
use tokio_io::AsyncWrite;
use zstd_sys;
struct EncoderContext {
s: *mut zstd_sys::ZSTD_CStream,
}
impl Default for EncoderContext {
fn default() -> Self {
EncoderContext { s: unsafe { zstd_sys::ZSTD_createCStream() } }
}
}
impl Drop for EncoderContext {
fn drop(&mut self) {
let code = unsafe { zstd_sys::ZSTD_freeCStream(self.s) };
parse_code(code).unwrap();
}
}
use zstd_safe;
#[derive(PartialEq)]
enum EncoderState {
@ -56,7 +36,7 @@ pub struct Encoder<W: Write> {
offset: usize,
// compression context
context: EncoderContext,
context: zstd_safe::CStream,
state: EncoderState,
}
@ -126,15 +106,12 @@ impl<W: Write> Encoder<W> {
/// but requires the dictionary to be present during decompression.)
pub fn with_dictionary(writer: W, level: i32, dictionary: &[u8])
-> io::Result<Self> {
let context = EncoderContext::default();
let mut context = zstd_safe::create_cstream();
// Initialize the stream with an existing dictionary
parse_code(unsafe {
zstd_sys::ZSTD_initCStream_usingDict(context.s,
dictionary.as_ptr() as *const c_void,
dictionary.len(),
level)
})?;
parse_code(zstd_safe::init_cstream_using_dict(&mut context,
dictionary,
level))?;
Encoder::with_context(writer, context)
}
@ -157,10 +134,11 @@ impl<W: Write> Encoder<W> {
AutoFinishEncoder::new(self, f)
}
fn with_context(writer: W, context: EncoderContext) -> io::Result<Self> {
fn with_context(writer: W, context: zstd_safe::CStream)
-> io::Result<Self> {
// This is the output buffer size,
// for compressed data we get from zstd.
let buffer_size = unsafe { zstd_sys::ZSTD_CStreamOutSize() };
let buffer_size = zstd_safe::cstream_out_size();
Ok(Encoder {
writer: writer,
@ -219,6 +197,12 @@ impl<W: Write> Encoder<W> {
}
}
/// Expands the buffer before writing there.
unsafe fn expand_buffer(&mut self) {
let capacity = self.buffer.capacity();
self.buffer.set_len(capacity);
}
fn do_finish(&mut self) -> io::Result<()> {
if self.state == EncoderState::Accepting {
// Write any data pending in `self.buffer`.
@ -228,17 +212,22 @@ impl<W: Write> Encoder<W> {
if self.state == EncoderState::Finished {
// First, closes the stream.
let mut buffer = zstd_sys::ZSTD_outBuffer {
dst: self.buffer.as_mut_ptr() as *mut c_void,
size: self.buffer.capacity(),
pos: 0,
let (pos, remaining) = {
unsafe {
self.expand_buffer();
}
let mut buffer = zstd_safe::OutBuffer {
dst: &mut self.buffer,
pos: 0,
};
let code =
parse_code(zstd_safe::end_stream(&mut self.context,
&mut buffer))?;
(buffer.pos, code)
};
let remaining = parse_code(unsafe {
zstd_sys::ZSTD_endStream(self.context.s,
&mut buffer as *mut zstd_sys::ZSTD_outBuffer)
})?;
unsafe {
self.buffer.set_len(buffer.pos);
self.buffer.set_len(pos);
}
if remaining != 0 {
// Need to flush?
@ -255,7 +244,7 @@ impl<W: Write> Encoder<W> {
/// Return a recommendation for the size of data to write at once.
pub fn recommended_input_size() -> usize {
unsafe { zstd_sys::ZSTD_CStreamInSize() }
zstd_safe::cstream_in_size()
}
/// write_all, except keep track of partial writes for non-blocking IO.
@ -283,37 +272,37 @@ impl<W: Write> Write for Encoder<W> {
// If we get to here, `self.buffer` can safely be discarded.
let mut in_buffer = zstd_sys::ZSTD_inBuffer {
src: buf.as_ptr() as *const c_void,
size: buf.len(),
pos: 0,
};
let mut out_buffer = zstd_sys::ZSTD_outBuffer {
dst: self.buffer.as_mut_ptr() as *mut c_void,
size: self.buffer.capacity(),
pos: 0,
};
// Time to fill our output buffer
let (in_pos, out_pos, code) = {
unsafe {
self.expand_buffer();
}
let mut in_buffer = zstd_safe::InBuffer { src: buf, pos: 0 };
let mut out_buffer = zstd_safe::OutBuffer {
dst: &mut self.buffer,
pos: 0,
};
let code = zstd_safe::compress_stream(&mut self.context,
&mut out_buffer,
&mut in_buffer);
(in_buffer.pos, out_buffer.pos, code)
};
unsafe {
// Time to fill our output buffer
let code =
zstd_sys::ZSTD_compressStream(self.context.s,
&mut out_buffer as
*mut zstd_sys::ZSTD_outBuffer,
&mut in_buffer as
*mut zstd_sys::ZSTD_inBuffer);
// Note: this may very well be empty,
// if it doesn't exceed zstd's own buffer
self.buffer.set_len(out_buffer.pos);
// Do we care about the hint?
let _ = parse_code(code)?;
self.buffer.set_len(out_pos);
}
// Do we care about the hint?
let _ = parse_code(code)?;
self.offset = 0;
if in_buffer.pos > 0 || buf.is_empty() {
return Ok(in_buffer.pos);
if in_pos > 0 || buf.is_empty() {
return Ok(in_pos);
}
}
}
@ -322,19 +311,26 @@ impl<W: Write> Write for Encoder<W> {
if self.state == EncoderState::Accepting {
self.write_from_offset()?;
let mut buffer = zstd_sys::ZSTD_outBuffer {
dst: self.buffer.as_mut_ptr() as *mut c_void,
size: self.buffer.capacity(),
pos: 0,
let (pos, code) = {
unsafe {
self.expand_buffer();
}
let mut buffer = zstd_safe::OutBuffer {
dst: &mut self.buffer,
pos: 0,
};
let code = zstd_safe::flush_stream(&mut self.context,
&mut buffer);
(buffer.pos, code)
};
unsafe {
let code =
zstd_sys::ZSTD_flushStream(self.context.s,
&mut buffer as
*mut zstd_sys::ZSTD_outBuffer);
self.buffer.set_len(buffer.pos);
let _ = parse_code(code)?;
self.buffer.set_len(pos);
}
let _ = parse_code(code)?;
self.offset = 0;
}
@ -365,7 +361,8 @@ mod tests {
fn test_partial_write_flush() {
use std::io::Write;
let (input, mut z) = setup_partial_write();
let input = vec![b'b'; 128 * 1024];
let mut z = setup_partial_write(&input);
// flush shouldn't corrupt the stream
z.flush().unwrap();
@ -379,14 +376,15 @@ mod tests {
/// internal implementation details.
#[test]
fn test_partial_write_finish() {
let (input, z) = setup_partial_write();
let input = vec![b'b'; 128 * 1024];
let z = setup_partial_write(&input);
// finish shouldn't corrupt the stream
let buf = z.finish().unwrap().into_inner();
assert_eq!(&decode_all(&buf[..]).unwrap(), &input);
}
fn setup_partial_write() -> (Vec<u8>, Encoder<PartialWrite<Vec<u8>>>) {
fn setup_partial_write(input_data: &[u8]) -> Encoder<PartialWrite<Vec<u8>>> {
use std::io::Write;
let buf = PartialWrite::new(Vec::new(),
@ -394,13 +392,12 @@ mod tests {
let mut z = Encoder::new(buf, 1).unwrap();
// Fill in enough data to make sure the buffer gets written out.
let input = "b".repeat(128 * 1024).into_bytes();
z.write(&input).unwrap();
z.write(input_data).unwrap();
// At this point, the internal buffer in z should have some data.
assert_ne!(z.offset, z.buffer.len());
(input, z)
z
}
}

View file

@ -245,7 +245,7 @@ mod tests {
#[test]
fn test_ll_source() {
// Where could I find some long text?...
let data = include_bytes!("../../zstd-sys/src/bindings.rs");
let data = include_bytes!("../../zstd-safe/zstd-sys/src/bindings.rs");
// Test a few compression levels.
// TODO: check them all?
for level in 1..5 {

18
zstd-safe/Cargo.toml Normal file
View file

@ -0,0 +1,18 @@
[package]
authors = ["Alexandre Bury <alexandre.bury@gmail.com>"]
name = "zstd-safe"
version = "1.2.0"
description = "Safe low-level bindings for the zstd compression library."
keywords = ["zstd", "zstandard", "compression"]
categories = ["api-bindings", "compression"]
repository = "https://github.com/gyscos/zstd-rs"
license = "MIT/Apache-2.0"
[dependencies]
zstd-sys = { path="zstd-sys", version = "1.2", default-features = false }
libc = "0.2.21"
[features]
default = ["legacy"]
legacy = ["zstd-sys/legacy"]
bindgen = ["zstd-sys/bindgen"]

559
zstd-safe/src/lib.rs Normal file
View file

@ -0,0 +1,559 @@
//! Minimal safe wrapper around zstd-sys.
//!
//! This crates provides a minimal translation of the zstd-sys methods.
//!
//! Check zstd's own documentation for information on specific functions.
extern crate zstd_sys;
extern crate libc;
use std::marker::PhantomData;
use std::ops::Deref;
use std::ops::DerefMut;
fn ptr_void(src: &[u8]) -> *const libc::c_void {
src.as_ptr() as *const libc::c_void
}
fn ptr_mut_void(dst: &mut [u8]) -> *mut libc::c_void {
dst.as_mut_ptr() as *mut libc::c_void
}
pub fn version_number() -> u32 {
unsafe { zstd_sys::ZSTD_versionNumber() as u32 }
}
pub fn compress(dst: &mut [u8], src: &[u8], compression_level: i32) -> usize {
unsafe {
zstd_sys::ZSTD_compress(ptr_mut_void(dst),
dst.len(),
ptr_void(src),
src.len(),
compression_level)
}
}
pub fn decompress(dst: &mut [u8], src: &[u8]) -> usize {
unsafe {
zstd_sys::ZSTD_decompress(ptr_mut_void(dst),
dst.len(),
ptr_void(src),
src.len())
}
}
pub fn get_decompressed_size(src: &[u8]) -> u64 {
unsafe {
zstd_sys::ZSTD_getDecompressedSize(ptr_void(src), src.len()) as u64
}
}
pub fn max_clevel() -> i32 {
unsafe { zstd_sys::ZSTD_maxCLevel() as i32 }
}
pub fn compress_bound(src_size: usize) -> usize {
unsafe { zstd_sys::ZSTD_compressBound(src_size) }
}
pub fn is_error(code: usize) -> u32 {
unsafe { zstd_sys::ZSTD_isError(code) as u32 }
}
pub struct CCtx(*mut zstd_sys::ZSTD_CCtx_s);
impl Default for CCtx {
fn default() -> Self {
create_cctx()
}
}
pub fn create_cctx() -> CCtx {
CCtx(unsafe { zstd_sys::ZSTD_createCCtx() })
}
impl Drop for CCtx {
fn drop(&mut self) {
unsafe {
zstd_sys::ZSTD_freeCCtx(self.0);
}
}
}
pub fn get_error_name(code: usize) -> &'static std::ffi::CStr {
unsafe { std::ffi::CStr::from_ptr(zstd_sys::ZSTD_getErrorName(code)) }
}
pub fn compress_cctx(ctx: &mut CCtx, dst: &mut [u8], src: &[u8],
compression_level: i32)
-> usize {
unsafe {
zstd_sys::ZSTD_compressCCtx(ctx.0,
ptr_mut_void(dst),
dst.len(),
ptr_void(src),
src.len(),
compression_level)
}
}
pub struct DCtx(*mut zstd_sys::ZSTD_DCtx);
impl Default for DCtx {
fn default() -> Self {
create_dctx()
}
}
pub fn create_dctx() -> DCtx {
DCtx(unsafe { zstd_sys::ZSTD_createDCtx() })
}
impl Drop for DCtx {
fn drop(&mut self) {
unsafe {
zstd_sys::ZSTD_freeDCtx(self.0);
}
}
}
pub fn decompress_dctx(ctx: &mut DCtx, dst: &mut [u8], src: &[u8]) -> usize {
unsafe {
zstd_sys::ZSTD_decompressDCtx(ctx.0,
ptr_mut_void(dst),
dst.len(),
ptr_void(src),
src.len())
}
}
pub fn compress_using_dict(ctx: &mut CCtx, dst: &mut [u8], src: &[u8],
dict: &[u8], compression_level: i32)
-> usize {
unsafe {
zstd_sys::ZSTD_compress_usingDict(ctx.0,
ptr_mut_void(dst),
dst.len(),
ptr_void(src),
src.len(),
ptr_void(dict),
dict.len(),
compression_level)
}
}
pub fn decompress_using_dict(dctx: &mut DCtx, dst: &mut [u8], src: &[u8],
dict: &[u8])
-> usize {
unsafe {
zstd_sys::ZSTD_decompress_usingDict(dctx.0,
ptr_mut_void(dst),
dst.len(),
ptr_void(src),
src.len(),
ptr_void(dict),
dict.len())
}
}
pub struct CDict<'a>(*mut zstd_sys::ZSTD_CDict, PhantomData<&'a ()>);
pub fn create_cdict(dict_buffer: &[u8], compression_level: i32)
-> CDict<'static> {
CDict(unsafe {
zstd_sys::ZSTD_createCDict(ptr_void(dict_buffer),
dict_buffer.len(),
compression_level)
},
PhantomData)
}
impl<'a> Drop for CDict<'a> {
fn drop(&mut self) {
unsafe {
zstd_sys::ZSTD_freeCDict(self.0);
}
}
}
pub fn compress_using_cdict(cctx: &mut CCtx, dst: &mut [u8], src: &[u8],
cdict: &CDict)
-> usize {
unsafe {
zstd_sys::ZSTD_compress_usingCDict(cctx.0,
ptr_mut_void(dst),
dst.len(),
ptr_void(src),
src.len(),
cdict.0)
}
}
pub struct DDict<'a>(*mut zstd_sys::ZSTD_DDict, PhantomData<&'a ()>);
pub fn ceate_ddict(dict_buffer: &[u8]) -> DDict<'static> {
DDict(unsafe {
zstd_sys::ZSTD_createDDict(ptr_void(dict_buffer),
dict_buffer.len())
},
PhantomData)
}
impl<'a> Drop for DDict<'a> {
fn drop(&mut self) {
unsafe {
zstd_sys::ZSTD_freeDDict(self.0);
}
}
}
pub fn decompress_using_ddict(dctx: &mut DCtx, dst: &mut [u8], src: &[u8],
ddict: &DDict)
-> usize {
unsafe {
zstd_sys::ZSTD_decompress_usingDDict(dctx.0,
ptr_mut_void(dst),
dst.len(),
ptr_void(src),
src.len(),
ddict.0)
}
}
pub struct CStream(*mut zstd_sys::ZSTD_CStream);
impl Default for CStream {
fn default() -> Self {
create_cstream()
}
}
pub fn create_cstream() -> CStream {
CStream(unsafe { zstd_sys::ZSTD_createCStream() })
}
impl Drop for CStream {
fn drop(&mut self) {
unsafe {
zstd_sys::ZSTD_freeCStream(self.0);
}
}
}
pub fn init_cstream(zcs: &mut CStream, compression_level: i32) -> usize {
unsafe { zstd_sys::ZSTD_initCStream(zcs.0, compression_level) }
}
pub struct InBuffer<'a> {
pub src: &'a [u8],
pub pos: usize,
}
pub struct OutBuffer<'a> {
pub dst: &'a mut [u8],
pub pos: usize,
}
fn ptr_mut<B>(ptr_void: &mut B) -> *mut B {
ptr_void as *mut B
}
struct OutBufferWrapper<'a, 'b: 'a> {
buf: zstd_sys::ZSTD_outBuffer,
parent: &'a mut OutBuffer<'b>,
}
impl<'a, 'b: 'a> Deref for OutBufferWrapper<'a, 'b> {
type Target = zstd_sys::ZSTD_outBuffer;
fn deref(&self) -> &Self::Target {
&self.buf
}
}
impl<'a, 'b: 'a> DerefMut for OutBufferWrapper<'a, 'b> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.buf
}
}
impl<'a> OutBuffer<'a> {
fn wrap<'b>(&'b mut self) -> OutBufferWrapper<'b, 'a> {
OutBufferWrapper {
buf: zstd_sys::ZSTD_outBuffer {
dst: ptr_mut_void(self.dst),
size: self.dst.len(),
pos: self.pos,
},
parent: self,
}
}
}
impl<'a, 'b> Drop for OutBufferWrapper<'a, 'b> {
fn drop(&mut self) {
self.parent.pos = self.buf.pos;
}
}
struct InBufferWrapper<'a, 'b: 'a> {
buf: zstd_sys::ZSTD_inBuffer,
parent: &'a mut InBuffer<'b>,
}
impl<'a, 'b: 'a> Deref for InBufferWrapper<'a, 'b> {
type Target = zstd_sys::ZSTD_inBuffer;
fn deref(&self) -> &Self::Target {
&self.buf
}
}
impl<'a, 'b: 'a> DerefMut for InBufferWrapper<'a, 'b> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.buf
}
}
impl<'a> InBuffer<'a> {
fn wrap<'b>(&'b mut self) -> InBufferWrapper<'b, 'a> {
InBufferWrapper {
buf: zstd_sys::ZSTD_inBuffer {
src: ptr_void(self.src),
size: self.src.len(),
pos: self.pos,
},
parent: self,
}
}
}
impl<'a, 'b> Drop for InBufferWrapper<'a, 'b> {
fn drop(&mut self) {
self.parent.pos = self.buf.pos;
}
}
pub fn compress_stream(zcs: &mut CStream, output: &mut OutBuffer,
input: &mut InBuffer)
-> usize {
let mut output = output.wrap();
let mut input = input.wrap();
unsafe {
zstd_sys::ZSTD_compressStream(zcs.0,
ptr_mut(&mut output),
ptr_mut(&mut input))
}
}
pub fn flush_stream(zcs: &mut CStream, output: &mut OutBuffer) -> usize {
let mut output = output.wrap();
unsafe { zstd_sys::ZSTD_flushStream(zcs.0, ptr_mut(&mut output)) }
}
pub fn end_stream(zcs: &mut CStream, output: &mut OutBuffer) -> usize {
let mut output = output.wrap();
unsafe { zstd_sys::ZSTD_endStream(zcs.0, ptr_mut(&mut output)) }
}
pub fn cstream_in_size() -> usize {
unsafe { zstd_sys::ZSTD_CStreamInSize() }
}
pub fn cstream_out_size() -> usize {
unsafe { zstd_sys::ZSTD_CStreamOutSize() }
}
pub struct DStream(*mut zstd_sys::ZSTD_DStream);
impl Default for DStream {
fn default() -> Self {
create_dstream()
}
}
pub fn create_dstream() -> DStream {
DStream(unsafe { zstd_sys::ZSTD_createDStream() })
}
impl Drop for DStream {
fn drop(&mut self) {
unsafe {
zstd_sys::ZSTD_freeDStream(self.0);
}
}
}
pub fn init_dstream(zds: &mut DStream) -> usize {
unsafe { zstd_sys::ZSTD_initDStream(zds.0) }
}
pub fn decompress_stream(zds: &mut DStream, output: &mut OutBuffer,
input: &mut InBuffer)
-> usize {
let mut output = output.wrap();
let mut input = input.wrap();
unsafe {
zstd_sys::ZSTD_decompressStream(zds.0,
ptr_mut(&mut output),
ptr_mut(&mut input))
}
}
pub fn dstream_in_size() -> usize {
unsafe { zstd_sys::ZSTD_DStreamInSize() }
}
pub fn dstream_out_size() -> usize {
unsafe { zstd_sys::ZSTD_DStreamOutSize() }
}
pub fn find_frame_compressed_size(src: &[u8]) -> usize {
unsafe { zstd_sys::ZSTD_findFrameCompressedSize(ptr_void(src), src.len()) }
}
pub fn get_frame_content_size(src: &[u8]) -> u64 {
unsafe { zstd_sys::ZSTD_getFrameContentSize(ptr_void(src), src.len()) }
}
pub fn find_decompressed_size(src: &[u8]) -> u64 {
unsafe { zstd_sys::ZSTD_findDecompressedSize(ptr_void(src), src.len()) }
}
pub fn sizeof_cctx(cctx: &CCtx) -> usize {
unsafe { zstd_sys::ZSTD_sizeof_CCtx(cctx.0) }
}
pub fn sizeof_dctx(dctx: &DCtx) -> usize {
unsafe { zstd_sys::ZSTD_sizeof_DCtx(dctx.0) }
}
pub fn sizeof_cstream(zcs: &CStream) -> usize {
unsafe { zstd_sys::ZSTD_sizeof_CStream(zcs.0) }
}
pub fn sizeof_dstream(zds: &DStream) -> usize {
unsafe { zstd_sys::ZSTD_sizeof_DStream(zds.0) }
}
pub fn sizeof_cdict(cdict: &CDict) -> usize {
unsafe { zstd_sys::ZSTD_sizeof_CDict(cdict.0) }
}
pub fn sizeof_ddict(ddict: &DDict) -> usize {
unsafe { zstd_sys::ZSTD_sizeof_DDict(ddict.0) }
}
pub fn create_cdict_by_reference<'a>(dict_buffer: &'a [u8],
compression_level: i32)
-> CDict<'a> {
CDict(unsafe {
zstd_sys::ZSTD_createCDict_byReference(ptr_void(dict_buffer),
dict_buffer.len(),
compression_level)
},
PhantomData)
}
pub fn is_frame(buffer: &[u8]) -> u32 {
unsafe { zstd_sys::ZSTD_isFrame(ptr_void(buffer), buffer.len()) as u32 }
}
pub fn create_ddict_by_reference<'a>(dict_buffer: &'a [u8]) -> DDict<'a> {
DDict(unsafe {
zstd_sys::ZSTD_createDDict_byReference(ptr_void(dict_buffer),
dict_buffer.len())
},
PhantomData)
}
pub fn get_dict_id_from_dict(dict: &[u8]) -> u32 {
unsafe {
zstd_sys::ZSTD_getDictID_fromDict(ptr_void(dict), dict.len()) as u32
}
}
pub fn get_dict_id_from_ddict(ddict: &DDict) -> u32 {
unsafe { zstd_sys::ZSTD_getDictID_fromDDict(ddict.0) as u32 }
}
pub fn get_dict_id_from_frame(src: &[u8]) -> u32 {
unsafe {
zstd_sys::ZSTD_getDictID_fromFrame(ptr_void(src), src.len()) as u32
}
}
pub fn init_cstream_src_size(zcs: &mut CStream, compression_level: i32,
pledged_src_size: u64)
-> usize {
unsafe {
zstd_sys::ZSTD_initCStream_srcSize(zcs.0,
compression_level as libc::c_int,
pledged_src_size as
libc::c_ulonglong)
}
}
pub fn init_cstream_using_dict(zcs: &mut CStream, dict: &[u8],
compression_level: i32)
-> usize {
unsafe {
zstd_sys::ZSTD_initCStream_usingDict(zcs.0,
ptr_void(dict),
dict.len(),
compression_level)
}
}
pub fn init_cstream_using_csict(zcs: &mut CStream, cdict: &CDict) -> usize {
unsafe { zstd_sys::ZSTD_initCStream_usingCDict(zcs.0, cdict.0) }
}
pub fn reset_cstream(zcs: &mut CStream, pledged_src_size: u64) -> usize {
unsafe {
zstd_sys::ZSTD_resetCStream(zcs.0,
pledged_src_size as libc::c_ulonglong)
}
}
pub fn init_dstream_using_dict(zds: &mut DStream, dict: &[u8]) -> usize {
unsafe {
zstd_sys::ZSTD_initDStream_usingDict(zds.0, ptr_void(dict), dict.len())
}
}
pub fn init_dstream_using_ddict(zds: &mut DStream, ddict: &DDict) -> usize {
unsafe { zstd_sys::ZSTD_initDStream_usingDDict(zds.0, ddict.0) }
}
pub fn reset_dstream(zds: &mut DStream) -> usize {
unsafe { zstd_sys::ZSTD_resetDStream(zds.0) }
}
pub fn train_from_buffer(dict_buffer: &mut [u8], samples_buffer: &[u8],
samples_sizes: &[usize])
-> usize {
assert_eq!(samples_buffer.len(), samples_sizes.iter().sum());
unsafe {
zstd_sys::ZDICT_trainFromBuffer(ptr_mut_void(dict_buffer),
dict_buffer.len(),
ptr_void(samples_buffer),
samples_sizes.as_ptr(),
samples_sizes.len() as u32)
}
}
pub fn get_block_size_max(cctx: &mut CCtx) -> usize {
unsafe { zstd_sys::ZSTD_getBlockSizeMax(cctx.0) }
}
pub fn compress_block(cctx: &mut CCtx, dst: &mut [u8], src: &[u8]) -> usize {
unsafe {
zstd_sys::ZSTD_compressBlock(cctx.0,
ptr_mut_void(dst),
dst.len(),
ptr_void(src),
src.len())
}
}
pub fn decompress_block(dctx: &mut DCtx, dst: &mut [u8], src: &[u8]) -> usize {
unsafe {
zstd_sys::ZSTD_decompressBlock(dctx.0,
ptr_mut_void(dst),
dst.len(),
ptr_void(src),
src.len())
}
}
pub fn insert_block(dctx: &mut DCtx, block: &[u8]) -> usize {
unsafe { zstd_sys::ZSTD_insertBlock(dctx.0, ptr_void(block), block.len()) }
}

13
zstd-safe/src/lib.rs.bk Normal file
View file

@ -0,0 +1,13 @@
extern crate zstd_sys;
pub fn versionNumber() -> u32 {
unsafe { zstd_sys::ZSTD_versionNumber() as u32 }
}
pub fn compress(dst: &mut [u8],
src: &[u8],
compressionLevel: u32) -> usize {
unsafe { zstd_sys::ZSTD_compress(dst.as_mut_ptr(), dst.len(), src.as_ptr(), src.len(), compressionLevel) as usize }
}

View file

@ -10,7 +10,7 @@ repository = "https://github.com/gyscos/zstd-rs"
license = "MIT/Apache-2.0"
[build-dependencies]
bindgen = { version = "0.22.1", optional = true }
bindgen = { version = "0.25", optional = true }
gcc = "0.3.45"
glob = "0.2.11"

File diff suppressed because it is too large Load diff

View file

@ -4,7 +4,7 @@
/* This file is used to generate bindings for both headers.
* Just run the following command to generate the bindings:
bindgen zstd.h --ctypes-prefix ::libc -- -DZSTD_STATIC_LINKING_ONLY --blacklist-type max_align_t > src/ll.rs
bindgen zstd.h --ctypes-prefix ::libc --blacklist-type max_align_t --no-unstable-rust --use-core -- -DZSTD_STATIC_LINKING_ONLY > src/bindings.rs
Or use the `bindgen` feature, which will create the bindings automatically.

View file

@ -1,780 +0,0 @@
/* automatically generated by rust-bindgen */
pub const ZSTD_VERSION_MAJOR: ::libc::c_uint = 1;
pub const ZSTD_VERSION_MINOR: ::libc::c_uint = 1;
pub const ZSTD_VERSION_RELEASE: ::libc::c_uint = 4;
pub const ZSTD_MAGICNUMBER: ::libc::c_uint = 4247762216;
pub const ZSTD_MAGIC_SKIPPABLE_START: ::libc::c_uint = 407710288;
pub const ZSTD_CONTENTSIZE_UNKNOWN: ::libc::c_int = -1;
pub const ZSTD_CONTENTSIZE_ERROR: ::libc::c_int = -2;
pub const ZSTD_WINDOWLOG_MAX_32: ::libc::c_uint = 27;
pub const ZSTD_WINDOWLOG_MAX_64: ::libc::c_uint = 27;
pub const ZSTD_WINDOWLOG_MIN: ::libc::c_uint = 10;
pub const ZSTD_HASHLOG_MIN: ::libc::c_uint = 6;
pub const ZSTD_CHAINLOG_MIN: ::libc::c_uint = 6;
pub const ZSTD_HASHLOG3_MAX: ::libc::c_uint = 17;
pub const ZSTD_SEARCHLOG_MIN: ::libc::c_uint = 1;
pub const ZSTD_SEARCHLENGTH_MAX: ::libc::c_uint = 7;
pub const ZSTD_SEARCHLENGTH_MIN: ::libc::c_uint = 3;
pub const ZSTD_TARGETLENGTH_MIN: ::libc::c_uint = 4;
pub const ZSTD_TARGETLENGTH_MAX: ::libc::c_uint = 999;
pub const ZSTD_FRAMEHEADERSIZE_MAX: ::libc::c_uint = 18;
pub const ZSTD_FRAMEHEADERSIZE_MIN: ::libc::c_uint = 6;
pub const ZSTD_BLOCKSIZE_ABSOLUTEMAX: ::libc::c_uint = 131072;
pub type wchar_t = ::libc::c_int;
extern "C" {
pub fn ZSTD_versionNumber() -> ::libc::c_uint;
}
extern "C" {
pub fn ZSTD_compress(dst: *mut ::libc::c_void, dstCapacity: usize,
src: *const ::libc::c_void, srcSize: usize,
compressionLevel: ::libc::c_int) -> usize;
}
extern "C" {
pub fn ZSTD_decompress(dst: *mut ::libc::c_void, dstCapacity: usize,
src: *const ::libc::c_void, compressedSize: usize)
-> usize;
}
extern "C" {
pub fn ZSTD_getDecompressedSize(src: *const ::libc::c_void,
srcSize: usize) -> ::libc::c_ulonglong;
}
extern "C" {
pub fn ZSTD_maxCLevel() -> ::libc::c_int;
}
extern "C" {
pub fn ZSTD_compressBound(srcSize: usize) -> usize;
}
extern "C" {
pub fn ZSTD_isError(code: usize) -> ::libc::c_uint;
}
extern "C" {
pub fn ZSTD_getErrorName(code: usize) -> *const ::libc::c_char;
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZSTD_CCtx_s([u8; 0]);
pub type ZSTD_CCtx = ZSTD_CCtx_s;
extern "C" {
pub fn ZSTD_createCCtx() -> *mut ZSTD_CCtx;
}
extern "C" {
pub fn ZSTD_freeCCtx(cctx: *mut ZSTD_CCtx) -> usize;
}
extern "C" {
pub fn ZSTD_compressCCtx(ctx: *mut ZSTD_CCtx, dst: *mut ::libc::c_void,
dstCapacity: usize, src: *const ::libc::c_void,
srcSize: usize, compressionLevel: ::libc::c_int)
-> usize;
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZSTD_DCtx_s([u8; 0]);
pub type ZSTD_DCtx = ZSTD_DCtx_s;
extern "C" {
pub fn ZSTD_createDCtx() -> *mut ZSTD_DCtx;
}
extern "C" {
pub fn ZSTD_freeDCtx(dctx: *mut ZSTD_DCtx) -> usize;
}
extern "C" {
pub fn ZSTD_decompressDCtx(ctx: *mut ZSTD_DCtx, dst: *mut ::libc::c_void,
dstCapacity: usize, src: *const ::libc::c_void,
srcSize: usize) -> usize;
}
extern "C" {
pub fn ZSTD_compress_usingDict(ctx: *mut ZSTD_CCtx,
dst: *mut ::libc::c_void,
dstCapacity: usize,
src: *const ::libc::c_void, srcSize: usize,
dict: *const ::libc::c_void,
dictSize: usize,
compressionLevel: ::libc::c_int) -> usize;
}
extern "C" {
pub fn ZSTD_decompress_usingDict(dctx: *mut ZSTD_DCtx,
dst: *mut ::libc::c_void,
dstCapacity: usize,
src: *const ::libc::c_void,
srcSize: usize,
dict: *const ::libc::c_void,
dictSize: usize) -> usize;
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZSTD_CDict_s([u8; 0]);
pub type ZSTD_CDict = ZSTD_CDict_s;
extern "C" {
pub fn ZSTD_createCDict(dictBuffer: *const ::libc::c_void,
dictSize: usize, compressionLevel: ::libc::c_int)
-> *mut ZSTD_CDict;
}
extern "C" {
pub fn ZSTD_freeCDict(CDict: *mut ZSTD_CDict) -> usize;
}
extern "C" {
pub fn ZSTD_compress_usingCDict(cctx: *mut ZSTD_CCtx,
dst: *mut ::libc::c_void,
dstCapacity: usize,
src: *const ::libc::c_void,
srcSize: usize, cdict: *const ZSTD_CDict)
-> usize;
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZSTD_DDict_s([u8; 0]);
pub type ZSTD_DDict = ZSTD_DDict_s;
extern "C" {
pub fn ZSTD_createDDict(dictBuffer: *const ::libc::c_void,
dictSize: usize) -> *mut ZSTD_DDict;
}
extern "C" {
pub fn ZSTD_freeDDict(ddict: *mut ZSTD_DDict) -> usize;
}
extern "C" {
pub fn ZSTD_decompress_usingDDict(dctx: *mut ZSTD_DCtx,
dst: *mut ::libc::c_void,
dstCapacity: usize,
src: *const ::libc::c_void,
srcSize: usize,
ddict: *const ZSTD_DDict) -> usize;
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct ZSTD_inBuffer_s {
pub src: *const ::libc::c_void,
pub size: usize,
pub pos: usize,
}
#[test]
fn bindgen_test_layout_ZSTD_inBuffer_s() {
assert_eq!(::core::mem::size_of::<ZSTD_inBuffer_s>() , 24usize , concat !
( "Size of: " , stringify ! ( ZSTD_inBuffer_s ) ));
assert_eq! (::core::mem::align_of::<ZSTD_inBuffer_s>() , 8usize , concat !
( "Alignment of " , stringify ! ( ZSTD_inBuffer_s ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const ZSTD_inBuffer_s ) ) . src as * const _ as
usize } , 0usize , concat ! (
"Alignment of field: " , stringify ! ( ZSTD_inBuffer_s ) ,
"::" , stringify ! ( src ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const ZSTD_inBuffer_s ) ) . size as * const _
as usize } , 8usize , concat ! (
"Alignment of field: " , stringify ! ( ZSTD_inBuffer_s ) ,
"::" , stringify ! ( size ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const ZSTD_inBuffer_s ) ) . pos as * const _ as
usize } , 16usize , concat ! (
"Alignment of field: " , stringify ! ( ZSTD_inBuffer_s ) ,
"::" , stringify ! ( pos ) ));
}
impl Clone for ZSTD_inBuffer_s {
fn clone(&self) -> Self { *self }
}
pub type ZSTD_inBuffer = ZSTD_inBuffer_s;
#[repr(C)]
#[derive(Debug, Copy)]
pub struct ZSTD_outBuffer_s {
pub dst: *mut ::libc::c_void,
pub size: usize,
pub pos: usize,
}
#[test]
fn bindgen_test_layout_ZSTD_outBuffer_s() {
assert_eq!(::core::mem::size_of::<ZSTD_outBuffer_s>() , 24usize , concat !
( "Size of: " , stringify ! ( ZSTD_outBuffer_s ) ));
assert_eq! (::core::mem::align_of::<ZSTD_outBuffer_s>() , 8usize , concat
! ( "Alignment of " , stringify ! ( ZSTD_outBuffer_s ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const ZSTD_outBuffer_s ) ) . dst as * const _
as usize } , 0usize , concat ! (
"Alignment of field: " , stringify ! ( ZSTD_outBuffer_s ) ,
"::" , stringify ! ( dst ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const ZSTD_outBuffer_s ) ) . size as * const _
as usize } , 8usize , concat ! (
"Alignment of field: " , stringify ! ( ZSTD_outBuffer_s ) ,
"::" , stringify ! ( size ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const ZSTD_outBuffer_s ) ) . pos as * const _
as usize } , 16usize , concat ! (
"Alignment of field: " , stringify ! ( ZSTD_outBuffer_s ) ,
"::" , stringify ! ( pos ) ));
}
impl Clone for ZSTD_outBuffer_s {
fn clone(&self) -> Self { *self }
}
pub type ZSTD_outBuffer = ZSTD_outBuffer_s;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZSTD_CStream_s([u8; 0]);
pub type ZSTD_CStream = ZSTD_CStream_s;
extern "C" {
pub fn ZSTD_createCStream() -> *mut ZSTD_CStream;
}
extern "C" {
pub fn ZSTD_freeCStream(zcs: *mut ZSTD_CStream) -> usize;
}
extern "C" {
pub fn ZSTD_initCStream(zcs: *mut ZSTD_CStream,
compressionLevel: ::libc::c_int) -> usize;
}
extern "C" {
pub fn ZSTD_compressStream(zcs: *mut ZSTD_CStream,
output: *mut ZSTD_outBuffer,
input: *mut ZSTD_inBuffer) -> usize;
}
extern "C" {
pub fn ZSTD_flushStream(zcs: *mut ZSTD_CStream,
output: *mut ZSTD_outBuffer) -> usize;
}
extern "C" {
pub fn ZSTD_endStream(zcs: *mut ZSTD_CStream, output: *mut ZSTD_outBuffer)
-> usize;
}
extern "C" {
pub fn ZSTD_CStreamInSize() -> usize;
}
extern "C" {
pub fn ZSTD_CStreamOutSize() -> usize;
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZSTD_DStream_s([u8; 0]);
pub type ZSTD_DStream = ZSTD_DStream_s;
extern "C" {
pub fn ZSTD_createDStream() -> *mut ZSTD_DStream;
}
extern "C" {
pub fn ZSTD_freeDStream(zds: *mut ZSTD_DStream) -> usize;
}
extern "C" {
pub fn ZSTD_initDStream(zds: *mut ZSTD_DStream) -> usize;
}
extern "C" {
pub fn ZSTD_decompressStream(zds: *mut ZSTD_DStream,
output: *mut ZSTD_outBuffer,
input: *mut ZSTD_inBuffer) -> usize;
}
extern "C" {
pub fn ZSTD_DStreamInSize() -> usize;
}
extern "C" {
pub fn ZSTD_DStreamOutSize() -> usize;
}
pub const ZSTD_frameHeaderSize_prefix: usize = 5;
pub const ZSTD_frameHeaderSize_min: usize = 6;
pub const ZSTD_frameHeaderSize_max: usize = 18;
pub const ZSTD_skippableHeaderSize: usize = 8;
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum ZSTD_strategy {
ZSTD_fast = 0,
ZSTD_dfast = 1,
ZSTD_greedy = 2,
ZSTD_lazy = 3,
ZSTD_lazy2 = 4,
ZSTD_btlazy2 = 5,
ZSTD_btopt = 6,
ZSTD_btopt2 = 7,
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct ZSTD_compressionParameters {
pub windowLog: ::libc::c_uint,
pub chainLog: ::libc::c_uint,
pub hashLog: ::libc::c_uint,
pub searchLog: ::libc::c_uint,
pub searchLength: ::libc::c_uint,
pub targetLength: ::libc::c_uint,
pub strategy: ZSTD_strategy,
}
#[test]
fn bindgen_test_layout_ZSTD_compressionParameters() {
assert_eq!(::core::mem::size_of::<ZSTD_compressionParameters>() , 28usize
, concat ! (
"Size of: " , stringify ! ( ZSTD_compressionParameters ) ));
assert_eq! (::core::mem::align_of::<ZSTD_compressionParameters>() , 4usize
, concat ! (
"Alignment of " , stringify ! ( ZSTD_compressionParameters )
));
assert_eq! (unsafe {
& ( * ( 0 as * const ZSTD_compressionParameters ) ) .
windowLog as * const _ as usize } , 0usize , concat ! (
"Alignment of field: " , stringify ! (
ZSTD_compressionParameters ) , "::" , stringify ! ( windowLog
) ));
assert_eq! (unsafe {
& ( * ( 0 as * const ZSTD_compressionParameters ) ) . chainLog
as * const _ as usize } , 4usize , concat ! (
"Alignment of field: " , stringify ! (
ZSTD_compressionParameters ) , "::" , stringify ! ( chainLog )
));
assert_eq! (unsafe {
& ( * ( 0 as * const ZSTD_compressionParameters ) ) . hashLog
as * const _ as usize } , 8usize , concat ! (
"Alignment of field: " , stringify ! (
ZSTD_compressionParameters ) , "::" , stringify ! ( hashLog )
));
assert_eq! (unsafe {
& ( * ( 0 as * const ZSTD_compressionParameters ) ) .
searchLog as * const _ as usize } , 12usize , concat ! (
"Alignment of field: " , stringify ! (
ZSTD_compressionParameters ) , "::" , stringify ! ( searchLog
) ));
assert_eq! (unsafe {
& ( * ( 0 as * const ZSTD_compressionParameters ) ) .
searchLength as * const _ as usize } , 16usize , concat ! (
"Alignment of field: " , stringify ! (
ZSTD_compressionParameters ) , "::" , stringify ! (
searchLength ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const ZSTD_compressionParameters ) ) .
targetLength as * const _ as usize } , 20usize , concat ! (
"Alignment of field: " , stringify ! (
ZSTD_compressionParameters ) , "::" , stringify ! (
targetLength ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const ZSTD_compressionParameters ) ) . strategy
as * const _ as usize } , 24usize , concat ! (
"Alignment of field: " , stringify ! (
ZSTD_compressionParameters ) , "::" , stringify ! ( strategy )
));
}
impl Clone for ZSTD_compressionParameters {
fn clone(&self) -> Self { *self }
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct ZSTD_frameParameters {
pub contentSizeFlag: ::libc::c_uint,
pub checksumFlag: ::libc::c_uint,
pub noDictIDFlag: ::libc::c_uint,
}
#[test]
fn bindgen_test_layout_ZSTD_frameParameters() {
assert_eq!(::core::mem::size_of::<ZSTD_frameParameters>() , 12usize ,
concat ! ( "Size of: " , stringify ! ( ZSTD_frameParameters )
));
assert_eq! (::core::mem::align_of::<ZSTD_frameParameters>() , 4usize ,
concat ! (
"Alignment of " , stringify ! ( ZSTD_frameParameters ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const ZSTD_frameParameters ) ) .
contentSizeFlag as * const _ as usize } , 0usize , concat ! (
"Alignment of field: " , stringify ! ( ZSTD_frameParameters )
, "::" , stringify ! ( contentSizeFlag ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const ZSTD_frameParameters ) ) . checksumFlag
as * const _ as usize } , 4usize , concat ! (
"Alignment of field: " , stringify ! ( ZSTD_frameParameters )
, "::" , stringify ! ( checksumFlag ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const ZSTD_frameParameters ) ) . noDictIDFlag
as * const _ as usize } , 8usize , concat ! (
"Alignment of field: " , stringify ! ( ZSTD_frameParameters )
, "::" , stringify ! ( noDictIDFlag ) ));
}
impl Clone for ZSTD_frameParameters {
fn clone(&self) -> Self { *self }
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct ZSTD_parameters {
pub cParams: ZSTD_compressionParameters,
pub fParams: ZSTD_frameParameters,
}
#[test]
fn bindgen_test_layout_ZSTD_parameters() {
assert_eq!(::core::mem::size_of::<ZSTD_parameters>() , 40usize , concat !
( "Size of: " , stringify ! ( ZSTD_parameters ) ));
assert_eq! (::core::mem::align_of::<ZSTD_parameters>() , 4usize , concat !
( "Alignment of " , stringify ! ( ZSTD_parameters ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const ZSTD_parameters ) ) . cParams as * const
_ as usize } , 0usize , concat ! (
"Alignment of field: " , stringify ! ( ZSTD_parameters ) ,
"::" , stringify ! ( cParams ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const ZSTD_parameters ) ) . fParams as * const
_ as usize } , 28usize , concat ! (
"Alignment of field: " , stringify ! ( ZSTD_parameters ) ,
"::" , stringify ! ( fParams ) ));
}
impl Clone for ZSTD_parameters {
fn clone(&self) -> Self { *self }
}
pub type ZSTD_allocFunction =
::core::option::Option<unsafe extern "C" fn(opaque: *mut ::libc::c_void,
size: usize)
-> *mut ::libc::c_void>;
pub type ZSTD_freeFunction =
::core::option::Option<unsafe extern "C" fn(opaque: *mut ::libc::c_void,
address:
*mut ::libc::c_void)>;
#[repr(C)]
#[derive(Debug, Copy)]
pub struct ZSTD_customMem {
pub customAlloc: ZSTD_allocFunction,
pub customFree: ZSTD_freeFunction,
pub opaque: *mut ::libc::c_void,
}
#[test]
fn bindgen_test_layout_ZSTD_customMem() {
assert_eq!(::core::mem::size_of::<ZSTD_customMem>() , 24usize , concat ! (
"Size of: " , stringify ! ( ZSTD_customMem ) ));
assert_eq! (::core::mem::align_of::<ZSTD_customMem>() , 8usize , concat !
( "Alignment of " , stringify ! ( ZSTD_customMem ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const ZSTD_customMem ) ) . customAlloc as *
const _ as usize } , 0usize , concat ! (
"Alignment of field: " , stringify ! ( ZSTD_customMem ) , "::"
, stringify ! ( customAlloc ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const ZSTD_customMem ) ) . customFree as *
const _ as usize } , 8usize , concat ! (
"Alignment of field: " , stringify ! ( ZSTD_customMem ) , "::"
, stringify ! ( customFree ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const ZSTD_customMem ) ) . opaque as * const _
as usize } , 16usize , concat ! (
"Alignment of field: " , stringify ! ( ZSTD_customMem ) , "::"
, stringify ! ( opaque ) ));
}
impl Clone for ZSTD_customMem {
fn clone(&self) -> Self { *self }
}
extern "C" {
pub fn ZSTD_findFrameCompressedSize(src: *const ::libc::c_void,
srcSize: usize) -> usize;
}
extern "C" {
pub fn ZSTD_getFrameContentSize(src: *const ::libc::c_void,
srcSize: usize) -> ::libc::c_ulonglong;
}
extern "C" {
pub fn ZSTD_findDecompressedSize(src: *const ::libc::c_void,
srcSize: usize) -> ::libc::c_ulonglong;
}
extern "C" {
pub fn ZSTD_estimateCCtxSize(cParams: ZSTD_compressionParameters)
-> usize;
}
extern "C" {
pub fn ZSTD_createCCtx_advanced(customMem: ZSTD_customMem)
-> *mut ZSTD_CCtx;
}
extern "C" {
pub fn ZSTD_sizeof_CCtx(cctx: *const ZSTD_CCtx) -> usize;
}
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum ZSTD_CCtxParameter {
ZSTD_p_forceWindow = 0,
ZSTD_p_forceRawDict = 1,
}
extern "C" {
pub fn ZSTD_setCCtxParameter(cctx: *mut ZSTD_CCtx,
param: ZSTD_CCtxParameter,
value: ::libc::c_uint) -> usize;
}
extern "C" {
pub fn ZSTD_createCDict_byReference(dictBuffer: *const ::libc::c_void,
dictSize: usize,
compressionLevel: ::libc::c_int)
-> *mut ZSTD_CDict;
}
extern "C" {
pub fn ZSTD_createCDict_advanced(dict: *const ::libc::c_void,
dictSize: usize,
byReference: ::libc::c_uint,
params: ZSTD_parameters,
customMem: ZSTD_customMem)
-> *mut ZSTD_CDict;
}
extern "C" {
pub fn ZSTD_sizeof_CDict(cdict: *const ZSTD_CDict) -> usize;
}
extern "C" {
pub fn ZSTD_getCParams(compressionLevel: ::libc::c_int,
estimatedSrcSize: ::libc::c_ulonglong,
dictSize: usize) -> ZSTD_compressionParameters;
}
extern "C" {
pub fn ZSTD_getParams(compressionLevel: ::libc::c_int,
estimatedSrcSize: ::libc::c_ulonglong,
dictSize: usize) -> ZSTD_parameters;
}
extern "C" {
pub fn ZSTD_checkCParams(params: ZSTD_compressionParameters) -> usize;
}
extern "C" {
pub fn ZSTD_adjustCParams(cPar: ZSTD_compressionParameters,
srcSize: ::libc::c_ulonglong, dictSize: usize)
-> ZSTD_compressionParameters;
}
extern "C" {
pub fn ZSTD_compress_advanced(ctx: *mut ZSTD_CCtx,
dst: *mut ::libc::c_void,
dstCapacity: usize,
src: *const ::libc::c_void, srcSize: usize,
dict: *const ::libc::c_void,
dictSize: usize, params: ZSTD_parameters)
-> usize;
}
extern "C" {
pub fn ZSTD_isFrame(buffer: *const ::libc::c_void, size: usize)
-> ::libc::c_uint;
}
extern "C" {
pub fn ZSTD_estimateDCtxSize() -> usize;
}
extern "C" {
pub fn ZSTD_createDCtx_advanced(customMem: ZSTD_customMem)
-> *mut ZSTD_DCtx;
}
extern "C" {
pub fn ZSTD_sizeof_DCtx(dctx: *const ZSTD_DCtx) -> usize;
}
extern "C" {
pub fn ZSTD_createDDict_byReference(dictBuffer: *const ::libc::c_void,
dictSize: usize) -> *mut ZSTD_DDict;
}
extern "C" {
pub fn ZSTD_createDDict_advanced(dict: *const ::libc::c_void,
dictSize: usize,
byReference: ::libc::c_uint,
customMem: ZSTD_customMem)
-> *mut ZSTD_DDict;
}
extern "C" {
pub fn ZSTD_sizeof_DDict(ddict: *const ZSTD_DDict) -> usize;
}
extern "C" {
pub fn ZSTD_getDictID_fromDict(dict: *const ::libc::c_void,
dictSize: usize) -> ::libc::c_uint;
}
extern "C" {
pub fn ZSTD_getDictID_fromDDict(ddict: *const ZSTD_DDict)
-> ::libc::c_uint;
}
extern "C" {
pub fn ZSTD_getDictID_fromFrame(src: *const ::libc::c_void,
srcSize: usize) -> ::libc::c_uint;
}
extern "C" {
pub fn ZSTD_createCStream_advanced(customMem: ZSTD_customMem)
-> *mut ZSTD_CStream;
}
extern "C" {
pub fn ZSTD_initCStream_srcSize(zcs: *mut ZSTD_CStream,
compressionLevel: ::libc::c_int,
pledgedSrcSize: ::libc::c_ulonglong)
-> usize;
}
extern "C" {
pub fn ZSTD_initCStream_usingDict(zcs: *mut ZSTD_CStream,
dict: *const ::libc::c_void,
dictSize: usize,
compressionLevel: ::libc::c_int)
-> usize;
}
extern "C" {
pub fn ZSTD_initCStream_advanced(zcs: *mut ZSTD_CStream,
dict: *const ::libc::c_void,
dictSize: usize, params: ZSTD_parameters,
pledgedSrcSize: ::libc::c_ulonglong)
-> usize;
}
extern "C" {
pub fn ZSTD_initCStream_usingCDict(zcs: *mut ZSTD_CStream,
cdict: *const ZSTD_CDict) -> usize;
}
extern "C" {
pub fn ZSTD_resetCStream(zcs: *mut ZSTD_CStream,
pledgedSrcSize: ::libc::c_ulonglong) -> usize;
}
extern "C" {
pub fn ZSTD_sizeof_CStream(zcs: *const ZSTD_CStream) -> usize;
}
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum ZSTD_DStreamParameter_e { DStream_p_maxWindowSize = 0, }
extern "C" {
pub fn ZSTD_createDStream_advanced(customMem: ZSTD_customMem)
-> *mut ZSTD_DStream;
}
extern "C" {
pub fn ZSTD_initDStream_usingDict(zds: *mut ZSTD_DStream,
dict: *const ::libc::c_void,
dictSize: usize) -> usize;
}
extern "C" {
pub fn ZSTD_setDStreamParameter(zds: *mut ZSTD_DStream,
paramType: ZSTD_DStreamParameter_e,
paramValue: ::libc::c_uint) -> usize;
}
extern "C" {
pub fn ZSTD_initDStream_usingDDict(zds: *mut ZSTD_DStream,
ddict: *const ZSTD_DDict) -> usize;
}
extern "C" {
pub fn ZSTD_resetDStream(zds: *mut ZSTD_DStream) -> usize;
}
extern "C" {
pub fn ZSTD_sizeof_DStream(zds: *const ZSTD_DStream) -> usize;
}
extern "C" {
pub fn ZSTD_compressBegin(cctx: *mut ZSTD_CCtx,
compressionLevel: ::libc::c_int) -> usize;
}
extern "C" {
pub fn ZSTD_compressBegin_usingDict(cctx: *mut ZSTD_CCtx,
dict: *const ::libc::c_void,
dictSize: usize,
compressionLevel: ::libc::c_int)
-> usize;
}
extern "C" {
pub fn ZSTD_compressBegin_advanced(cctx: *mut ZSTD_CCtx,
dict: *const ::libc::c_void,
dictSize: usize,
params: ZSTD_parameters,
pledgedSrcSize: ::libc::c_ulonglong)
-> usize;
}
extern "C" {
pub fn ZSTD_copyCCtx(cctx: *mut ZSTD_CCtx, preparedCCtx: *const ZSTD_CCtx,
pledgedSrcSize: ::libc::c_ulonglong) -> usize;
}
extern "C" {
pub fn ZSTD_compressBegin_usingCDict(cctx: *mut ZSTD_CCtx,
cdict: *const ZSTD_CDict,
pledgedSrcSize: ::libc::c_ulonglong)
-> usize;
}
extern "C" {
pub fn ZSTD_compressContinue(cctx: *mut ZSTD_CCtx,
dst: *mut ::libc::c_void, dstCapacity: usize,
src: *const ::libc::c_void, srcSize: usize)
-> usize;
}
extern "C" {
pub fn ZSTD_compressEnd(cctx: *mut ZSTD_CCtx, dst: *mut ::libc::c_void,
dstCapacity: usize, src: *const ::libc::c_void,
srcSize: usize) -> usize;
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct ZSTD_frameParams {
pub frameContentSize: ::libc::c_ulonglong,
pub windowSize: ::libc::c_uint,
pub dictID: ::libc::c_uint,
pub checksumFlag: ::libc::c_uint,
}
#[test]
fn bindgen_test_layout_ZSTD_frameParams() {
assert_eq!(::core::mem::size_of::<ZSTD_frameParams>() , 24usize , concat !
( "Size of: " , stringify ! ( ZSTD_frameParams ) ));
assert_eq! (::core::mem::align_of::<ZSTD_frameParams>() , 8usize , concat
! ( "Alignment of " , stringify ! ( ZSTD_frameParams ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const ZSTD_frameParams ) ) . frameContentSize
as * const _ as usize } , 0usize , concat ! (
"Alignment of field: " , stringify ! ( ZSTD_frameParams ) ,
"::" , stringify ! ( frameContentSize ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const ZSTD_frameParams ) ) . windowSize as *
const _ as usize } , 8usize , concat ! (
"Alignment of field: " , stringify ! ( ZSTD_frameParams ) ,
"::" , stringify ! ( windowSize ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const ZSTD_frameParams ) ) . dictID as * const
_ as usize } , 12usize , concat ! (
"Alignment of field: " , stringify ! ( ZSTD_frameParams ) ,
"::" , stringify ! ( dictID ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const ZSTD_frameParams ) ) . checksumFlag as *
const _ as usize } , 16usize , concat ! (
"Alignment of field: " , stringify ! ( ZSTD_frameParams ) ,
"::" , stringify ! ( checksumFlag ) ));
}
impl Clone for ZSTD_frameParams {
fn clone(&self) -> Self { *self }
}
extern "C" {
pub fn ZSTD_getFrameParams(fparamsPtr: *mut ZSTD_frameParams,
src: *const ::libc::c_void, srcSize: usize)
-> usize;
}
extern "C" {
pub fn ZSTD_decompressBegin(dctx: *mut ZSTD_DCtx) -> usize;
}
extern "C" {
pub fn ZSTD_decompressBegin_usingDict(dctx: *mut ZSTD_DCtx,
dict: *const ::libc::c_void,
dictSize: usize) -> usize;
}
extern "C" {
pub fn ZSTD_copyDCtx(dctx: *mut ZSTD_DCtx,
preparedDCtx: *const ZSTD_DCtx);
}
extern "C" {
pub fn ZSTD_nextSrcSizeToDecompress(dctx: *mut ZSTD_DCtx) -> usize;
}
extern "C" {
pub fn ZSTD_decompressContinue(dctx: *mut ZSTD_DCtx,
dst: *mut ::libc::c_void,
dstCapacity: usize,
src: *const ::libc::c_void, srcSize: usize)
-> usize;
}
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum ZSTD_nextInputType_e {
ZSTDnit_frameHeader = 0,
ZSTDnit_blockHeader = 1,
ZSTDnit_block = 2,
ZSTDnit_lastBlock = 3,
ZSTDnit_checksum = 4,
ZSTDnit_skippableFrame = 5,
}
extern "C" {
pub fn ZSTD_nextInputType(dctx: *mut ZSTD_DCtx) -> ZSTD_nextInputType_e;
}
extern "C" {
pub fn ZSTD_getBlockSizeMax(cctx: *mut ZSTD_CCtx) -> usize;
}
extern "C" {
pub fn ZSTD_compressBlock(cctx: *mut ZSTD_CCtx, dst: *mut ::libc::c_void,
dstCapacity: usize, src: *const ::libc::c_void,
srcSize: usize) -> usize;
}
extern "C" {
pub fn ZSTD_decompressBlock(dctx: *mut ZSTD_DCtx,
dst: *mut ::libc::c_void, dstCapacity: usize,
src: *const ::libc::c_void, srcSize: usize)
-> usize;
}
extern "C" {
pub fn ZSTD_insertBlock(dctx: *mut ZSTD_DCtx,
blockStart: *const ::libc::c_void,
blockSize: usize) -> usize;
}
extern "C" {
pub fn ZDICT_trainFromBuffer(dictBuffer: *mut ::libc::c_void,
dictBufferCapacity: usize,
samplesBuffer: *const ::libc::c_void,
samplesSizes: *const usize,
nbSamples: ::libc::c_uint) -> usize;
}
extern "C" {
pub fn ZDICT_getDictID(dictBuffer: *const ::libc::c_void, dictSize: usize)
-> ::libc::c_uint;
}
extern "C" {
pub fn ZDICT_isError(errorCode: usize) -> ::libc::c_uint;
}
extern "C" {
pub fn ZDICT_getErrorName(errorCode: usize) -> *const ::libc::c_char;
}