Debian Codegraph @

src/lz4_hc/stream/api.rs

raw symbols SCIP
1 #![allow(unsafe_code)]
2
3 use superrust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/::superrust-analyzer cargo lzzzz 2.0.0 lz4_hc/::{bindingrust-analyzer cargo lzzzz 2.0.0 lz4_hc/binding/, bindingrust-analyzer cargo lzzzz 2.0.0 lz4_hc/binding/::LZ4StreamHCrust-analyzer cargo lzzzz 2.0.0 lz4_hc/binding/LZ4StreamHC#};
4 use craterust-analyzer cargo lzzzz 2.0.0 crate/::{Errorrust-analyzer cargo lzzzz 2.0.0 common/error/Error#, ErrorKindrust-analyzer cargo lzzzz 2.0.0 common/error/ErrorKind#, Resultrust-analyzer cargo lzzzz 2.0.0 common/error/Result#};
5
6 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{
7 osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/::{c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#, c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#},
8 ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::NonNullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/non_null/NonNull#,
9 ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::null_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/null_mut().
10 };
11
12 pub struct CompressionContextrust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/api/CompressionContext# {
13 streamrust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/api/CompressionContext#stream.: NonNullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/non_null/NonNull#<LZ4StreamHCrust-analyzer cargo lzzzz 2.0.0 lz4_hc/binding/LZ4StreamHC#>,
14 }
15
16 unsafe impl Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# for CompressionContextrust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/api/CompressionContext# {}
17
18 impl CompressionContextrust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/api/CompressionContext# {
19 pub fn newrust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/api/impl#[CompressionContext]new().() -> Resultrust-analyzer cargo lzzzz 2.0.0 common/error/Result#<Selfrust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/api/impl#[CompressionContext]> {
20 let ptr = unsafe { NonNullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/non_null/NonNull#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/non_null/impl#[`NonNull<T>`]new().(bindingrust-analyzer cargo lzzzz 2.0.0 lz4_hc/binding/::LZ4_createStreamHCrust-analyzer cargo lzzzz 2.0.0 LZ4_createStreamHC().()) };
21 ptr.ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| Errorrust-analyzer cargo lzzzz 2.0.0 common/error/Error#::newrust-analyzer cargo lzzzz 2.0.0 common/error/impl#[Error]new().(ErrorKindrust-analyzer cargo lzzzz 2.0.0 common/error/ErrorKind#::InitializationFailedrust-analyzer cargo lzzzz 2.0.0 common/error/ErrorKind#InitializationFailed#))
22 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|stream| Selfrust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/api/impl#[CompressionContext] { streamrust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/api/CompressionContext#stream. })
23 }
24
25 pub fn set_compression_levelrust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/api/impl#[CompressionContext]set_compression_level().(&mut self, compression_level: i32) {
26 unsafe {
27 bindingrust-analyzer cargo lzzzz 2.0.0 lz4_hc/binding/::LZ4_setCompressionLevelrust-analyzer cargo lzzzz 2.0.0 LZ4_setCompressionLevel().(self.streamrust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/api/CompressionContext#stream..as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/non_null/impl#[`NonNull<T>`]as_ptr().(), compression_level as c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#)
28 }
29 }
30
31 pub fn set_favor_dec_speedrust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/api/impl#[CompressionContext]set_favor_dec_speed().(&mut self, flag: bool) {
32 unsafe { bindingrust-analyzer cargo lzzzz 2.0.0 lz4_hc/binding/::LZ4_favorDecompressionSpeedrust-analyzer cargo lzzzz 2.0.0 LZ4_favorDecompressionSpeed().(self.streamrust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/api/CompressionContext#stream..as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/non_null/impl#[`NonNull<T>`]as_ptr().(), i32::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[i32][`From<bool>`]from().(flag)) }
33 }
34
35 pub fn load_dictrust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/api/impl#[CompressionContext]load_dict().(&mut self, dict: &[u8]) {
36 unsafe {
37 bindingrust-analyzer cargo lzzzz 2.0.0 lz4_hc/binding/::LZ4_loadDictHCrust-analyzer cargo lzzzz 2.0.0 LZ4_loadDictHC().(
38 self.streamrust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/api/CompressionContext#stream..as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/non_null/impl#[`NonNull<T>`]as_ptr().(),
39 dict.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_ptr().() as *const c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#,
40 dict.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#,
41 );
42 }
43 }
44
45 pub fn save_dictrust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/api/impl#[CompressionContext]save_dict().(&mut self, dict: &mut [u8]) {
46 unsafe {
47 bindingrust-analyzer cargo lzzzz 2.0.0 lz4_hc/binding/::LZ4_saveDictHCrust-analyzer cargo lzzzz 2.0.0 LZ4_saveDictHC().(
48 self.streamrust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/api/CompressionContext#stream..as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/non_null/impl#[`NonNull<T>`]as_ptr().(),
49 dict.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_ptr().() as *mut c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#,
50 dict.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#,
51 );
52 }
53 }
54
55 pub fn nextrust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/api/impl#[CompressionContext]next().(&mut self, src: &[u8], dst: *mut u8, dst_len: usize) -> Resultrust-analyzer cargo lzzzz 2.0.0 common/error/Result#<usize> {
56 if src.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() {
57 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(0);
58 }
59 let dst_len = unsafe {
60 bindingrust-analyzer cargo lzzzz 2.0.0 lz4_hc/binding/::LZ4_compress_HC_continuerust-analyzer cargo lzzzz 2.0.0 LZ4_compress_HC_continue().(
61 self.streamrust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/api/CompressionContext#stream..as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/non_null/impl#[`NonNull<T>`]as_ptr().(),
62 src.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_ptr().() as *const c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#,
63 dst as *mut c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#,
64 src.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#,
65 dst_len as c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#,
66 ) as usize
67 };
68 if dst_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 {
69 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(dst_len)
70 } else {
71 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo lzzzz 2.0.0 common/error/Error#::newrust-analyzer cargo lzzzz 2.0.0 common/error/impl#[Error]new().(ErrorKindrust-analyzer cargo lzzzz 2.0.0 common/error/ErrorKind#::CompressionFailedrust-analyzer cargo lzzzz 2.0.0 common/error/ErrorKind#CompressionFailed#))
72 }
73 }
74
75 pub fn next_partialrust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/api/impl#[CompressionContext]next_partial().(&mut self, src: &[u8], dst: &mut [u8]) -> Resultrust-analyzer cargo lzzzz 2.0.0 common/error/Result#<(usize, usize)> {
76 if src.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() || dst.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() {
77 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((0, 0));
78 }
79 let mut src_len = src.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#;
80 let dst_len = unsafe {
81 bindingrust-analyzer cargo lzzzz 2.0.0 lz4_hc/binding/::LZ4_compress_HC_continue_destSizerust-analyzer cargo lzzzz 2.0.0 LZ4_compress_HC_continue_destSize().(
82 self.streamrust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/api/CompressionContext#stream..as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/non_null/impl#[`NonNull<T>`]as_ptr().(),
83 src.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_ptr().() as *const c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#,
84 dst.as_mut_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_mut_ptr().() as *mut c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#,
85 &mut src_len as *mut c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#,
86 dst.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#,
87 ) as usize
88 };
89 if dst_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 {
90 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((src_len as usize, dst_len))
91 } else {
92 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo lzzzz 2.0.0 common/error/Error#::newrust-analyzer cargo lzzzz 2.0.0 common/error/impl#[Error]new().(ErrorKindrust-analyzer cargo lzzzz 2.0.0 common/error/ErrorKind#::CompressionFailedrust-analyzer cargo lzzzz 2.0.0 common/error/ErrorKind#CompressionFailed#))
93 }
94 }
95
96 pub fn attach_dictrust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/api/impl#[CompressionContext]attach_dict().(&mut self, dict_stream: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&CompressionContextrust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/api/CompressionContext#>, compression_level: i32) {
97 unsafe {
98 if dict_stream.is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
99 // Note(sewer56): When detaching dictionary, we need to reset the stream state
100 // This behaviour is consistent with what the LZ4 library itself does internally.
101 // The LZ4HC API does not have a way to retrieve compression level, so we must pass it manually,
102 // since the HC API differs here.
103 bindingrust-analyzer cargo lzzzz 2.0.0 lz4_hc/binding/::LZ4_resetStreamHC_fastrust-analyzer cargo lzzzz 2.0.0 LZ4_resetStreamHC_fast().(self.streamrust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/api/CompressionContext#stream..as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/non_null/impl#[`NonNull<T>`]as_ptr().(), compression_level);
104 }
105 let dict_ptr = dict_stream.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|ctx| ctx.streamrust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/api/CompressionContext#stream..as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/non_null/impl#[`NonNull<T>`]as_ptr().()).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(null_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/null_mut().());
106 bindingrust-analyzer cargo lzzzz 2.0.0 lz4_hc/binding/::LZ4_attach_HC_dictionaryrust-analyzer cargo lzzzz 2.0.0 LZ4_attach_HC_dictionary().(self.streamrust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/api/CompressionContext#stream..as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/non_null/impl#[`NonNull<T>`]as_ptr().(), dict_ptr);
107 }
108 }
109 }
110
111 impl Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for CompressionContextrust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/api/CompressionContext# {
112 fn droprust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/api/impl#[CompressionContext][Drop]drop().(&mut self) {
113 unsafe {
114 bindingrust-analyzer cargo lzzzz 2.0.0 lz4_hc/binding/::LZ4_freeStreamHCrust-analyzer cargo lzzzz 2.0.0 LZ4_freeStreamHC().(self.streamrust-analyzer cargo lzzzz 2.0.0 lz4_hc/stream/api/CompressionContext#stream..as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/non_null/impl#[`NonNull<T>`]as_mut().());
115 }
116 }
117 }