/// Copies the given bytes into Pdfium's WASM memory heap, returning a pointer to the
/// destination location.
///
/// WASM modules are isolated from one another and cannot directly share memory. We must
/// therefore copy buffers from our own memory heap across into Pdfium's memory heap, and vice versa.
Copies the given bytes into Pdfium's WASM memory heap, returning a pointer to the
destination location.

WASM modules are isolated from one another and cannot directly share memory. We must
therefore copy buffers from our own memory heap across into Pdfium's memory heap, and vice versa.
Copies the given bytes into Pdfium ' s WASM memory heap returning a pointer to the destination location . WASM modules are isolated from one another and cannot directly share memory . We must therefore copy buffers from our own memory heap across into Pdfium ' s memory heap and vice versa .
fn copy_bytes_to_pdfium(&self, bytes: &[u8]) -> usize {
        log::debug!("pdfium-render::PdfiumRenderWasmState::copy_bytes_to_pdfium(): entering");
        let remote_ptr = self.malloc(bytes.len());
        log::debug!("pdfium-render::PdfiumRenderWasmState::copy_bytes_to_pdfium(): got pointer offset back from Module._malloc(): {}", remote_ptr);
        self.heap_u8()
            .set(unsafe { &Uint8Array::view(bytes) }, remote_ptr as u32);
        log::debug!("pdfium-render::PdfiumRenderWasmState::copy_bytes_to_pdfium(): copied {} bytes into allocated buffer", bytes.len());
        if self.debug {
            // Compare memory after copying to ensure it is the same.
            let mut differences_count = 0;
            let pdfium_heap = self.heap_u8();
            for (index, byte) in bytes.iter().enumerate() {
                let dest = pdfium_heap.get_index((remote_ptr + index) as u32);
                if *byte != dest {
                    differences_count += 1;
                    log::warn!(
                        "pdfium-render::PdfiumRenderWasmState::copy_bytes_to_pdfium(): byte index {} differs between source and destination: source data = {}, destination data = {}",
                        index,
                        byte,
                        dest,
                    );
                }
            }
            log::debug!("pdfium-render::PdfiumRenderWasmState::copy_bytes_to_pdfium(): {} bytes differ between source and destination byte buffers", differences_count);
        }
        log::debug!("pdfium-render::PdfiumRenderWasmState::copy_bytes_to_pdfium(): leaving");
        remote_ptr
    }
fn copy_bytes_to_pdfium ( & self , bytes : & [ u8 ] ) -> usize { log :: debug ! ( " " ) ; let remote_ptr = self . malloc ( bytes . len ( ) ) ; log :: debug ! ( " " remote_ptr ) ; self . heap_u8 ( ) . set ( unsafe { & Uint8Array :: view ( bytes ) } , remote_ptr as u32 ) ; log :: debug ! ( " " bytes len ( ) ) ; if self . debug { // Compare memory after copying to ensure it is the same. let mut differences_count = 0 ; let pdfium_heap = self . heap_u8 ( ) ; for ( index , byte ) in bytes . iter ( ) . enumerate ( ) { let dest = pdfium_heap . get_index ( ( remote_ptr + index ) as u32 ) ; if * byte != dest { differences_count += 1 ; log :: warn ! ( " " index byte dest ) ; } } log :: debug ! ( " " differences_count ) ; } log :: debug ! ( " " ) ; remote_ptr }
Copies the given bytes into Pdfium's WASM memory heap, returning a pointer to the
destination location.
Copies the given bytes into Pdfium ' s WASM memory heap returning a pointer to the destination location .
&self
bytes
&[u8]