1 //! C API for the Chunker.
3 use std
::os
::raw
::c_void
;
9 /// Creates a new chunker instance.
11 pub extern "C" fn proxmox_chunker_new(chunk_size_avg
: size_t
) -> *mut Chunker
{
12 Box
::leak(Box
::new(Chunker
::new(chunk_size_avg
as usize)))
15 /// Drops an instance of a chunker. The pointer must be valid or `NULL`.
17 pub extern "C" fn proxmox_chunker_done(me
: *mut Chunker
) {
25 /// Scan the specified data for a chunk border. Returns 0 if none was found, or a positive offset
28 pub extern "C" fn proxmox_chunker_scan(
33 let me
= unsafe { &mut *me }
;
34 me
.scan(unsafe { std::slice::from_raw_parts(data as *const u8, size as usize) }
) as size_t
37 /// Compute a chunk digest. This is mostly a convenience method to avoid having to lookup the right
38 /// digest method for your language of choice.
40 pub extern "C" fn proxmox_chunk_digest(
43 out_digest
: *mut [u8; 32],
45 let digest
= crate::FixedChunk
::from_data(unsafe {
46 std
::slice
::from_raw_parts(data
as *const u8, size
as usize)
48 unsafe { *out_digest = digest.0 }
;