pub fn write_packed<Store, Heap>(
    db: &Database<Store, Heap>,
    out: &mut dyn io::Write,
    ) -> io::Result<()>
where
    Store: store::Store,
    Heap: heap::SizedHeap,
{
    // Byte [0..12): The signature magic bytes.
    out.write_all(&SIGNATURE[..])?;
    // Byte [12..14): The 16-bit format version.
    out.write_all(&u16_to_le_bytes(1))?;
    // Byte [14..16): The 8-bit format type. 0 indicates the packed format.
    // Then an unused padding byte.
    out.write_all(&[0, 0])?;

    let head = db.get_head();

    // Byte [16..56): The 40-byte head.
    out.write_all(&head.to_bytes()[..])?;

    let max_page = head.max_page();
    let num_pages = 1 + max_page.0;
    let page_size_in_bytes = <Store::Size as store::PageSize>::SIZE as u64;
    let store_len_in_bytes = num_pages * page_size_in_bytes;
    let heap_len_in_bytes = db.get_heap().len();

    // Byte [56..64): The page size, in bytes.
    out.write_all(&u64_to_le_bytes(page_size_in_bytes))?;
    // Byte [64..72): The size of the store, in bytes.
    out.write_all(&u64_to_le_bytes(store_len_in_bytes))?;
    // Byte [72..80): The size of the heap, in bytes.
    out.write_all(&u64_to_le_bytes(heap_len_in_bytes))?;

    // Pad with zeros until we are aligned to the page size. We should be able
    // to use a fixed-size slice here instead of a vec, but unfortunately that
    // results in a compile error about an associated type not being found.
    out.write_all(&vec![0; <Store::Size as store::PageSize>::SIZE - 80])?;

    db.get_store().dump(out)?;
    db.get_heap().dump(out)?;

    Ok(())
}
/// Write the database as a single stream, in packed format.
///
/// The packed format has the advantage that the entire database is a single
/// file, which makes it easy to share and relocate. The downside of the packed
/// format is that it is read-only. A packed database cannot record new
/// transactions after it has been written.
///
/// The packed format consists of a header, followed by the store file and heap
/// file concatenated.
Write the database as a single stream, in packed format.
The packed format has the advantage that the entire database is a single
file, which makes it easy to share and relocate. The downside of the packed
format is that it is read-only. A packed database cannot record new
transactions after it has been written.

The packed format consists of a header, followed by the store file and heap
file concatenated.
Write the database as a single stream in packed format . The packed format has the advantage that the entire database is a single file which makes it easy to share and relocate . The downside of the packed format is that it is read - only . A packed database cannot record new transactions after it has been written . The packed format consists of a header followed by the store file and heap file concatenated .
pub fn write_packed<Store, Heap>(
    db: &Database<Store, Heap>,
    out: &mut dyn io::Write,
    ) -> io::Result<()>
where
    Store: store::Store,
    Heap: heap::SizedHeap,
{
    // Byte [0..12): The signature magic bytes.
    out.write_all(&SIGNATURE[..])?;
    // Byte [12..14): The 16-bit format version.
    out.write_all(&u16_to_le_bytes(1))?;
    // Byte [14..16): The 8-bit format type. 0 indicates the packed format.
    // Then an unused padding byte.
    out.write_all(&[0, 0])?;
    let head = db.get_head();
    // Byte [16..56): The 40-byte head.
    out.write_all(&head.to_bytes()[..])?;
    let max_page = head.max_page();
    let num_pages = 1 + max_page.0;
    let page_size_in_bytes = <Store::Size as store::PageSize>::SIZE as u64;
    let store_len_in_bytes = num_pages * page_size_in_bytes;
    let heap_len_in_bytes = db.get_heap().len();
    // Byte [56..64): The page size, in bytes.
    out.write_all(&u64_to_le_bytes(page_size_in_bytes))?;
    // Byte [64..72): The size of the store, in bytes.
    out.write_all(&u64_to_le_bytes(store_len_in_bytes))?;
    // Byte [72..80): The size of the heap, in bytes.
    out.write_all(&u64_to_le_bytes(heap_len_in_bytes))?;
    // Pad with zeros until we are aligned to the page size. We should be able
    // to use a fixed-size slice here instead of a vec, but unfortunately that
    // results in a compile error about an associated type not being found.
    out.write_all(&vec![0; <Store::Size as store::PageSize>::SIZE - 80])?;
    db.get_store().dump(out)?;
    db.get_heap().dump(out)?;
    Ok(())
}
pub fn write_packed < Store , Heap > ( db : & Database < Store , Heap > , out : & mut dyn io :: Write , ) -> io :: Result < ( ) > where Store : store :: Store , Heap : heap :: SizedHeap , { // Byte [0..12): The signature magic bytes. out . write_all ( & SIGNATURE [ .. ] ) ? ; // Byte [12..14): The 16-bit format version. out . write_all ( & u16_to_le_bytes ( 1 ) ) ? ; // Byte [14..16): The 8-bit format type. 0 indicates the packed format. // Then an unused padding byte. out . write_all ( & [ 0 , 0 ] ) ? ; let head = db . get_head ( ) ; // Byte [16..56): The 40-byte head. out . write_all ( & head . to_bytes ( ) [ .. ] ) ? ; let max_page = head . max_page ( ) ; let num_pages = 1 + max_page . 0 ; let page_size_in_bytes = < Store :: Size as store :: PageSize > :: SIZE as u64 ; let store_len_in_bytes = num_pages * page_size_in_bytes ; let heap_len_in_bytes = db . get_heap ( ) . len ( ) ; // Byte [56..64): The page size, in bytes. out . write_all ( & u64_to_le_bytes ( page_size_in_bytes ) ) ? ; // Byte [64..72): The size of the store, in bytes. out . write_all ( & u64_to_le_bytes ( store_len_in_bytes ) ) ? ; // Byte [72..80): The size of the heap, in bytes. out . write_all ( & u64_to_le_bytes ( heap_len_in_bytes ) ) ? ; // Pad with zeros until we are aligned to the page size. We should be able // to use a fixed-size slice here instead of a vec, but unfortunately that // results in a compile error about an associated type not being found. out . write_all ( & vec ! [ 0 Store Size as store PageSize SIZE 80 ] ) ? ; db . get_store ( ) . dump ( out ) ? ; db . get_heap ( ) . dump ( out ) ? ; Ok ( ( ) ) }
Write the database as a single stream, in packed format.
Write the database as a single stream in packed format .
db
&Database<Store, Heap>
out
&mut dyn io::Write
db
&Database<Store, Heap>
out
&mut dyn io::Write