pub struct Encoder<'a, R> { /* private fields */ }
Expand description

Specify the encoding settings, such as window size, logging, input, and output

To create a new Encoder, use for_reader(), for_file(), or for_bytes(). Then, change any of the encoding settings with Encoder’s helper methods. Finally, encode the input data with encode_to_writer(), encode_to_file(), or encode_to_vec().

let input = b"ABBACABBCADFEGABA";
let compressed = Encoder::for_bytes(input)
    .two_sample()
    .lzss_backend(LzssBackend::Kmp)
    .with_logging(&mut ::std::io::stdout())
    .encode_to_vec();

The default encoding settings are as follows:

  • One Sample encoding
  • No user offset or length values
  • No logging
  • LZSS settings:
    • 16 bit window (65536 bytes)
    • 8 bit lookahead (256 bytes)
    • Minimum match of 3 bytes
    • Brute match searching

Implementations

Create a new Encoder for the data in rdr.

Set the encoded VPK file to use either a one sample offset lookback, or a two sample lookback.

In one sample mode, the offset value is directly encoded into the output. In two sample mode, the offset value is divided by four. Then the remainder (if necessary) and quotient are stored in the output.

Conveince method to set one sample encoding without importing VpkMethod.

Conveince method to set two sample encoding without importing VpkMethod.

Set the settings used for the underyling lzss compression. See LzssSettings for more details.

Set the algorithm used to search for LZSS matches when encoding

Manually set the offset Huffman Tree with a text based representation of a tree. This representation can be extracted from a vpk0 file by vpk_info or Decoder::trees.

let compressed = Encoder::for_bytes(b"sam I am I am sam")
    .with_offsets("(3, (7, 10))")
    .encode_to_vec();

Note that the encoding will fail if there is an offset whose size in bits is larger than the largest provided offset.

Set the offset Huffman Tree if offsets.is_some(), else create the offset tree from the input data.

Manually set the length Huffman Tree with a text based representation of a tree. This representation can be extracted from a vpk0 file by vpk_info or Decoder::trees.

let compressed = Encoder::for_bytes(b"sam I am I am sam")
    .with_lengths("((3, 5), (7, (12, 16))")
    .encode_to_vec();

Note that the encoding will fail if there is an offset whose size in bits is larger than the largest provided offset.

Set the length Huffman Tree if offsets.is_some(), else create the offset tree from the input data.

Write debugging and diagnotic information to log while the input is being encoded.

Start the encoding and write the compressed data out to wtr

Start the encoding and write the compressed data out to the newly created File f

Start the encoding and return the compressed data in a Vec<u8>.

Create a new Encoder for the file at p.

Create a new Encoder for the data the bytes slice.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.