1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
pub use brotli_decompressor::ffi;
pub use brotli_decompressor::{BrotliDecoderReturnInfo, HuffmanCode};
pub use brotli_decompressor::ffi::interface::{
  brotli_alloc_func,
  brotli_free_func,
  c_void,
};

pub unsafe extern fn CBrotliDecoderCreateInstance(
    alloc_func: brotli_alloc_func,
    free_func: brotli_free_func,
    opaque: *mut c_void,
) -> *mut ffi::BrotliDecoderState {
   ffi::BrotliDecoderCreateInstance(alloc_func, free_func, opaque)
}

pub unsafe extern fn CBrotliDecoderSetParameter(state_ptr: *mut ffi::BrotliDecoderState,
                                       selector: ffi::interface::BrotliDecoderParameter,
                                       value: u32) {
    ffi::BrotliDecoderSetParameter(state_ptr,  selector, value)
} 
     
#[cfg(feature="std")] // this requires a default allocator
pub unsafe extern fn CBrotliDecoderDecompress(
  encoded_size: usize,
  encoded_buffer: *const u8,
  decoded_size: *mut usize,
  decoded_buffer: *mut u8) -> ffi::interface::BrotliDecoderResult {
    ffi::BrotliDecoderDecompress(encoded_size, encoded_buffer, decoded_size, decoded_buffer)
}

pub unsafe extern fn CBrotliDecoderDecompressStream(
    state_ptr: *mut ffi::BrotliDecoderState,
    available_in: *mut usize,
    input_buf_ptr: *mut*const u8,
    available_out: *mut usize,
    output_buf_ptr: *mut*mut u8,
    total_out: *mut usize,
) -> ffi::interface::BrotliDecoderResult {
ffi::BrotliDecoderDecompressStream(
  state_ptr,
  available_in,
  input_buf_ptr,
  available_out,
  output_buf_ptr,
  total_out)
}

pub unsafe extern fn CBrotliDecoderDecompressStreaming(
    state_ptr: *mut ffi::BrotliDecoderState,
    available_in: *mut usize,
    input_buf_ptr: *const u8,
    available_out: *mut usize,
    output_buf_ptr: *mut u8,
) -> ffi::interface::BrotliDecoderResult {
ffi::BrotliDecoderDecompressStreaming(
  state_ptr,
  available_in,
  input_buf_ptr,
  available_out,
  output_buf_ptr)
}

pub unsafe extern fn CBrotliDecoderDecompressWithReturnInfo(
    available_in: usize,
    input_buf_ptr: *const u8,
    available_out_and_scratch: usize,
    output_buf_and_scratch: *mut u8,
) -> BrotliDecoderReturnInfo {
ffi::BrotliDecoderDecompressWithReturnInfo(
  available_in,
  input_buf_ptr,
  available_out_and_scratch,
  output_buf_and_scratch)
}

pub unsafe extern fn CBrotliDecoderDecompressPrealloc(
    available_in: usize,
    input_buf_ptr: *const u8,
    available_out: usize,
    output_buf_ptr: *mut u8,
    available_u8: usize,
    u8_ptr: *mut u8,
    available_u32: usize,
    u32_ptr: *mut u32,
    available_hc: usize,
    hc_ptr: *mut HuffmanCode,
) -> BrotliDecoderReturnInfo {
ffi::BrotliDecoderDecompressPrealloc(
  available_in,
  input_buf_ptr,
  available_out,
  output_buf_ptr,
  available_u8,
  u8_ptr,
  available_u32,
  u32_ptr,
  available_hc,
  hc_ptr)
}

pub unsafe extern fn CBrotliDecoderMallocU8(state_ptr: *mut ffi::BrotliDecoderState, size: usize) -> *mut u8 {
  ffi::BrotliDecoderMallocU8(state_ptr, size)
}

pub unsafe extern fn CBrotliDecoderFreeU8(state_ptr: *mut ffi::BrotliDecoderState, data: *mut u8, size: usize) {
  ffi::BrotliDecoderFreeU8(state_ptr, data, size)
}

pub unsafe extern fn CBrotliDecoderMallocUsize(state_ptr: *mut ffi::BrotliDecoderState, size: usize) -> *mut usize {
  ffi::BrotliDecoderMallocUsize(state_ptr, size)
}

pub unsafe extern fn CBrotliDecoderFreeUsize(state_ptr: *mut ffi::BrotliDecoderState, data: *mut usize, size: usize) {
  ffi::BrotliDecoderFreeUsize(state_ptr, data, size)
}

pub unsafe extern fn CBrotliDecoderDestroyInstance(state_ptr: *mut ffi::BrotliDecoderState) {
  ffi::BrotliDecoderDestroyInstance(state_ptr)
}

pub extern fn CBrotliDecoderVersion() -> u32 {
  ffi::BrotliDecoderVersion()
}

#[no_mangle]
pub extern fn CBrotliDecoderErrorString(c: ffi::BrotliDecoderErrorCode) -> *const u8 {
  ffi::BrotliDecoderErrorString(c)
}

#[no_mangle]
pub unsafe extern fn CBrotliDecoderHasMoreOutput(state_ptr: *const ffi::BrotliDecoderState) -> i32 {
  ffi::BrotliDecoderHasMoreOutput(state_ptr)
}

#[no_mangle]
pub unsafe extern fn CBrotliDecoderTakeOutput(state_ptr: *mut ffi::BrotliDecoderState, size: *mut usize) -> *const u8 {
  ffi::BrotliDecoderTakeOutput(state_ptr, size)
}



#[no_mangle]
pub unsafe extern fn CBrotliDecoderIsUsed(state_ptr: *const ffi::BrotliDecoderState) -> i32 {
  ffi::BrotliDecoderIsUsed(state_ptr)
}
#[no_mangle]
pub unsafe extern fn CBrotliDecoderIsFinished(state_ptr: *const ffi::BrotliDecoderState) -> i32 {
  ffi::BrotliDecoderIsFinished(state_ptr)
}
#[no_mangle]
pub unsafe extern fn CBrotliDecoderGetErrorCode(state_ptr: *const ffi::BrotliDecoderState) -> ffi::BrotliDecoderErrorCode {
  ffi::BrotliDecoderGetErrorCode(state_ptr)
}
#[no_mangle]
pub unsafe extern fn CBrotliDecoderGetErrorString(state_ptr: *const ffi::BrotliDecoderState) -> *const u8 {
  ffi::BrotliDecoderGetErrorString(state_ptr)
}