diff --git a/csbindgen-tests/build.rs b/csbindgen-tests/build.rs index c01fa7f..03e1d8a 100644 --- a/csbindgen-tests/build.rs +++ b/csbindgen-tests/build.rs @@ -3,14 +3,20 @@ use std::error::Error; fn main() -> Result<(), Box> { bindgen::Builder::default() .header("c/lz4/lz4.h") - //.header("c/lz4/lz4hc.h") - //.header("c/lz4/lz4frame.h") - //.header("c/lz4/xxhash.h") + .header("c/lz4/lz4hc.h") + .header("c/lz4/lz4frame.h") + .header("c/lz4/xxhash.h") .generate()? .write_to_file("src/lz4.rs")?; - // TODO:build this - cc::Build::new().file("c/lz4/lz4.c").compile("lz4"); + cc::Build::new() + .files([ + "c/lz4/lz4.c", + "c/lz4/lz4hc.c", + "c/lz4/lz4frame.c", + "c/lz4/xxhash.c", + ]) + .compile("lz4"); // bindgen::Builder::default() // .header("c/zstd/zstd.h") @@ -31,7 +37,7 @@ fn main() -> Result<(), Box> { // .generate()? // .write_to_file("src/bullet3.rs")?; - csbindgen::Builder::new() + csbindgen::Builder::default() .input_bindgen_file("src/lz4.rs") .rust_method_prefix("csbindgen_") .rust_file_header("use super::lz4;") @@ -43,6 +49,12 @@ fn main() -> Result<(), Box> { .csharp_method_prefix("") .generate_to_file("src/lz4_ffi.rs", "../dotnet-sandbox/lz4_bindgen.cs")?; + csbindgen::Builder::default() + .input_extern_file("src/lib.rs") + .csharp_class_name("LibRust") + .csharp_dll_name("csbindgen_tests") + .generate_csharp_file("../dotnet-sandbox/method_call.cs")?; + // csbindgen::Builder::new() // .input_bindgen_file("src/zstd.rs") // .rust_method_prefix("csbindgen_zstd_") diff --git a/csbindgen-tests/src/lib.rs b/csbindgen-tests/src/lib.rs index c989422..f56b4d6 100644 --- a/csbindgen-tests/src/lib.rs +++ b/csbindgen-tests/src/lib.rs @@ -1,29 +1,39 @@ - #[allow(dead_code)] - #[allow(non_snake_case)] - #[allow(non_camel_case_types)] - #[allow(non_upper_case_globals)] - mod lz4; +#[allow(dead_code)] +#[allow(non_snake_case)] +#[allow(non_camel_case_types)] +#[allow(non_upper_case_globals)] +mod lz4; #[allow(dead_code)] #[allow(non_snake_case)] #[allow(non_camel_case_types)] mod lz4_ffi; +#[no_mangle] +pub extern "C" fn my_add(x: i32, y: i32) -> i32 { + x + y +} + #[test] fn build_test() { - let path = std::env::current_dir().unwrap(); - println!("starting dir: {}", path.display()); // csbindgen/csbindgen-tests + // let path = std::env::current_dir().unwrap(); + // println!("starting dir: {}", path.display()); // csbindgen/csbindgen-tests - // unsafe { - // let num = lz4::LZ4_versionNumber(); - // println!("lz4 num: {}", num); - // } + // // unsafe { + // // let num = lz4::LZ4_versionNumber(); + // // println!("lz4 num: {}", num); + // // } - csbindgen::Builder::new() - .input_bindgen_file("src/quiche.rs") - .rust_method_prefix("csbindgen_quiche_") - .csharp_class_name("LibQuiche") - .csharp_dll_name("libquiche") - .generate_to_file("src/quiche_ffi.rs", "../dotnet-sandbox/quiche_bindgen.cs") - .unwrap(); + // csbindgen::Builder::default() + // .input_bindgen_file("src/lz4.rs") + // .rust_method_prefix("csbindgen_") + // .rust_file_header("use super::lz4;") + // .rust_method_type_path("lz4") + // .csharp_class_name("LibLz4") + // .csharp_dll_name("csbindgen_tests") + // .csharp_dll_name_if("UNITY_IOS && !UNITY_EDITOR", "__Internal") + // .csharp_entry_point_prefix("csbindgen_") + // .csharp_method_prefix("") + // .generate_to_file("src/lz4_ffi.rs", "../dotnet-sandbox/lz4_bindgen.cs") + // .unwrap(); } diff --git a/csbindgen-tests/src/lz4.rs b/csbindgen-tests/src/lz4.rs index 72666da..3fbf825 100644 --- a/csbindgen-tests/src/lz4.rs +++ b/csbindgen-tests/src/lz4.rs @@ -31,6 +31,31 @@ pub const WINT_MIN: u32 = 0; pub const WINT_MAX: u32 = 65535; pub const LZ4_STREAM_MINSIZE: u32 = 16416; pub const LZ4_STREAMDECODE_MINSIZE: u32 = 32; +pub const LZ4HC_CLEVEL_MIN: u32 = 3; +pub const LZ4HC_CLEVEL_DEFAULT: u32 = 9; +pub const LZ4HC_CLEVEL_OPT_MIN: u32 = 10; +pub const LZ4HC_CLEVEL_MAX: u32 = 12; +pub const LZ4HC_DICTIONARY_LOGSIZE: u32 = 16; +pub const LZ4HC_MAXD: u32 = 65536; +pub const LZ4HC_MAXD_MASK: u32 = 65535; +pub const LZ4HC_HASH_LOG: u32 = 15; +pub const LZ4HC_HASHTABLESIZE: u32 = 32768; +pub const LZ4HC_HASH_MASK: u32 = 32767; +pub const LZ4_STREAMHC_MINSIZE: u32 = 262200; +pub const LZ4F_VERSION: u32 = 100; +pub const LZ4F_HEADER_SIZE_MIN: u32 = 7; +pub const LZ4F_HEADER_SIZE_MAX: u32 = 19; +pub const LZ4F_BLOCK_HEADER_SIZE: u32 = 4; +pub const LZ4F_BLOCK_CHECKSUM_SIZE: u32 = 4; +pub const LZ4F_CONTENT_CHECKSUM_SIZE: u32 = 4; +pub const LZ4F_MAGICNUMBER: u32 = 407708164; +pub const LZ4F_MAGIC_SKIPPABLE_START: u32 = 407710288; +pub const LZ4F_MIN_SIZE_TO_KNOW_HEADER_LENGTH: u32 = 5; +pub const XXHASH_H_5627135585666179: u32 = 1; +pub const XXH_VERSION_MAJOR: u32 = 0; +pub const XXH_VERSION_MINOR: u32 = 6; +pub const XXH_VERSION_RELEASE: u32 = 5; +pub const XXH_VERSION_NUMBER: u32 = 605; pub type wchar_t = ::std::os::raw::c_ushort; pub type max_align_t = f64; extern "C" { @@ -596,3 +621,999 @@ extern "C" { #[doc = " LZ4_resetStream() :\n An LZ4_stream_t structure must be initialized at least once.\n This is done with LZ4_initStream(), or LZ4_resetStream().\n Consider switching to LZ4_initStream(),\n invoking LZ4_resetStream() will trigger deprecation warnings in the future."] pub fn LZ4_resetStream(streamPtr: *mut LZ4_stream_t); } +extern "C" { + #[doc = " LZ4_compress_HC() :\n Compress data from `src` into `dst`, using the powerful but slower \"HC\" algorithm.\n `dst` must be already allocated.\n Compression is guaranteed to succeed if `dstCapacity >= LZ4_compressBound(srcSize)` (see \"lz4.h\")\n Max supported `srcSize` value is LZ4_MAX_INPUT_SIZE (see \"lz4.h\")\n `compressionLevel` : any value between 1 and LZ4HC_CLEVEL_MAX will work.\n Values > LZ4HC_CLEVEL_MAX behave the same as LZ4HC_CLEVEL_MAX.\n @return : the number of bytes written into 'dst'\n or 0 if compression fails."] + pub fn LZ4_compress_HC( + src: *const ::std::os::raw::c_char, + dst: *mut ::std::os::raw::c_char, + srcSize: ::std::os::raw::c_int, + dstCapacity: ::std::os::raw::c_int, + compressionLevel: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + #[doc = " LZ4_compress_HC_extStateHC() :\n Same as LZ4_compress_HC(), but using an externally allocated memory segment for `state`.\n `state` size is provided by LZ4_sizeofStateHC().\n Memory segment must be aligned on 8-bytes boundaries (which a normal malloc() should do properly)."] + pub fn LZ4_sizeofStateHC() -> ::std::os::raw::c_int; +} +extern "C" { + pub fn LZ4_compress_HC_extStateHC( + stateHC: *mut ::std::os::raw::c_void, + src: *const ::std::os::raw::c_char, + dst: *mut ::std::os::raw::c_char, + srcSize: ::std::os::raw::c_int, + maxDstSize: ::std::os::raw::c_int, + compressionLevel: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + #[doc = " LZ4_compress_HC_destSize() : v1.9.0+\n Will compress as much data as possible from `src`\n to fit into `targetDstSize` budget.\n Result is provided in 2 parts :\n @return : the number of bytes written into 'dst' (necessarily <= targetDstSize)\n or 0 if compression fails.\n `srcSizePtr` : on success, *srcSizePtr is updated to indicate how much bytes were read from `src`"] + pub fn LZ4_compress_HC_destSize( + stateHC: *mut ::std::os::raw::c_void, + src: *const ::std::os::raw::c_char, + dst: *mut ::std::os::raw::c_char, + srcSizePtr: *mut ::std::os::raw::c_int, + targetDstSize: ::std::os::raw::c_int, + compressionLevel: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +pub type LZ4_streamHC_t = LZ4_streamHC_u; +extern "C" { + #[doc = " LZ4_createStreamHC() and LZ4_freeStreamHC() :\n These functions create and release memory for LZ4 HC streaming state.\n Newly created states are automatically initialized.\n A same state can be used multiple times consecutively,\n starting with LZ4_resetStreamHC_fast() to start a new stream of blocks."] + pub fn LZ4_createStreamHC() -> *mut LZ4_streamHC_t; +} +extern "C" { + pub fn LZ4_freeStreamHC(streamHCPtr: *mut LZ4_streamHC_t) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn LZ4_resetStreamHC_fast( + streamHCPtr: *mut LZ4_streamHC_t, + compressionLevel: ::std::os::raw::c_int, + ); +} +extern "C" { + pub fn LZ4_loadDictHC( + streamHCPtr: *mut LZ4_streamHC_t, + dictionary: *const ::std::os::raw::c_char, + dictSize: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn LZ4_compress_HC_continue( + streamHCPtr: *mut LZ4_streamHC_t, + src: *const ::std::os::raw::c_char, + dst: *mut ::std::os::raw::c_char, + srcSize: ::std::os::raw::c_int, + maxDstSize: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + #[doc = " LZ4_compress_HC_continue_destSize() : v1.9.0+\n Similar to LZ4_compress_HC_continue(),\n but will read as much data as possible from `src`\n to fit into `targetDstSize` budget.\n Result is provided into 2 parts :\n @return : the number of bytes written into 'dst' (necessarily <= targetDstSize)\n or 0 if compression fails.\n `srcSizePtr` : on success, *srcSizePtr will be updated to indicate how much bytes were read from `src`.\n Note that this function may not consume the entire input."] + pub fn LZ4_compress_HC_continue_destSize( + LZ4_streamHCPtr: *mut LZ4_streamHC_t, + src: *const ::std::os::raw::c_char, + dst: *mut ::std::os::raw::c_char, + srcSizePtr: *mut ::std::os::raw::c_int, + targetDstSize: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn LZ4_saveDictHC( + streamHCPtr: *mut LZ4_streamHC_t, + safeBuffer: *mut ::std::os::raw::c_char, + maxDictSize: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct LZ4HC_CCtx_internal { + pub hashTable: [LZ4_u32; 32768usize], + pub chainTable: [LZ4_u16; 65536usize], + pub end: *const LZ4_byte, + pub prefixStart: *const LZ4_byte, + pub dictStart: *const LZ4_byte, + pub dictLimit: LZ4_u32, + pub lowLimit: LZ4_u32, + pub nextToUpdate: LZ4_u32, + pub compressionLevel: ::std::os::raw::c_short, + pub favorDecSpeed: LZ4_i8, + pub dirty: LZ4_i8, + pub dictCtx: *const LZ4HC_CCtx_internal, +} +#[test] +fn bindgen_test_layout_LZ4HC_CCtx_internal() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 262192usize, + concat!("Size of: ", stringify!(LZ4HC_CCtx_internal)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(LZ4HC_CCtx_internal)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).hashTable) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(LZ4HC_CCtx_internal), + "::", + stringify!(hashTable) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).chainTable) as usize - ptr as usize }, + 131072usize, + concat!( + "Offset of field: ", + stringify!(LZ4HC_CCtx_internal), + "::", + stringify!(chainTable) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, + 262144usize, + concat!( + "Offset of field: ", + stringify!(LZ4HC_CCtx_internal), + "::", + stringify!(end) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).prefixStart) as usize - ptr as usize }, + 262152usize, + concat!( + "Offset of field: ", + stringify!(LZ4HC_CCtx_internal), + "::", + stringify!(prefixStart) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).dictStart) as usize - ptr as usize }, + 262160usize, + concat!( + "Offset of field: ", + stringify!(LZ4HC_CCtx_internal), + "::", + stringify!(dictStart) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).dictLimit) as usize - ptr as usize }, + 262168usize, + concat!( + "Offset of field: ", + stringify!(LZ4HC_CCtx_internal), + "::", + stringify!(dictLimit) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).lowLimit) as usize - ptr as usize }, + 262172usize, + concat!( + "Offset of field: ", + stringify!(LZ4HC_CCtx_internal), + "::", + stringify!(lowLimit) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).nextToUpdate) as usize - ptr as usize }, + 262176usize, + concat!( + "Offset of field: ", + stringify!(LZ4HC_CCtx_internal), + "::", + stringify!(nextToUpdate) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).compressionLevel) as usize - ptr as usize }, + 262180usize, + concat!( + "Offset of field: ", + stringify!(LZ4HC_CCtx_internal), + "::", + stringify!(compressionLevel) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).favorDecSpeed) as usize - ptr as usize }, + 262182usize, + concat!( + "Offset of field: ", + stringify!(LZ4HC_CCtx_internal), + "::", + stringify!(favorDecSpeed) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).dirty) as usize - ptr as usize }, + 262183usize, + concat!( + "Offset of field: ", + stringify!(LZ4HC_CCtx_internal), + "::", + stringify!(dirty) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).dictCtx) as usize - ptr as usize }, + 262184usize, + concat!( + "Offset of field: ", + stringify!(LZ4HC_CCtx_internal), + "::", + stringify!(dictCtx) + ) + ); +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union LZ4_streamHC_u { + pub minStateSize: [::std::os::raw::c_char; 262200usize], + pub internal_donotuse: LZ4HC_CCtx_internal, +} +#[test] +fn bindgen_test_layout_LZ4_streamHC_u() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 262200usize, + concat!("Size of: ", stringify!(LZ4_streamHC_u)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(LZ4_streamHC_u)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).minStateSize) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(LZ4_streamHC_u), + "::", + stringify!(minStateSize) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).internal_donotuse) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(LZ4_streamHC_u), + "::", + stringify!(internal_donotuse) + ) + ); +} +extern "C" { + pub fn LZ4_initStreamHC( + buffer: *mut ::std::os::raw::c_void, + size: usize, + ) -> *mut LZ4_streamHC_t; +} +extern "C" { + pub fn LZ4_compressHC( + source: *const ::std::os::raw::c_char, + dest: *mut ::std::os::raw::c_char, + inputSize: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn LZ4_compressHC_limitedOutput( + source: *const ::std::os::raw::c_char, + dest: *mut ::std::os::raw::c_char, + inputSize: ::std::os::raw::c_int, + maxOutputSize: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn LZ4_compressHC2( + source: *const ::std::os::raw::c_char, + dest: *mut ::std::os::raw::c_char, + inputSize: ::std::os::raw::c_int, + compressionLevel: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn LZ4_compressHC2_limitedOutput( + source: *const ::std::os::raw::c_char, + dest: *mut ::std::os::raw::c_char, + inputSize: ::std::os::raw::c_int, + maxOutputSize: ::std::os::raw::c_int, + compressionLevel: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn LZ4_compressHC_withStateHC( + state: *mut ::std::os::raw::c_void, + source: *const ::std::os::raw::c_char, + dest: *mut ::std::os::raw::c_char, + inputSize: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn LZ4_compressHC_limitedOutput_withStateHC( + state: *mut ::std::os::raw::c_void, + source: *const ::std::os::raw::c_char, + dest: *mut ::std::os::raw::c_char, + inputSize: ::std::os::raw::c_int, + maxOutputSize: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn LZ4_compressHC2_withStateHC( + state: *mut ::std::os::raw::c_void, + source: *const ::std::os::raw::c_char, + dest: *mut ::std::os::raw::c_char, + inputSize: ::std::os::raw::c_int, + compressionLevel: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn LZ4_compressHC2_limitedOutput_withStateHC( + state: *mut ::std::os::raw::c_void, + source: *const ::std::os::raw::c_char, + dest: *mut ::std::os::raw::c_char, + inputSize: ::std::os::raw::c_int, + maxOutputSize: ::std::os::raw::c_int, + compressionLevel: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn LZ4_compressHC_continue( + LZ4_streamHCPtr: *mut LZ4_streamHC_t, + source: *const ::std::os::raw::c_char, + dest: *mut ::std::os::raw::c_char, + inputSize: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn LZ4_compressHC_limitedOutput_continue( + LZ4_streamHCPtr: *mut LZ4_streamHC_t, + source: *const ::std::os::raw::c_char, + dest: *mut ::std::os::raw::c_char, + inputSize: ::std::os::raw::c_int, + maxOutputSize: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn LZ4_createHC(inputBuffer: *const ::std::os::raw::c_char) -> *mut ::std::os::raw::c_void; +} +extern "C" { + pub fn LZ4_freeHC(LZ4HC_Data: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn LZ4_slideInputBufferHC( + LZ4HC_Data: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_char; +} +extern "C" { + pub fn LZ4_compressHC2_continue( + LZ4HC_Data: *mut ::std::os::raw::c_void, + source: *const ::std::os::raw::c_char, + dest: *mut ::std::os::raw::c_char, + inputSize: ::std::os::raw::c_int, + compressionLevel: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn LZ4_compressHC2_limitedOutput_continue( + LZ4HC_Data: *mut ::std::os::raw::c_void, + source: *const ::std::os::raw::c_char, + dest: *mut ::std::os::raw::c_char, + inputSize: ::std::os::raw::c_int, + maxOutputSize: ::std::os::raw::c_int, + compressionLevel: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn LZ4_sizeofStreamStateHC() -> ::std::os::raw::c_int; +} +extern "C" { + pub fn LZ4_resetStreamStateHC( + state: *mut ::std::os::raw::c_void, + inputBuffer: *mut ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn LZ4_resetStreamHC( + streamHCPtr: *mut LZ4_streamHC_t, + compressionLevel: ::std::os::raw::c_int, + ); +} +pub type LZ4F_errorCode_t = usize; +extern "C" { + pub fn LZ4F_isError(code: LZ4F_errorCode_t) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn LZ4F_getErrorName(code: LZ4F_errorCode_t) -> *const ::std::os::raw::c_char; +} +pub const LZ4F_blockSizeID_t_LZ4F_default: LZ4F_blockSizeID_t = 0; +pub const LZ4F_blockSizeID_t_LZ4F_max64KB: LZ4F_blockSizeID_t = 4; +pub const LZ4F_blockSizeID_t_LZ4F_max256KB: LZ4F_blockSizeID_t = 5; +pub const LZ4F_blockSizeID_t_LZ4F_max1MB: LZ4F_blockSizeID_t = 6; +pub const LZ4F_blockSizeID_t_LZ4F_max4MB: LZ4F_blockSizeID_t = 7; +pub type LZ4F_blockSizeID_t = ::std::os::raw::c_int; +pub const LZ4F_blockMode_t_LZ4F_blockLinked: LZ4F_blockMode_t = 0; +pub const LZ4F_blockMode_t_LZ4F_blockIndependent: LZ4F_blockMode_t = 1; +pub type LZ4F_blockMode_t = ::std::os::raw::c_int; +pub const LZ4F_contentChecksum_t_LZ4F_noContentChecksum: LZ4F_contentChecksum_t = 0; +pub const LZ4F_contentChecksum_t_LZ4F_contentChecksumEnabled: LZ4F_contentChecksum_t = 1; +pub type LZ4F_contentChecksum_t = ::std::os::raw::c_int; +pub const LZ4F_blockChecksum_t_LZ4F_noBlockChecksum: LZ4F_blockChecksum_t = 0; +pub const LZ4F_blockChecksum_t_LZ4F_blockChecksumEnabled: LZ4F_blockChecksum_t = 1; +pub type LZ4F_blockChecksum_t = ::std::os::raw::c_int; +pub const LZ4F_frameType_t_LZ4F_frame: LZ4F_frameType_t = 0; +pub const LZ4F_frameType_t_LZ4F_skippableFrame: LZ4F_frameType_t = 1; +pub type LZ4F_frameType_t = ::std::os::raw::c_int; +#[doc = " LZ4F_frameInfo_t :\n makes it possible to set or read frame parameters.\n Structure must be first init to 0, using memset() or LZ4F_INIT_FRAMEINFO,\n setting all parameters to default.\n It's then possible to update selectively some parameters"] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct LZ4F_frameInfo_t { + pub blockSizeID: LZ4F_blockSizeID_t, + pub blockMode: LZ4F_blockMode_t, + pub contentChecksumFlag: LZ4F_contentChecksum_t, + pub frameType: LZ4F_frameType_t, + pub contentSize: ::std::os::raw::c_ulonglong, + pub dictID: ::std::os::raw::c_uint, + pub blockChecksumFlag: LZ4F_blockChecksum_t, +} +#[test] +fn bindgen_test_layout_LZ4F_frameInfo_t() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 32usize, + concat!("Size of: ", stringify!(LZ4F_frameInfo_t)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(LZ4F_frameInfo_t)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).blockSizeID) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(LZ4F_frameInfo_t), + "::", + stringify!(blockSizeID) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).blockMode) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(LZ4F_frameInfo_t), + "::", + stringify!(blockMode) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).contentChecksumFlag) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(LZ4F_frameInfo_t), + "::", + stringify!(contentChecksumFlag) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).frameType) as usize - ptr as usize }, + 12usize, + concat!( + "Offset of field: ", + stringify!(LZ4F_frameInfo_t), + "::", + stringify!(frameType) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).contentSize) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(LZ4F_frameInfo_t), + "::", + stringify!(contentSize) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).dictID) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(LZ4F_frameInfo_t), + "::", + stringify!(dictID) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).blockChecksumFlag) as usize - ptr as usize }, + 28usize, + concat!( + "Offset of field: ", + stringify!(LZ4F_frameInfo_t), + "::", + stringify!(blockChecksumFlag) + ) + ); +} +#[doc = " LZ4F_preferences_t :\n makes it possible to supply advanced compression instructions to streaming interface.\n Structure must be first init to 0, using memset() or LZ4F_INIT_PREFERENCES,\n setting all parameters to default.\n All reserved fields must be set to zero."] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct LZ4F_preferences_t { + pub frameInfo: LZ4F_frameInfo_t, + pub compressionLevel: ::std::os::raw::c_int, + pub autoFlush: ::std::os::raw::c_uint, + pub favorDecSpeed: ::std::os::raw::c_uint, + pub reserved: [::std::os::raw::c_uint; 3usize], +} +#[test] +fn bindgen_test_layout_LZ4F_preferences_t() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 56usize, + concat!("Size of: ", stringify!(LZ4F_preferences_t)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(LZ4F_preferences_t)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).frameInfo) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(LZ4F_preferences_t), + "::", + stringify!(frameInfo) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).compressionLevel) as usize - ptr as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(LZ4F_preferences_t), + "::", + stringify!(compressionLevel) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).autoFlush) as usize - ptr as usize }, + 36usize, + concat!( + "Offset of field: ", + stringify!(LZ4F_preferences_t), + "::", + stringify!(autoFlush) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).favorDecSpeed) as usize - ptr as usize }, + 40usize, + concat!( + "Offset of field: ", + stringify!(LZ4F_preferences_t), + "::", + stringify!(favorDecSpeed) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).reserved) as usize - ptr as usize }, + 44usize, + concat!( + "Offset of field: ", + stringify!(LZ4F_preferences_t), + "::", + stringify!(reserved) + ) + ); +} +extern "C" { + pub fn LZ4F_compressionLevel_max() -> ::std::os::raw::c_int; +} +extern "C" { + #[doc = " LZ4F_compressFrameBound() :\n Returns the maximum possible compressed size with LZ4F_compressFrame() given srcSize and preferences.\n `preferencesPtr` is optional. It can be replaced by NULL, in which case, the function will assume default preferences.\n Note : this result is only usable with LZ4F_compressFrame().\n It may also be relevant to LZ4F_compressUpdate() _only if_ no flush() operation is ever performed."] + pub fn LZ4F_compressFrameBound( + srcSize: usize, + preferencesPtr: *const LZ4F_preferences_t, + ) -> usize; +} +extern "C" { + #[doc = " LZ4F_compressFrame() :\n Compress srcBuffer content into an LZ4-compressed frame.\n It's a one shot operation, all input content is consumed, and all output is generated.\n\n Note : it's a stateless operation (no LZ4F_cctx state needed).\n In order to reduce load on the allocator, LZ4F_compressFrame(), by default,\n uses the stack to allocate space for the compression state and some table.\n If this usage of the stack is too much for your application,\n consider compiling `lz4frame.c` with compile-time macro LZ4F_HEAPMODE set to 1 instead.\n All state allocations will use the Heap.\n It also means each invocation of LZ4F_compressFrame() will trigger several internal alloc/free invocations.\n\n @dstCapacity MUST be >= LZ4F_compressFrameBound(srcSize, preferencesPtr).\n @preferencesPtr is optional : one can provide NULL, in which case all preferences are set to default.\n @return : number of bytes written into dstBuffer.\n or an error code if it fails (can be tested using LZ4F_isError())"] + pub fn LZ4F_compressFrame( + dstBuffer: *mut ::std::os::raw::c_void, + dstCapacity: usize, + srcBuffer: *const ::std::os::raw::c_void, + srcSize: usize, + preferencesPtr: *const LZ4F_preferences_t, + ) -> usize; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct LZ4F_cctx_s { + _unused: [u8; 0], +} +pub type LZ4F_cctx = LZ4F_cctx_s; +pub type LZ4F_compressionContext_t = *mut LZ4F_cctx; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct LZ4F_compressOptions_t { + pub stableSrc: ::std::os::raw::c_uint, + pub reserved: [::std::os::raw::c_uint; 3usize], +} +#[test] +fn bindgen_test_layout_LZ4F_compressOptions_t() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(LZ4F_compressOptions_t)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(LZ4F_compressOptions_t)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).stableSrc) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(LZ4F_compressOptions_t), + "::", + stringify!(stableSrc) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).reserved) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(LZ4F_compressOptions_t), + "::", + stringify!(reserved) + ) + ); +} +extern "C" { + pub fn LZ4F_getVersion() -> ::std::os::raw::c_uint; +} +extern "C" { + #[doc = " LZ4F_createCompressionContext() :\n The first thing to do is to create a compressionContext object,\n which will keep track of operation state during streaming compression.\n This is achieved using LZ4F_createCompressionContext(), which takes as argument a version,\n and a pointer to LZ4F_cctx*, to write the resulting pointer into.\n @version provided MUST be LZ4F_VERSION. It is intended to track potential version mismatch, notably when using DLL.\n The function provides a pointer to a fully allocated LZ4F_cctx object.\n @cctxPtr MUST be != NULL.\n If @return != zero, context creation failed.\n A created compression context can be employed multiple times for consecutive streaming operations.\n Once all streaming compression jobs are completed,\n the state object can be released using LZ4F_freeCompressionContext().\n Note1 : LZ4F_freeCompressionContext() is always successful. Its return value can be ignored.\n Note2 : LZ4F_freeCompressionContext() works fine with NULL input pointers (do nothing)."] + pub fn LZ4F_createCompressionContext( + cctxPtr: *mut *mut LZ4F_cctx, + version: ::std::os::raw::c_uint, + ) -> LZ4F_errorCode_t; +} +extern "C" { + pub fn LZ4F_freeCompressionContext(cctx: *mut LZ4F_cctx) -> LZ4F_errorCode_t; +} +extern "C" { + #[doc = " LZ4F_compressBegin() :\n will write the frame header into dstBuffer.\n dstCapacity must be >= LZ4F_HEADER_SIZE_MAX bytes.\n `prefsPtr` is optional : NULL can be provided to set all preferences to default.\n @return : number of bytes written into dstBuffer for the header\n or an error code (which can be tested using LZ4F_isError())"] + pub fn LZ4F_compressBegin( + cctx: *mut LZ4F_cctx, + dstBuffer: *mut ::std::os::raw::c_void, + dstCapacity: usize, + prefsPtr: *const LZ4F_preferences_t, + ) -> usize; +} +extern "C" { + #[doc = " LZ4F_compressBound() :\n Provides minimum dstCapacity required to guarantee success of\n LZ4F_compressUpdate(), given a srcSize and preferences, for a worst case scenario.\n When srcSize==0, LZ4F_compressBound() provides an upper bound for LZ4F_flush() and LZ4F_compressEnd() instead.\n Note that the result is only valid for a single invocation of LZ4F_compressUpdate().\n When invoking LZ4F_compressUpdate() multiple times,\n if the output buffer is gradually filled up instead of emptied and re-used from its start,\n one must check if there is enough remaining capacity before each invocation, using LZ4F_compressBound().\n @return is always the same for a srcSize and prefsPtr.\n prefsPtr is optional : when NULL is provided, preferences will be set to cover worst case scenario.\n tech details :\n @return if automatic flushing is not enabled, includes the possibility that internal buffer might already be filled by up to (blockSize-1) bytes.\n It also includes frame footer (ending + checksum), since it might be generated by LZ4F_compressEnd().\n @return doesn't include frame header, as it was already generated by LZ4F_compressBegin()."] + pub fn LZ4F_compressBound(srcSize: usize, prefsPtr: *const LZ4F_preferences_t) -> usize; +} +extern "C" { + #[doc = " LZ4F_compressUpdate() :\n LZ4F_compressUpdate() can be called repetitively to compress as much data as necessary.\n Important rule: dstCapacity MUST be large enough to ensure operation success even in worst case situations.\n This value is provided by LZ4F_compressBound().\n If this condition is not respected, LZ4F_compress() will fail (result is an errorCode).\n After an error, the state is left in a UB state, and must be re-initialized or freed.\n If previously an uncompressed block was written, buffered data is flushed\n before appending compressed data is continued.\n `cOptPtr` is optional : NULL can be provided, in which case all options are set to default.\n @return : number of bytes written into `dstBuffer` (it can be zero, meaning input data was just buffered).\n or an error code if it fails (which can be tested using LZ4F_isError())"] + pub fn LZ4F_compressUpdate( + cctx: *mut LZ4F_cctx, + dstBuffer: *mut ::std::os::raw::c_void, + dstCapacity: usize, + srcBuffer: *const ::std::os::raw::c_void, + srcSize: usize, + cOptPtr: *const LZ4F_compressOptions_t, + ) -> usize; +} +extern "C" { + #[doc = " LZ4F_flush() :\n When data must be generated and sent immediately, without waiting for a block to be completely filled,\n it's possible to call LZ4_flush(). It will immediately compress any data buffered within cctx.\n `dstCapacity` must be large enough to ensure the operation will be successful.\n `cOptPtr` is optional : it's possible to provide NULL, all options will be set to default.\n @return : nb of bytes written into dstBuffer (can be zero, when there is no data stored within cctx)\n or an error code if it fails (which can be tested using LZ4F_isError())\n Note : LZ4F_flush() is guaranteed to be successful when dstCapacity >= LZ4F_compressBound(0, prefsPtr)."] + pub fn LZ4F_flush( + cctx: *mut LZ4F_cctx, + dstBuffer: *mut ::std::os::raw::c_void, + dstCapacity: usize, + cOptPtr: *const LZ4F_compressOptions_t, + ) -> usize; +} +extern "C" { + #[doc = " LZ4F_compressEnd() :\n To properly finish an LZ4 frame, invoke LZ4F_compressEnd().\n It will flush whatever data remained within `cctx` (like LZ4_flush())\n and properly finalize the frame, with an endMark and a checksum.\n `cOptPtr` is optional : NULL can be provided, in which case all options will be set to default.\n @return : nb of bytes written into dstBuffer, necessarily >= 4 (endMark),\n or an error code if it fails (which can be tested using LZ4F_isError())\n Note : LZ4F_compressEnd() is guaranteed to be successful when dstCapacity >= LZ4F_compressBound(0, prefsPtr).\n A successful call to LZ4F_compressEnd() makes `cctx` available again for another compression task."] + pub fn LZ4F_compressEnd( + cctx: *mut LZ4F_cctx, + dstBuffer: *mut ::std::os::raw::c_void, + dstCapacity: usize, + cOptPtr: *const LZ4F_compressOptions_t, + ) -> usize; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct LZ4F_dctx_s { + _unused: [u8; 0], +} +pub type LZ4F_dctx = LZ4F_dctx_s; +pub type LZ4F_decompressionContext_t = *mut LZ4F_dctx; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct LZ4F_decompressOptions_t { + pub stableDst: ::std::os::raw::c_uint, + pub skipChecksums: ::std::os::raw::c_uint, + pub reserved1: ::std::os::raw::c_uint, + pub reserved0: ::std::os::raw::c_uint, +} +#[test] +fn bindgen_test_layout_LZ4F_decompressOptions_t() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(LZ4F_decompressOptions_t)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(LZ4F_decompressOptions_t)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).stableDst) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(LZ4F_decompressOptions_t), + "::", + stringify!(stableDst) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).skipChecksums) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(LZ4F_decompressOptions_t), + "::", + stringify!(skipChecksums) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).reserved1) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(LZ4F_decompressOptions_t), + "::", + stringify!(reserved1) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).reserved0) as usize - ptr as usize }, + 12usize, + concat!( + "Offset of field: ", + stringify!(LZ4F_decompressOptions_t), + "::", + stringify!(reserved0) + ) + ); +} +extern "C" { + #[doc = " LZ4F_createDecompressionContext() :\n Create an LZ4F_dctx object, to track all decompression operations.\n @version provided MUST be LZ4F_VERSION.\n @dctxPtr MUST be valid.\n The function fills @dctxPtr with the value of a pointer to an allocated and initialized LZ4F_dctx object.\n The @return is an errorCode, which can be tested using LZ4F_isError().\n dctx memory can be released using LZ4F_freeDecompressionContext();\n Result of LZ4F_freeDecompressionContext() indicates current state of decompressionContext when being released.\n That is, it should be == 0 if decompression has been completed fully and correctly."] + pub fn LZ4F_createDecompressionContext( + dctxPtr: *mut *mut LZ4F_dctx, + version: ::std::os::raw::c_uint, + ) -> LZ4F_errorCode_t; +} +extern "C" { + pub fn LZ4F_freeDecompressionContext(dctx: *mut LZ4F_dctx) -> LZ4F_errorCode_t; +} +extern "C" { + #[doc = " LZ4F_headerSize() : v1.9.0+\n Provide the header size of a frame starting at `src`.\n `srcSize` must be >= LZ4F_MIN_SIZE_TO_KNOW_HEADER_LENGTH,\n which is enough to decode the header length.\n @return : size of frame header\n or an error code, which can be tested using LZ4F_isError()\n note : Frame header size is variable, but is guaranteed to be\n >= LZ4F_HEADER_SIZE_MIN bytes, and <= LZ4F_HEADER_SIZE_MAX bytes."] + pub fn LZ4F_headerSize(src: *const ::std::os::raw::c_void, srcSize: usize) -> usize; +} +extern "C" { + #[doc = " LZ4F_getFrameInfo() :\n This function extracts frame parameters (max blockSize, dictID, etc.).\n Its usage is optional: user can also invoke LZ4F_decompress() directly.\n\n Extracted information will fill an existing LZ4F_frameInfo_t structure.\n This can be useful for allocation and dictionary identification purposes.\n\n LZ4F_getFrameInfo() can work in the following situations :\n\n 1) At the beginning of a new frame, before any invocation of LZ4F_decompress().\n It will decode header from `srcBuffer`,\n consuming the header and starting the decoding process.\n\n Input size must be large enough to contain the full frame header.\n Frame header size can be known beforehand by LZ4F_headerSize().\n Frame header size is variable, but is guaranteed to be >= LZ4F_HEADER_SIZE_MIN bytes,\n and not more than <= LZ4F_HEADER_SIZE_MAX bytes.\n Hence, blindly providing LZ4F_HEADER_SIZE_MAX bytes or more will always work.\n It's allowed to provide more input data than the header size,\n LZ4F_getFrameInfo() will only consume the header.\n\n If input size is not large enough,\n aka if it's smaller than header size,\n function will fail and return an error code.\n\n 2) After decoding has been started,\n it's possible to invoke LZ4F_getFrameInfo() anytime\n to extract already decoded frame parameters stored within dctx.\n\n Note that, if decoding has barely started,\n and not yet read enough information to decode the header,\n LZ4F_getFrameInfo() will fail.\n\n The number of bytes consumed from srcBuffer will be updated in *srcSizePtr (necessarily <= original value).\n LZ4F_getFrameInfo() only consumes bytes when decoding has not yet started,\n and when decoding the header has been successful.\n Decompression must then resume from (srcBuffer + *srcSizePtr).\n\n @return : a hint about how many srcSize bytes LZ4F_decompress() expects for next call,\n or an error code which can be tested using LZ4F_isError().\n note 1 : in case of error, dctx is not modified. Decoding operation can resume from beginning safely.\n note 2 : frame parameters are *copied into* an already allocated LZ4F_frameInfo_t structure."] + pub fn LZ4F_getFrameInfo( + dctx: *mut LZ4F_dctx, + frameInfoPtr: *mut LZ4F_frameInfo_t, + srcBuffer: *const ::std::os::raw::c_void, + srcSizePtr: *mut usize, + ) -> usize; +} +extern "C" { + #[doc = " LZ4F_decompress() :\n Call this function repetitively to regenerate data compressed in `srcBuffer`.\n\n The function requires a valid dctx state.\n It will read up to *srcSizePtr bytes from srcBuffer,\n and decompress data into dstBuffer, of capacity *dstSizePtr.\n\n The nb of bytes consumed from srcBuffer will be written into *srcSizePtr (necessarily <= original value).\n The nb of bytes decompressed into dstBuffer will be written into *dstSizePtr (necessarily <= original value).\n\n The function does not necessarily read all input bytes, so always check value in *srcSizePtr.\n Unconsumed source data must be presented again in subsequent invocations.\n\n `dstBuffer` can freely change between each consecutive function invocation.\n `dstBuffer` content will be overwritten.\n\n Note: if `LZ4F_getFrameInfo()` is called before `LZ4F_decompress()`, srcBuffer must be updated to reflect\n the number of bytes consumed after reading the frame header. Failure to update srcBuffer before calling\n `LZ4F_decompress()` will cause decompression failure or, even worse, successful but incorrect decompression.\n See the `LZ4F_getFrameInfo()` docs for details.\n\n @return : an hint of how many `srcSize` bytes LZ4F_decompress() expects for next call.\n Schematically, it's the size of the current (or remaining) compressed block + header of next block.\n Respecting the hint provides some small speed benefit, because it skips intermediate buffers.\n This is just a hint though, it's always possible to provide any srcSize.\n\n When a frame is fully decoded, @return will be 0 (no more data expected).\n When provided with more bytes than necessary to decode a frame,\n LZ4F_decompress() will stop reading exactly at end of current frame, and @return 0.\n\n If decompression failed, @return is an error code, which can be tested using LZ4F_isError().\n After a decompression error, the `dctx` context is not resumable.\n Use LZ4F_resetDecompressionContext() to return to clean state.\n\n After a frame is fully decoded, dctx can be used again to decompress another frame."] + pub fn LZ4F_decompress( + dctx: *mut LZ4F_dctx, + dstBuffer: *mut ::std::os::raw::c_void, + dstSizePtr: *mut usize, + srcBuffer: *const ::std::os::raw::c_void, + srcSizePtr: *mut usize, + dOptPtr: *const LZ4F_decompressOptions_t, + ) -> usize; +} +extern "C" { + #[doc = " LZ4F_resetDecompressionContext() : added in v1.8.0\n In case of an error, the context is left in \"undefined\" state.\n In which case, it's necessary to reset it, before re-using it.\n This method can also be used to abruptly stop any unfinished decompression,\n and start a new one using same context resources."] + pub fn LZ4F_resetDecompressionContext(dctx: *mut LZ4F_dctx); +} +pub const XXH_errorcode_XXH_OK: XXH_errorcode = 0; +pub const XXH_errorcode_XXH_ERROR: XXH_errorcode = 1; +pub type XXH_errorcode = ::std::os::raw::c_int; +extern "C" { + pub fn XXH_versionNumber() -> ::std::os::raw::c_uint; +} +pub type XXH32_hash_t = ::std::os::raw::c_uint; +extern "C" { + #[doc = " XXH32() :\nCalculate the 32-bit hash of sequence \"length\" bytes stored at memory address \"input\".\nThe memory between input & input+length must be valid (allocated and read-accessible).\n\"seed\" can be used to alter the result predictably.\nSpeed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark) : 5.4 GB/s"] + pub fn XXH32( + input: *const ::std::os::raw::c_void, + length: usize, + seed: ::std::os::raw::c_uint, + ) -> XXH32_hash_t; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct XXH32_state_s { + _unused: [u8; 0], +} +pub type XXH32_state_t = XXH32_state_s; +extern "C" { + pub fn XXH32_createState() -> *mut XXH32_state_t; +} +extern "C" { + pub fn XXH32_freeState(statePtr: *mut XXH32_state_t) -> XXH_errorcode; +} +extern "C" { + pub fn XXH32_copyState(dst_state: *mut XXH32_state_t, src_state: *const XXH32_state_t); +} +extern "C" { + pub fn XXH32_reset(statePtr: *mut XXH32_state_t, seed: ::std::os::raw::c_uint) + -> XXH_errorcode; +} +extern "C" { + pub fn XXH32_update( + statePtr: *mut XXH32_state_t, + input: *const ::std::os::raw::c_void, + length: usize, + ) -> XXH_errorcode; +} +extern "C" { + pub fn XXH32_digest(statePtr: *const XXH32_state_t) -> XXH32_hash_t; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct XXH32_canonical_t { + pub digest: [::std::os::raw::c_uchar; 4usize], +} +#[test] +fn bindgen_test_layout_XXH32_canonical_t() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(XXH32_canonical_t)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(XXH32_canonical_t)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).digest) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(XXH32_canonical_t), + "::", + stringify!(digest) + ) + ); +} +extern "C" { + pub fn XXH32_canonicalFromHash(dst: *mut XXH32_canonical_t, hash: XXH32_hash_t); +} +extern "C" { + pub fn XXH32_hashFromCanonical(src: *const XXH32_canonical_t) -> XXH32_hash_t; +} +pub type XXH64_hash_t = ::std::os::raw::c_ulonglong; +extern "C" { + #[doc = " XXH64() :\nCalculate the 64-bit hash of sequence of length \"len\" stored at memory address \"input\".\n\"seed\" can be used to alter the result predictably.\nThis function runs faster on 64-bit systems, but slower on 32-bit systems (see benchmark)."] + pub fn XXH64( + input: *const ::std::os::raw::c_void, + length: usize, + seed: ::std::os::raw::c_ulonglong, + ) -> XXH64_hash_t; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct XXH64_state_s { + _unused: [u8; 0], +} +pub type XXH64_state_t = XXH64_state_s; +extern "C" { + pub fn XXH64_createState() -> *mut XXH64_state_t; +} +extern "C" { + pub fn XXH64_freeState(statePtr: *mut XXH64_state_t) -> XXH_errorcode; +} +extern "C" { + pub fn XXH64_copyState(dst_state: *mut XXH64_state_t, src_state: *const XXH64_state_t); +} +extern "C" { + pub fn XXH64_reset( + statePtr: *mut XXH64_state_t, + seed: ::std::os::raw::c_ulonglong, + ) -> XXH_errorcode; +} +extern "C" { + pub fn XXH64_update( + statePtr: *mut XXH64_state_t, + input: *const ::std::os::raw::c_void, + length: usize, + ) -> XXH_errorcode; +} +extern "C" { + pub fn XXH64_digest(statePtr: *const XXH64_state_t) -> XXH64_hash_t; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct XXH64_canonical_t { + pub digest: [::std::os::raw::c_uchar; 8usize], +} +#[test] +fn bindgen_test_layout_XXH64_canonical_t() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(XXH64_canonical_t)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(XXH64_canonical_t)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).digest) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(XXH64_canonical_t), + "::", + stringify!(digest) + ) + ); +} +extern "C" { + pub fn XXH64_canonicalFromHash(dst: *mut XXH64_canonical_t, hash: XXH64_hash_t); +} +extern "C" { + pub fn XXH64_hashFromCanonical(src: *const XXH64_canonical_t) -> XXH64_hash_t; +} diff --git a/csbindgen-tests/src/lz4_ffi.rs b/csbindgen-tests/src/lz4_ffi.rs index 898cd47..e199ce5 100644 --- a/csbindgen-tests/src/lz4_ffi.rs +++ b/csbindgen-tests/src/lz4_ffi.rs @@ -686,4 +686,1058 @@ pub extern "C" fn csbindgen_LZ4_resetStream( } } +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_compress_HC( + src: *const c_char, + dst: *mut c_char, + srcSize: c_int, + dstCapacity: c_int, + compressionLevel: c_int +) -> c_int +{ + unsafe { + return lz4::LZ4_compress_HC( + src, + dst, + srcSize, + dstCapacity, + compressionLevel + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_sizeofStateHC( + +) -> c_int +{ + unsafe { + return lz4::LZ4_sizeofStateHC( + + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_compress_HC_extStateHC( + stateHC: *mut c_void, + src: *const c_char, + dst: *mut c_char, + srcSize: c_int, + maxDstSize: c_int, + compressionLevel: c_int +) -> c_int +{ + unsafe { + return lz4::LZ4_compress_HC_extStateHC( + stateHC, + src, + dst, + srcSize, + maxDstSize, + compressionLevel + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_compress_HC_destSize( + stateHC: *mut c_void, + src: *const c_char, + dst: *mut c_char, + srcSizePtr: *mut c_int, + targetDstSize: c_int, + compressionLevel: c_int +) -> c_int +{ + unsafe { + return lz4::LZ4_compress_HC_destSize( + stateHC, + src, + dst, + srcSizePtr, + targetDstSize, + compressionLevel + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_createStreamHC( + +) -> *mut lz4::LZ4_streamHC_t +{ + unsafe { + return lz4::LZ4_createStreamHC( + + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_freeStreamHC( + streamHCPtr: *mut lz4::LZ4_streamHC_t +) -> c_int +{ + unsafe { + return lz4::LZ4_freeStreamHC( + streamHCPtr + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_resetStreamHC_fast( + streamHCPtr: *mut lz4::LZ4_streamHC_t, + compressionLevel: c_int +) +{ + unsafe { + return lz4::LZ4_resetStreamHC_fast( + streamHCPtr, + compressionLevel + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_loadDictHC( + streamHCPtr: *mut lz4::LZ4_streamHC_t, + dictionary: *const c_char, + dictSize: c_int +) -> c_int +{ + unsafe { + return lz4::LZ4_loadDictHC( + streamHCPtr, + dictionary, + dictSize + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_compress_HC_continue( + streamHCPtr: *mut lz4::LZ4_streamHC_t, + src: *const c_char, + dst: *mut c_char, + srcSize: c_int, + maxDstSize: c_int +) -> c_int +{ + unsafe { + return lz4::LZ4_compress_HC_continue( + streamHCPtr, + src, + dst, + srcSize, + maxDstSize + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_compress_HC_continue_destSize( + LZ4_streamHCPtr: *mut lz4::LZ4_streamHC_t, + src: *const c_char, + dst: *mut c_char, + srcSizePtr: *mut c_int, + targetDstSize: c_int +) -> c_int +{ + unsafe { + return lz4::LZ4_compress_HC_continue_destSize( + LZ4_streamHCPtr, + src, + dst, + srcSizePtr, + targetDstSize + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_saveDictHC( + streamHCPtr: *mut lz4::LZ4_streamHC_t, + safeBuffer: *mut c_char, + maxDictSize: c_int +) -> c_int +{ + unsafe { + return lz4::LZ4_saveDictHC( + streamHCPtr, + safeBuffer, + maxDictSize + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_initStreamHC( + buffer: *mut c_void, + size: usize +) -> *mut lz4::LZ4_streamHC_t +{ + unsafe { + return lz4::LZ4_initStreamHC( + buffer, + size + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_compressHC( + source: *const c_char, + dest: *mut c_char, + inputSize: c_int +) -> c_int +{ + unsafe { + return lz4::LZ4_compressHC( + source, + dest, + inputSize + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_compressHC_limitedOutput( + source: *const c_char, + dest: *mut c_char, + inputSize: c_int, + maxOutputSize: c_int +) -> c_int +{ + unsafe { + return lz4::LZ4_compressHC_limitedOutput( + source, + dest, + inputSize, + maxOutputSize + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_compressHC2( + source: *const c_char, + dest: *mut c_char, + inputSize: c_int, + compressionLevel: c_int +) -> c_int +{ + unsafe { + return lz4::LZ4_compressHC2( + source, + dest, + inputSize, + compressionLevel + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_compressHC2_limitedOutput( + source: *const c_char, + dest: *mut c_char, + inputSize: c_int, + maxOutputSize: c_int, + compressionLevel: c_int +) -> c_int +{ + unsafe { + return lz4::LZ4_compressHC2_limitedOutput( + source, + dest, + inputSize, + maxOutputSize, + compressionLevel + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_compressHC_withStateHC( + state: *mut c_void, + source: *const c_char, + dest: *mut c_char, + inputSize: c_int +) -> c_int +{ + unsafe { + return lz4::LZ4_compressHC_withStateHC( + state, + source, + dest, + inputSize + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_compressHC_limitedOutput_withStateHC( + state: *mut c_void, + source: *const c_char, + dest: *mut c_char, + inputSize: c_int, + maxOutputSize: c_int +) -> c_int +{ + unsafe { + return lz4::LZ4_compressHC_limitedOutput_withStateHC( + state, + source, + dest, + inputSize, + maxOutputSize + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_compressHC2_withStateHC( + state: *mut c_void, + source: *const c_char, + dest: *mut c_char, + inputSize: c_int, + compressionLevel: c_int +) -> c_int +{ + unsafe { + return lz4::LZ4_compressHC2_withStateHC( + state, + source, + dest, + inputSize, + compressionLevel + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_compressHC2_limitedOutput_withStateHC( + state: *mut c_void, + source: *const c_char, + dest: *mut c_char, + inputSize: c_int, + maxOutputSize: c_int, + compressionLevel: c_int +) -> c_int +{ + unsafe { + return lz4::LZ4_compressHC2_limitedOutput_withStateHC( + state, + source, + dest, + inputSize, + maxOutputSize, + compressionLevel + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_compressHC_continue( + LZ4_streamHCPtr: *mut lz4::LZ4_streamHC_t, + source: *const c_char, + dest: *mut c_char, + inputSize: c_int +) -> c_int +{ + unsafe { + return lz4::LZ4_compressHC_continue( + LZ4_streamHCPtr, + source, + dest, + inputSize + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_compressHC_limitedOutput_continue( + LZ4_streamHCPtr: *mut lz4::LZ4_streamHC_t, + source: *const c_char, + dest: *mut c_char, + inputSize: c_int, + maxOutputSize: c_int +) -> c_int +{ + unsafe { + return lz4::LZ4_compressHC_limitedOutput_continue( + LZ4_streamHCPtr, + source, + dest, + inputSize, + maxOutputSize + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_createHC( + inputBuffer: *const c_char +) -> *mut c_void +{ + unsafe { + return lz4::LZ4_createHC( + inputBuffer + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_freeHC( + LZ4HC_Data: *mut c_void +) -> c_int +{ + unsafe { + return lz4::LZ4_freeHC( + LZ4HC_Data + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_slideInputBufferHC( + LZ4HC_Data: *mut c_void +) -> *mut c_char +{ + unsafe { + return lz4::LZ4_slideInputBufferHC( + LZ4HC_Data + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_compressHC2_continue( + LZ4HC_Data: *mut c_void, + source: *const c_char, + dest: *mut c_char, + inputSize: c_int, + compressionLevel: c_int +) -> c_int +{ + unsafe { + return lz4::LZ4_compressHC2_continue( + LZ4HC_Data, + source, + dest, + inputSize, + compressionLevel + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_compressHC2_limitedOutput_continue( + LZ4HC_Data: *mut c_void, + source: *const c_char, + dest: *mut c_char, + inputSize: c_int, + maxOutputSize: c_int, + compressionLevel: c_int +) -> c_int +{ + unsafe { + return lz4::LZ4_compressHC2_limitedOutput_continue( + LZ4HC_Data, + source, + dest, + inputSize, + maxOutputSize, + compressionLevel + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_sizeofStreamStateHC( + +) -> c_int +{ + unsafe { + return lz4::LZ4_sizeofStreamStateHC( + + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_resetStreamStateHC( + state: *mut c_void, + inputBuffer: *mut c_char +) -> c_int +{ + unsafe { + return lz4::LZ4_resetStreamStateHC( + state, + inputBuffer + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4_resetStreamHC( + streamHCPtr: *mut lz4::LZ4_streamHC_t, + compressionLevel: c_int +) +{ + unsafe { + return lz4::LZ4_resetStreamHC( + streamHCPtr, + compressionLevel + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4F_isError( + code: lz4::LZ4F_errorCode_t +) -> c_uint +{ + unsafe { + return lz4::LZ4F_isError( + code + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4F_getErrorName( + code: lz4::LZ4F_errorCode_t +) -> *const c_char +{ + unsafe { + return lz4::LZ4F_getErrorName( + code + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4F_compressionLevel_max( + +) -> c_int +{ + unsafe { + return lz4::LZ4F_compressionLevel_max( + + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4F_compressFrameBound( + srcSize: usize, + preferencesPtr: *const lz4::LZ4F_preferences_t +) -> usize +{ + unsafe { + return lz4::LZ4F_compressFrameBound( + srcSize, + preferencesPtr + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4F_compressFrame( + dstBuffer: *mut c_void, + dstCapacity: usize, + srcBuffer: *const c_void, + srcSize: usize, + preferencesPtr: *const lz4::LZ4F_preferences_t +) -> usize +{ + unsafe { + return lz4::LZ4F_compressFrame( + dstBuffer, + dstCapacity, + srcBuffer, + srcSize, + preferencesPtr + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4F_getVersion( + +) -> c_uint +{ + unsafe { + return lz4::LZ4F_getVersion( + + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4F_createCompressionContext( + cctxPtr: *mut *mut lz4::LZ4F_cctx, + version: c_uint +) -> lz4::LZ4F_errorCode_t +{ + unsafe { + return lz4::LZ4F_createCompressionContext( + cctxPtr, + version + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4F_freeCompressionContext( + cctx: *mut lz4::LZ4F_cctx +) -> lz4::LZ4F_errorCode_t +{ + unsafe { + return lz4::LZ4F_freeCompressionContext( + cctx + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4F_compressBegin( + cctx: *mut lz4::LZ4F_cctx, + dstBuffer: *mut c_void, + dstCapacity: usize, + prefsPtr: *const lz4::LZ4F_preferences_t +) -> usize +{ + unsafe { + return lz4::LZ4F_compressBegin( + cctx, + dstBuffer, + dstCapacity, + prefsPtr + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4F_compressBound( + srcSize: usize, + prefsPtr: *const lz4::LZ4F_preferences_t +) -> usize +{ + unsafe { + return lz4::LZ4F_compressBound( + srcSize, + prefsPtr + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4F_compressUpdate( + cctx: *mut lz4::LZ4F_cctx, + dstBuffer: *mut c_void, + dstCapacity: usize, + srcBuffer: *const c_void, + srcSize: usize, + cOptPtr: *const lz4::LZ4F_compressOptions_t +) -> usize +{ + unsafe { + return lz4::LZ4F_compressUpdate( + cctx, + dstBuffer, + dstCapacity, + srcBuffer, + srcSize, + cOptPtr + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4F_flush( + cctx: *mut lz4::LZ4F_cctx, + dstBuffer: *mut c_void, + dstCapacity: usize, + cOptPtr: *const lz4::LZ4F_compressOptions_t +) -> usize +{ + unsafe { + return lz4::LZ4F_flush( + cctx, + dstBuffer, + dstCapacity, + cOptPtr + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4F_compressEnd( + cctx: *mut lz4::LZ4F_cctx, + dstBuffer: *mut c_void, + dstCapacity: usize, + cOptPtr: *const lz4::LZ4F_compressOptions_t +) -> usize +{ + unsafe { + return lz4::LZ4F_compressEnd( + cctx, + dstBuffer, + dstCapacity, + cOptPtr + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4F_createDecompressionContext( + dctxPtr: *mut *mut lz4::LZ4F_dctx, + version: c_uint +) -> lz4::LZ4F_errorCode_t +{ + unsafe { + return lz4::LZ4F_createDecompressionContext( + dctxPtr, + version + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4F_freeDecompressionContext( + dctx: *mut lz4::LZ4F_dctx +) -> lz4::LZ4F_errorCode_t +{ + unsafe { + return lz4::LZ4F_freeDecompressionContext( + dctx + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4F_headerSize( + src: *const c_void, + srcSize: usize +) -> usize +{ + unsafe { + return lz4::LZ4F_headerSize( + src, + srcSize + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4F_getFrameInfo( + dctx: *mut lz4::LZ4F_dctx, + frameInfoPtr: *mut lz4::LZ4F_frameInfo_t, + srcBuffer: *const c_void, + srcSizePtr: *mut usize +) -> usize +{ + unsafe { + return lz4::LZ4F_getFrameInfo( + dctx, + frameInfoPtr, + srcBuffer, + srcSizePtr + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4F_decompress( + dctx: *mut lz4::LZ4F_dctx, + dstBuffer: *mut c_void, + dstSizePtr: *mut usize, + srcBuffer: *const c_void, + srcSizePtr: *mut usize, + dOptPtr: *const lz4::LZ4F_decompressOptions_t +) -> usize +{ + unsafe { + return lz4::LZ4F_decompress( + dctx, + dstBuffer, + dstSizePtr, + srcBuffer, + srcSizePtr, + dOptPtr + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_LZ4F_resetDecompressionContext( + dctx: *mut lz4::LZ4F_dctx +) +{ + unsafe { + return lz4::LZ4F_resetDecompressionContext( + dctx + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_XXH_versionNumber( + +) -> c_uint +{ + unsafe { + return lz4::XXH_versionNumber( + + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_XXH32( + input: *const c_void, + length: usize, + seed: c_uint +) -> lz4::XXH32_hash_t +{ + unsafe { + return lz4::XXH32( + input, + length, + seed + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_XXH32_createState( + +) -> *mut lz4::XXH32_state_t +{ + unsafe { + return lz4::XXH32_createState( + + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_XXH32_freeState( + statePtr: *mut lz4::XXH32_state_t +) -> lz4::XXH_errorcode +{ + unsafe { + return lz4::XXH32_freeState( + statePtr + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_XXH32_copyState( + dst_state: *mut lz4::XXH32_state_t, + src_state: *const lz4::XXH32_state_t +) +{ + unsafe { + return lz4::XXH32_copyState( + dst_state, + src_state + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_XXH32_reset( + statePtr: *mut lz4::XXH32_state_t, + seed: c_uint +) -> lz4::XXH_errorcode +{ + unsafe { + return lz4::XXH32_reset( + statePtr, + seed + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_XXH32_update( + statePtr: *mut lz4::XXH32_state_t, + input: *const c_void, + length: usize +) -> lz4::XXH_errorcode +{ + unsafe { + return lz4::XXH32_update( + statePtr, + input, + length + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_XXH32_digest( + statePtr: *const lz4::XXH32_state_t +) -> lz4::XXH32_hash_t +{ + unsafe { + return lz4::XXH32_digest( + statePtr + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_XXH32_canonicalFromHash( + dst: *mut lz4::XXH32_canonical_t, + hash: lz4::XXH32_hash_t +) +{ + unsafe { + return lz4::XXH32_canonicalFromHash( + dst, + hash + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_XXH32_hashFromCanonical( + src: *const lz4::XXH32_canonical_t +) -> lz4::XXH32_hash_t +{ + unsafe { + return lz4::XXH32_hashFromCanonical( + src + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_XXH64( + input: *const c_void, + length: usize, + seed: c_ulonglong +) -> lz4::XXH64_hash_t +{ + unsafe { + return lz4::XXH64( + input, + length, + seed + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_XXH64_createState( + +) -> *mut lz4::XXH64_state_t +{ + unsafe { + return lz4::XXH64_createState( + + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_XXH64_freeState( + statePtr: *mut lz4::XXH64_state_t +) -> lz4::XXH_errorcode +{ + unsafe { + return lz4::XXH64_freeState( + statePtr + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_XXH64_copyState( + dst_state: *mut lz4::XXH64_state_t, + src_state: *const lz4::XXH64_state_t +) +{ + unsafe { + return lz4::XXH64_copyState( + dst_state, + src_state + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_XXH64_reset( + statePtr: *mut lz4::XXH64_state_t, + seed: c_ulonglong +) -> lz4::XXH_errorcode +{ + unsafe { + return lz4::XXH64_reset( + statePtr, + seed + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_XXH64_update( + statePtr: *mut lz4::XXH64_state_t, + input: *const c_void, + length: usize +) -> lz4::XXH_errorcode +{ + unsafe { + return lz4::XXH64_update( + statePtr, + input, + length + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_XXH64_digest( + statePtr: *const lz4::XXH64_state_t +) -> lz4::XXH64_hash_t +{ + unsafe { + return lz4::XXH64_digest( + statePtr + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_XXH64_canonicalFromHash( + dst: *mut lz4::XXH64_canonical_t, + hash: lz4::XXH64_hash_t +) +{ + unsafe { + return lz4::XXH64_canonicalFromHash( + dst, + hash + ) + } +} + +#[no_mangle] +pub extern "C" fn csbindgen_XXH64_hashFromCanonical( + src: *const lz4::XXH64_canonical_t +) -> lz4::XXH64_hash_t +{ + unsafe { + return lz4::XXH64_hashFromCanonical( + src + ) + } +} + \ No newline at end of file diff --git a/csbindgen/src/builder.rs b/csbindgen/src/builder.rs index 4025332..7a84186 100644 --- a/csbindgen/src/builder.rs +++ b/csbindgen/src/builder.rs @@ -5,7 +5,7 @@ use std::{ path::Path, }; -use crate::generate; +use crate::{generate, GenerateKind}; pub struct Builder { options: BindgenOptions, @@ -13,6 +13,7 @@ pub struct Builder { pub struct BindgenOptions { pub input_bindgen_file: String, + pub input_extern_file: String, pub method_filter: fn(method_name: String) -> bool, pub rust_method_type_path: String, pub rust_method_prefix: String, @@ -28,12 +29,13 @@ pub struct BindgenOptions { pub csharp_if_dll_name: String, } -impl Builder { - pub fn new() -> Self { +impl Default for Builder { + fn default() -> Self { Self { options: BindgenOptions { input_bindgen_file: "".to_string(), - method_filter: |x| !x.starts_with("_"), + input_extern_file: "".to_string(), + method_filter: |x| !x.starts_with('_'), rust_method_type_path: "".to_string(), rust_method_prefix: "".to_string(), rust_file_header: "".to_string(), @@ -49,6 +51,12 @@ impl Builder { }, } } +} + +impl Builder { + pub fn new() -> Self { + Self::default() + } /// Change an input .rs file(such as generated from bindgen) to generate binding. pub fn input_bindgen_file>(mut self, input_bindgen_file: T) -> Builder { @@ -56,7 +64,13 @@ impl Builder { self } - /// Filter generate method callback, default is `!x.starts_with("_")` + /// Change an input .rs file for collect extern methods to C# binding. + pub fn input_extern_file>(mut self, input_extern_file: T) -> Builder { + self.options.input_extern_file = input_extern_file.into(); + self + } + + /// Filter generate method callback, default is `!x.starts_with('_')` pub fn method_filter(mut self, method_filter: fn(method_name: String) -> bool) -> Builder { self.options.method_filter = method_filter; self @@ -141,35 +155,63 @@ impl Builder { self } - // pub fn generate_csharp_file>(&self, csharp_output_path: T) -> io::Result<()> { - // let mut file = OpenOptions::new() - // .write(true) - // .truncate(true) - // .create(true) - // .open(csharp_output_path.as_ref())?; + pub fn generate_csharp_file>( + &self, + csharp_output_path: P, + ) -> Result<(), Box> { + if !self.options.input_bindgen_file.is_empty() { + let (_, csharp) = generate(GenerateKind::InputBindgen, &self.options)?; - // let code = self.generate(); - // file.write_all(code.as_bytes())?; - // file.flush()?; + let mut csharp_file = make_file(csharp_output_path.as_ref())?; + csharp_file.write_all(csharp.as_bytes())?; + csharp_file.flush()?; + } - // Ok(()) - // } + if !self.options.input_extern_file.is_empty() { + let (_, csharp) = generate(GenerateKind::InputExtern, &self.options)?; + + let mut csharp_file = make_file(csharp_output_path.as_ref())?; + csharp_file.write_all(csharp.as_bytes())?; + csharp_file.flush()?; + } + + Ok(()) + } pub fn generate_to_file>( &self, rust_output_path: P, csharp_output_path: P, ) -> Result<(), Box> { - let (rust, csharp) = generate(&self.options)?; + if !self.options.input_bindgen_file.is_empty() { + let (rust, csharp) = generate(GenerateKind::InputBindgen, &self.options)?; - let mut rust_file = make_file(rust_output_path)?; - let mut csharp_file = make_file(csharp_output_path)?; + if let Some(rust) = rust { + let mut rust_file = make_file(rust_output_path.as_ref())?; - rust_file.write_all(rust.as_bytes())?; - rust_file.flush()?; + rust_file.write_all(rust.as_bytes())?; + rust_file.flush()?; + } - csharp_file.write_all(csharp.as_bytes())?; - csharp_file.flush()?; + let mut csharp_file = make_file(csharp_output_path.as_ref())?; + csharp_file.write_all(csharp.as_bytes())?; + csharp_file.flush()?; + } + + if !self.options.input_extern_file.is_empty() { + let (rust, csharp) = generate(GenerateKind::InputExtern, &self.options)?; + + if let Some(rust) = rust { + let mut rust_file = make_file(rust_output_path.as_ref())?; + + rust_file.write_all(rust.as_bytes())?; + rust_file.flush()?; + } + + let mut csharp_file = make_file(csharp_output_path.as_ref())?; + csharp_file.write_all(csharp.as_bytes())?; + csharp_file.flush()?; + } Ok(()) } diff --git a/csbindgen/src/emitter.rs b/csbindgen/src/emitter.rs index 555fdd2..4b41c90 100644 --- a/csbindgen/src/emitter.rs +++ b/csbindgen/src/emitter.rs @@ -74,7 +74,7 @@ use ::std::os::raw::*; " ); - return result; + result } pub fn emit_csharp( @@ -107,14 +107,14 @@ pub fn emit_csharp( x => format!("{x}{method_name}"), }; let return_type = match &item.return_type { - Some(x) => x.to_csharp_string(&options, &aliases), + Some(x) => x.to_csharp_string(options, aliases), None => "void".to_string(), }; let parameters = item .parameters .iter() - .map(|p| format!("{} {}", p.rust_type.to_csharp_string(&options, &aliases), p.escape_name())) + .map(|p| format!("{} {}", p.rust_type.to_csharp_string(options, aliases), p.escape_name())) .collect::>() .join(", "); @@ -124,7 +124,7 @@ pub fn emit_csharp( method_list_string.push_str_ln( format!(" public static extern {return_type} {method_prefix}{method_name}({parameters});").as_str(), ); - method_list_string.push_str("\n"); + method_list_string.push('\n'); } let mut structs_string = String::new(); @@ -147,7 +147,7 @@ pub fn emit_csharp( structs_string.push_str( format!( " public {} {}", - field.rust_type.to_csharp_string(&options, &aliases), + field.rust_type.to_csharp_string(options, aliases), field.name ) .as_str(), @@ -163,7 +163,7 @@ pub fn emit_csharp( structs_string.push_str_ln(";"); } structs_string.push_str_ln(" }"); - structs_string.push_str("\n"); + structs_string.push('\n'); } // TODO: for Unity, `__Intern`. @@ -189,5 +189,5 @@ namespace {namespace} " ); - return result; + result } diff --git a/csbindgen/src/lib.rs b/csbindgen/src/lib.rs index fb334b5..79eae7c 100644 --- a/csbindgen/src/lib.rs +++ b/csbindgen/src/lib.rs @@ -11,12 +11,26 @@ use emitter::*; use parser::*; use std::{collections::HashSet, error::Error}; -pub(crate) fn generate(options: &BindgenOptions) -> Result<(String, String), Box> { - let path = &options.input_bindgen_file; - let file_content = std::fs::read_to_string(path)?; +enum GenerateKind { + InputBindgen, + InputExtern, +} + +pub(crate) fn generate( + generate_kind: GenerateKind, + options: &BindgenOptions, +) -> Result<(Option, String), Box> { + let path = match generate_kind{ + GenerateKind::InputBindgen => &options.input_bindgen_file, + GenerateKind::InputExtern => &options.input_extern_file, + }; + let file_content = std::fs::read_to_string(path).expect(("input file not found, path:".to_string() + path).as_str()); let file_ast = syn::parse_file(file_content.as_str())?; - let methods = collect_method(&file_ast, options); + let (methods, generate_rust) = match generate_kind { + GenerateKind::InputBindgen => (collect_foreign_method(&file_ast, options), true), + GenerateKind::InputExtern => (collect_extern_method(&file_ast, options), false), + }; let aliases = collect_type_alias(&file_ast); let structs = collect_struct(&file_ast); @@ -42,10 +56,14 @@ pub(crate) fn generate(options: &BindgenOptions) -> Result<(String, String), Box let structs = reduce_struct(&structs, &using_types); - let rust = emit_rust_method(&methods, &options); - let csharp = emit_csharp(&methods, &aliases, &structs, &options); + let rust = if generate_rust { + Some(emit_rust_method(&methods, options)) + } else { + None + }; + let csharp = emit_csharp(&methods, &aliases, &structs, options); - return Ok((rust, csharp)); + Ok((rust, csharp)) } // #[test] diff --git a/csbindgen/src/parser.rs b/csbindgen/src/parser.rs index 341bd19..fbcce5c 100644 --- a/csbindgen/src/parser.rs +++ b/csbindgen/src/parser.rs @@ -2,59 +2,95 @@ use crate::{builder::BindgenOptions, type_meta::*}; use std::collections::{HashMap, HashSet}; use syn::{ForeignItem, Item, Pat, ReturnType}; -pub fn collect_method(ast: &syn::File, options: &BindgenOptions) -> Vec { +enum FnItem { + ForeignItem(syn::ForeignItemFn), + Item(syn::ItemFn), +} + +pub fn collect_foreign_method(ast: &syn::File, options: &BindgenOptions) -> Vec { let mut list: Vec = Vec::new(); for item in ast.items.iter() { if let Item::ForeignMod(m) = item { for item in m.items.iter() { if let ForeignItem::Fn(m) = item { - let method_name = m.sig.ident.to_string(); - - let mut parameters: Vec = Vec::new(); - let mut retrun_type: Option = None; - - // argument - for arg in m.sig.inputs.iter() { - if let syn::FnArg::Typed(t) = arg { - let mut parameter_name: String = "".to_string(); - - if let Pat::Ident(ident) = &*t.pat { - parameter_name = ident.ident.to_string(); - } - - let rust_type = parse_type(&t.ty); - - parameters.push(Parameter { - name: parameter_name, - rust_type: rust_type, - }); - } - } - - // return - if let ReturnType::Type(_, b) = &m.sig.output { - let rust_type = parse_type(&b); - if rust_type.type_name == "" { - continue; - } - - retrun_type = Some(rust_type); - } - - if method_name != "" && (&options.method_filter)(method_name.clone()) { - list.push(ExternMethod { - method_name: method_name.clone(), - parameters: parameters, - return_type: retrun_type, - }); + let method = parse_method(FnItem::ForeignItem(m.clone()), options); + if let Some(x) = method { + list.push(x); } } } } } - return list; + list +} + +pub fn collect_extern_method(ast: &syn::File, options: &BindgenOptions) -> Vec { + let mut list: Vec = Vec::new(); + + for item in ast.items.iter() { + if let Item::Fn(m) = item { + if let Some(_) = &m.sig.abi { // has extern + let method = parse_method(FnItem::Item(m.clone()), options); + if let Some(x) = method { + list.push(x); + } + } + } + } + + list +} + +fn parse_method(item: FnItem, options: &BindgenOptions) -> Option { + let sig = match item { + FnItem::ForeignItem(x) => x.sig, + FnItem::Item(x) => x.sig, + }; + + let method_name = sig.ident.to_string(); + + let mut parameters: Vec = Vec::new(); + let mut return_type: Option = None; + + // argument + for arg in sig.inputs.iter() { + if let syn::FnArg::Typed(t) = arg { + let mut parameter_name: String = "".to_string(); + + if let Pat::Ident(ident) = &*t.pat { + parameter_name = ident.ident.to_string(); + } + + let rust_type = parse_type(&t.ty); + + parameters.push(Parameter { + name: parameter_name, + rust_type, + }); + } + } + + // return + if let ReturnType::Type(_, b) = &sig.output { + let rust_type = parse_type(b); + if rust_type.type_name.is_empty() { + return None; + } + + return_type = Some(rust_type); + } + + if !method_name.is_empty() && (options.method_filter)(method_name.clone()) { + return Some(ExternMethod { + method_name, + parameters, + return_type, + }); + } + + None } pub fn collect_type_alias(ast: &syn::File) -> Vec<(String, RustType)> { @@ -85,7 +121,7 @@ pub fn collect_type_alias(ast: &syn::File) -> Vec<(String, RustType)> { } } } - return result; + result } pub fn collect_struct(ast: &syn::File) -> Vec { @@ -94,28 +130,28 @@ pub fn collect_struct(ast: &syn::File) -> Vec { for item in ast.items.iter() { if let Item::Union(t) = item { - let name = t.ident.to_string(); + let struct_name = t.ident.to_string(); let fields = collect_fields(&t.fields); result.push(RustStruct { - struct_name: name, - fields: fields, + struct_name, + fields, is_union: true, }); } else if let Item::Struct(t) = item { if let syn::Fields::Named(f) = &t.fields { - let name = t.ident.to_string(); - let fields = collect_fields(&f); + let struct_name = t.ident.to_string(); + let fields = collect_fields(f); result.push(RustStruct { - struct_name: name, - fields: fields, + struct_name, + fields, is_union: false, }); }; } } - return result; + result } fn collect_fields(fields: &syn::FieldsNamed) -> Vec { @@ -131,7 +167,7 @@ fn collect_fields(fields: &syn::FieldsNamed) -> Vec { } } - return result; + result } pub fn reduce_type_alias( @@ -152,7 +188,7 @@ pub fn reduce_type_alias( } } - return map; + map } pub fn reduce_struct(structs: &Vec, using_types: &HashSet) -> Vec { @@ -163,7 +199,7 @@ pub fn reduce_struct(structs: &Vec, using_types: &HashSet) - } } - return result; + result } fn parse_type(t: &syn::Type) -> RustType { @@ -206,13 +242,13 @@ fn parse_type(t: &syn::Type) -> RustType { _ => "".to_string(), }; - return RustType { + RustType { is_const: has_const, is_mut: has_mut, is_pointer: has_star, is_pointer_pointer: has_star_star, - is_fixed_array: (digits != ""), + is_fixed_array: !digits.is_empty(), type_name: name, fixed_array_digits: digits, - }; + } } diff --git a/csbindgen/src/type_meta.rs b/csbindgen/src/type_meta.rs index df416c6..071efd1 100644 --- a/csbindgen/src/type_meta.rs +++ b/csbindgen/src/type_meta.rs @@ -64,7 +64,7 @@ impl RustType { let mut sb = String::new(); if self.is_pointer || self.is_pointer_pointer { - sb.push_str("*"); + sb.push('*'); } if self.is_const { sb.push_str("const"); @@ -80,18 +80,19 @@ impl RustType { } } - sb.push_str(" "); + sb.push(' '); if self.is_fixed_array { - sb.push_str("["); + sb.push('['); sb.push_str(self.type_name.as_str()); sb.push_str("; "); sb.push_str(self.fixed_array_digits.as_str()); - sb.push_str("]"); + sb.push(']'); } else { - if !self.type_name.starts_with("c_") - && !(self.type_name == "usize" || self.type_name == "isize") - && !(type_path == "") + if !(self.type_name.starts_with("c_") + || self.type_name == "usize" + || self.type_name == "isize" + || (type_path.is_empty())) { sb.push_str(type_path); sb.push_str("::"); @@ -157,7 +158,7 @@ impl RustType { if self.is_fixed_array { sb.push_str("fixed "); - let type_name = convert_type_name(use_type.type_name.as_str(), &options); + let type_name = convert_type_name(use_type.type_name.as_str(), options); let type_name = match type_name.as_str() { // C# fixed allow types "bool" | "byte" | "short" | "int" | "long" | "char" | "sbyte" | "ushort" @@ -167,10 +168,10 @@ impl RustType { sb.push_str(type_name.as_str()); } else { - sb.push_str(convert_type_name(use_type.type_name.as_str(), &options).as_str()); + sb.push_str(convert_type_name(use_type.type_name.as_str(), options).as_str()); if use_alias { if use_type.is_pointer { - sb.push_str("*"); + sb.push('*'); } if use_type.is_pointer_pointer { sb.push_str("**"); @@ -178,7 +179,7 @@ impl RustType { } if self.is_pointer { - sb.push_str("*"); + sb.push('*'); } if self.is_pointer_pointer { sb.push_str("**"); diff --git a/dotnet-sandbox/Program.cs b/dotnet-sandbox/Program.cs index 6fc61a8..95ed354 100644 --- a/dotnet-sandbox/Program.cs +++ b/dotnet-sandbox/Program.cs @@ -7,6 +7,9 @@ unsafe { //var v = NativeMethods(); + var z = LibRust.my_add(100, 200); + Console.WriteLine(z); + var s = LibLz4.LZ4_versionString(); var ss = new string((sbyte*)s); Console.WriteLine(ss); diff --git a/dotnet-sandbox/lz4_bindgen.cs b/dotnet-sandbox/lz4_bindgen.cs index b3cd400..e1e6818 100644 --- a/dotnet-sandbox/lz4_bindgen.cs +++ b/dotnet-sandbox/lz4_bindgen.cs @@ -142,6 +142,210 @@ namespace CsBindgen [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_resetStream", CallingConvention = CallingConvention.Cdecl)] public static extern void LZ4_resetStream(LZ4_stream_u* streamPtr); + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compress_HC", CallingConvention = CallingConvention.Cdecl)] + public static extern int LZ4_compress_HC(byte* src, byte* dst, int srcSize, int dstCapacity, int compressionLevel); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_sizeofStateHC", CallingConvention = CallingConvention.Cdecl)] + public static extern int LZ4_sizeofStateHC(); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compress_HC_extStateHC", CallingConvention = CallingConvention.Cdecl)] + public static extern int LZ4_compress_HC_extStateHC(void* stateHC, byte* src, byte* dst, int srcSize, int maxDstSize, int compressionLevel); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compress_HC_destSize", CallingConvention = CallingConvention.Cdecl)] + public static extern int LZ4_compress_HC_destSize(void* stateHC, byte* src, byte* dst, int* srcSizePtr, int targetDstSize, int compressionLevel); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_createStreamHC", CallingConvention = CallingConvention.Cdecl)] + public static extern LZ4_streamHC_u* LZ4_createStreamHC(); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_freeStreamHC", CallingConvention = CallingConvention.Cdecl)] + public static extern int LZ4_freeStreamHC(LZ4_streamHC_u* streamHCPtr); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_resetStreamHC_fast", CallingConvention = CallingConvention.Cdecl)] + public static extern void LZ4_resetStreamHC_fast(LZ4_streamHC_u* streamHCPtr, int compressionLevel); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_loadDictHC", CallingConvention = CallingConvention.Cdecl)] + public static extern int LZ4_loadDictHC(LZ4_streamHC_u* streamHCPtr, byte* dictionary, int dictSize); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compress_HC_continue", CallingConvention = CallingConvention.Cdecl)] + public static extern int LZ4_compress_HC_continue(LZ4_streamHC_u* streamHCPtr, byte* src, byte* dst, int srcSize, int maxDstSize); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compress_HC_continue_destSize", CallingConvention = CallingConvention.Cdecl)] + public static extern int LZ4_compress_HC_continue_destSize(LZ4_streamHC_u* LZ4_streamHCPtr, byte* src, byte* dst, int* srcSizePtr, int targetDstSize); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_saveDictHC", CallingConvention = CallingConvention.Cdecl)] + public static extern int LZ4_saveDictHC(LZ4_streamHC_u* streamHCPtr, byte* safeBuffer, int maxDictSize); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_initStreamHC", CallingConvention = CallingConvention.Cdecl)] + public static extern LZ4_streamHC_u* LZ4_initStreamHC(void* buffer, UIntPtr size); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compressHC", CallingConvention = CallingConvention.Cdecl)] + public static extern int LZ4_compressHC(byte* source, byte* dest, int inputSize); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compressHC_limitedOutput", CallingConvention = CallingConvention.Cdecl)] + public static extern int LZ4_compressHC_limitedOutput(byte* source, byte* dest, int inputSize, int maxOutputSize); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compressHC2", CallingConvention = CallingConvention.Cdecl)] + public static extern int LZ4_compressHC2(byte* source, byte* dest, int inputSize, int compressionLevel); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compressHC2_limitedOutput", CallingConvention = CallingConvention.Cdecl)] + public static extern int LZ4_compressHC2_limitedOutput(byte* source, byte* dest, int inputSize, int maxOutputSize, int compressionLevel); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compressHC_withStateHC", CallingConvention = CallingConvention.Cdecl)] + public static extern int LZ4_compressHC_withStateHC(void* state, byte* source, byte* dest, int inputSize); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compressHC_limitedOutput_withStateHC", CallingConvention = CallingConvention.Cdecl)] + public static extern int LZ4_compressHC_limitedOutput_withStateHC(void* state, byte* source, byte* dest, int inputSize, int maxOutputSize); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compressHC2_withStateHC", CallingConvention = CallingConvention.Cdecl)] + public static extern int LZ4_compressHC2_withStateHC(void* state, byte* source, byte* dest, int inputSize, int compressionLevel); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compressHC2_limitedOutput_withStateHC", CallingConvention = CallingConvention.Cdecl)] + public static extern int LZ4_compressHC2_limitedOutput_withStateHC(void* state, byte* source, byte* dest, int inputSize, int maxOutputSize, int compressionLevel); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compressHC_continue", CallingConvention = CallingConvention.Cdecl)] + public static extern int LZ4_compressHC_continue(LZ4_streamHC_u* LZ4_streamHCPtr, byte* source, byte* dest, int inputSize); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compressHC_limitedOutput_continue", CallingConvention = CallingConvention.Cdecl)] + public static extern int LZ4_compressHC_limitedOutput_continue(LZ4_streamHC_u* LZ4_streamHCPtr, byte* source, byte* dest, int inputSize, int maxOutputSize); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_createHC", CallingConvention = CallingConvention.Cdecl)] + public static extern void* LZ4_createHC(byte* inputBuffer); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_freeHC", CallingConvention = CallingConvention.Cdecl)] + public static extern int LZ4_freeHC(void* LZ4HC_Data); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_slideInputBufferHC", CallingConvention = CallingConvention.Cdecl)] + public static extern byte* LZ4_slideInputBufferHC(void* LZ4HC_Data); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compressHC2_continue", CallingConvention = CallingConvention.Cdecl)] + public static extern int LZ4_compressHC2_continue(void* LZ4HC_Data, byte* source, byte* dest, int inputSize, int compressionLevel); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compressHC2_limitedOutput_continue", CallingConvention = CallingConvention.Cdecl)] + public static extern int LZ4_compressHC2_limitedOutput_continue(void* LZ4HC_Data, byte* source, byte* dest, int inputSize, int maxOutputSize, int compressionLevel); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_sizeofStreamStateHC", CallingConvention = CallingConvention.Cdecl)] + public static extern int LZ4_sizeofStreamStateHC(); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_resetStreamStateHC", CallingConvention = CallingConvention.Cdecl)] + public static extern int LZ4_resetStreamStateHC(void* state, byte* inputBuffer); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4_resetStreamHC", CallingConvention = CallingConvention.Cdecl)] + public static extern void LZ4_resetStreamHC(LZ4_streamHC_u* streamHCPtr, int compressionLevel); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_isError", CallingConvention = CallingConvention.Cdecl)] + public static extern uint LZ4F_isError(UIntPtr code); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_getErrorName", CallingConvention = CallingConvention.Cdecl)] + public static extern byte* LZ4F_getErrorName(UIntPtr code); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_compressionLevel_max", CallingConvention = CallingConvention.Cdecl)] + public static extern int LZ4F_compressionLevel_max(); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_compressFrameBound", CallingConvention = CallingConvention.Cdecl)] + public static extern UIntPtr LZ4F_compressFrameBound(UIntPtr srcSize, LZ4F_preferences_t* preferencesPtr); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_compressFrame", CallingConvention = CallingConvention.Cdecl)] + public static extern UIntPtr LZ4F_compressFrame(void* dstBuffer, UIntPtr dstCapacity, void* srcBuffer, UIntPtr srcSize, LZ4F_preferences_t* preferencesPtr); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_getVersion", CallingConvention = CallingConvention.Cdecl)] + public static extern uint LZ4F_getVersion(); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_createCompressionContext", CallingConvention = CallingConvention.Cdecl)] + public static extern UIntPtr LZ4F_createCompressionContext(LZ4F_cctx_s** cctxPtr, uint version); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_freeCompressionContext", CallingConvention = CallingConvention.Cdecl)] + public static extern UIntPtr LZ4F_freeCompressionContext(LZ4F_cctx_s* cctx); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_compressBegin", CallingConvention = CallingConvention.Cdecl)] + public static extern UIntPtr LZ4F_compressBegin(LZ4F_cctx_s* cctx, void* dstBuffer, UIntPtr dstCapacity, LZ4F_preferences_t* prefsPtr); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_compressBound", CallingConvention = CallingConvention.Cdecl)] + public static extern UIntPtr LZ4F_compressBound(UIntPtr srcSize, LZ4F_preferences_t* prefsPtr); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_compressUpdate", CallingConvention = CallingConvention.Cdecl)] + public static extern UIntPtr LZ4F_compressUpdate(LZ4F_cctx_s* cctx, void* dstBuffer, UIntPtr dstCapacity, void* srcBuffer, UIntPtr srcSize, LZ4F_compressOptions_t* cOptPtr); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_flush", CallingConvention = CallingConvention.Cdecl)] + public static extern UIntPtr LZ4F_flush(LZ4F_cctx_s* cctx, void* dstBuffer, UIntPtr dstCapacity, LZ4F_compressOptions_t* cOptPtr); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_compressEnd", CallingConvention = CallingConvention.Cdecl)] + public static extern UIntPtr LZ4F_compressEnd(LZ4F_cctx_s* cctx, void* dstBuffer, UIntPtr dstCapacity, LZ4F_compressOptions_t* cOptPtr); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_createDecompressionContext", CallingConvention = CallingConvention.Cdecl)] + public static extern UIntPtr LZ4F_createDecompressionContext(LZ4F_dctx_s** dctxPtr, uint version); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_freeDecompressionContext", CallingConvention = CallingConvention.Cdecl)] + public static extern UIntPtr LZ4F_freeDecompressionContext(LZ4F_dctx_s* dctx); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_headerSize", CallingConvention = CallingConvention.Cdecl)] + public static extern UIntPtr LZ4F_headerSize(void* src, UIntPtr srcSize); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_getFrameInfo", CallingConvention = CallingConvention.Cdecl)] + public static extern UIntPtr LZ4F_getFrameInfo(LZ4F_dctx_s* dctx, LZ4F_frameInfo_t* frameInfoPtr, void* srcBuffer, UIntPtr* srcSizePtr); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_decompress", CallingConvention = CallingConvention.Cdecl)] + public static extern UIntPtr LZ4F_decompress(LZ4F_dctx_s* dctx, void* dstBuffer, UIntPtr* dstSizePtr, void* srcBuffer, UIntPtr* srcSizePtr, LZ4F_decompressOptions_t* dOptPtr); + + [DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_resetDecompressionContext", CallingConvention = CallingConvention.Cdecl)] + public static extern void LZ4F_resetDecompressionContext(LZ4F_dctx_s* dctx); + + [DllImport(__DllName, EntryPoint = "csbindgen_XXH_versionNumber", CallingConvention = CallingConvention.Cdecl)] + public static extern uint XXH_versionNumber(); + + [DllImport(__DllName, EntryPoint = "csbindgen_XXH32", CallingConvention = CallingConvention.Cdecl)] + public static extern uint XXH32(void* input, UIntPtr length, uint seed); + + [DllImport(__DllName, EntryPoint = "csbindgen_XXH32_createState", CallingConvention = CallingConvention.Cdecl)] + public static extern XXH32_state_s* XXH32_createState(); + + [DllImport(__DllName, EntryPoint = "csbindgen_XXH32_freeState", CallingConvention = CallingConvention.Cdecl)] + public static extern int XXH32_freeState(XXH32_state_s* statePtr); + + [DllImport(__DllName, EntryPoint = "csbindgen_XXH32_copyState", CallingConvention = CallingConvention.Cdecl)] + public static extern void XXH32_copyState(XXH32_state_s* dst_state, XXH32_state_s* src_state); + + [DllImport(__DllName, EntryPoint = "csbindgen_XXH32_reset", CallingConvention = CallingConvention.Cdecl)] + public static extern int XXH32_reset(XXH32_state_s* statePtr, uint seed); + + [DllImport(__DllName, EntryPoint = "csbindgen_XXH32_update", CallingConvention = CallingConvention.Cdecl)] + public static extern int XXH32_update(XXH32_state_s* statePtr, void* input, UIntPtr length); + + [DllImport(__DllName, EntryPoint = "csbindgen_XXH32_digest", CallingConvention = CallingConvention.Cdecl)] + public static extern uint XXH32_digest(XXH32_state_s* statePtr); + + [DllImport(__DllName, EntryPoint = "csbindgen_XXH32_canonicalFromHash", CallingConvention = CallingConvention.Cdecl)] + public static extern void XXH32_canonicalFromHash(XXH32_canonical_t* dst, uint hash); + + [DllImport(__DllName, EntryPoint = "csbindgen_XXH32_hashFromCanonical", CallingConvention = CallingConvention.Cdecl)] + public static extern uint XXH32_hashFromCanonical(XXH32_canonical_t* src); + + [DllImport(__DllName, EntryPoint = "csbindgen_XXH64", CallingConvention = CallingConvention.Cdecl)] + public static extern ulong XXH64(void* input, UIntPtr length, ulong seed); + + [DllImport(__DllName, EntryPoint = "csbindgen_XXH64_createState", CallingConvention = CallingConvention.Cdecl)] + public static extern XXH64_state_s* XXH64_createState(); + + [DllImport(__DllName, EntryPoint = "csbindgen_XXH64_freeState", CallingConvention = CallingConvention.Cdecl)] + public static extern int XXH64_freeState(XXH64_state_s* statePtr); + + [DllImport(__DllName, EntryPoint = "csbindgen_XXH64_copyState", CallingConvention = CallingConvention.Cdecl)] + public static extern void XXH64_copyState(XXH64_state_s* dst_state, XXH64_state_s* src_state); + + [DllImport(__DllName, EntryPoint = "csbindgen_XXH64_reset", CallingConvention = CallingConvention.Cdecl)] + public static extern int XXH64_reset(XXH64_state_s* statePtr, ulong seed); + + [DllImport(__DllName, EntryPoint = "csbindgen_XXH64_update", CallingConvention = CallingConvention.Cdecl)] + public static extern int XXH64_update(XXH64_state_s* statePtr, void* input, UIntPtr length); + + [DllImport(__DllName, EntryPoint = "csbindgen_XXH64_digest", CallingConvention = CallingConvention.Cdecl)] + public static extern ulong XXH64_digest(XXH64_state_s* statePtr); + + [DllImport(__DllName, EntryPoint = "csbindgen_XXH64_canonicalFromHash", CallingConvention = CallingConvention.Cdecl)] + public static extern void XXH64_canonicalFromHash(XXH64_canonical_t* dst, ulong hash); + + [DllImport(__DllName, EntryPoint = "csbindgen_XXH64_hashFromCanonical", CallingConvention = CallingConvention.Cdecl)] + public static extern ulong XXH64_hashFromCanonical(XXH64_canonical_t* src); + } @@ -183,6 +387,106 @@ namespace CsBindgen public LZ4_streamDecode_t_internal internal_donotuse; } + [StructLayout(LayoutKind.Sequential)] + public unsafe struct LZ4HC_CCtx_internal + { + public fixed uint hashTable[32768]; + public fixed ushort chainTable[65536]; + public byte* end; + public byte* prefixStart; + public byte* dictStart; + public uint dictLimit; + public uint lowLimit; + public uint nextToUpdate; + public short compressionLevel; + public sbyte favorDecSpeed; + public sbyte dirty; + public LZ4HC_CCtx_internal* dictCtx; + } + + [StructLayout(LayoutKind.Explicit)] + public unsafe struct LZ4_streamHC_u + { + [FieldOffset(0)] + public fixed byte minStateSize[262200]; + [FieldOffset(0)] + public LZ4HC_CCtx_internal internal_donotuse; + } + + [StructLayout(LayoutKind.Sequential)] + public unsafe struct LZ4F_frameInfo_t + { + public int blockSizeID; + public int blockMode; + public int contentChecksumFlag; + public int frameType; + public ulong contentSize; + public uint dictID; + public int blockChecksumFlag; + } + + [StructLayout(LayoutKind.Sequential)] + public unsafe struct LZ4F_preferences_t + { + public LZ4F_frameInfo_t frameInfo; + public int compressionLevel; + public uint autoFlush; + public uint favorDecSpeed; + public fixed uint reserved[3]; + } + + [StructLayout(LayoutKind.Sequential)] + public unsafe struct LZ4F_cctx_s + { + public fixed byte _unused[1]; + } + + [StructLayout(LayoutKind.Sequential)] + public unsafe struct LZ4F_compressOptions_t + { + public uint stableSrc; + public fixed uint reserved[3]; + } + + [StructLayout(LayoutKind.Sequential)] + public unsafe struct LZ4F_dctx_s + { + public fixed byte _unused[1]; + } + + [StructLayout(LayoutKind.Sequential)] + public unsafe struct LZ4F_decompressOptions_t + { + public uint stableDst; + public uint skipChecksums; + public uint reserved1; + public uint reserved0; + } + + [StructLayout(LayoutKind.Sequential)] + public unsafe struct XXH32_state_s + { + public fixed byte _unused[1]; + } + + [StructLayout(LayoutKind.Sequential)] + public unsafe struct XXH32_canonical_t + { + public fixed byte digest[4]; + } + + [StructLayout(LayoutKind.Sequential)] + public unsafe struct XXH64_state_s + { + public fixed byte _unused[1]; + } + + [StructLayout(LayoutKind.Sequential)] + public unsafe struct XXH64_canonical_t + { + public fixed byte digest[8]; + } + } \ No newline at end of file diff --git a/dotnet-sandbox/method_call.cs b/dotnet-sandbox/method_call.cs new file mode 100644 index 0000000..bb535a6 --- /dev/null +++ b/dotnet-sandbox/method_call.cs @@ -0,0 +1,22 @@ +// +// This code is generated by csbindgen. +// DON'T CHANGE THIS DIRECTLY. +// +using System; +using System.Runtime.InteropServices; + +namespace CsBindgen +{ + public static unsafe partial class LibRust + { + const string __DllName = "csbindgen_tests"; + + [DllImport(__DllName, EntryPoint = "my_add", CallingConvention = CallingConvention.Cdecl)] + public static extern int my_add(int x, int y); + + + } + + +} + \ No newline at end of file