Skip to main content

encode_table

Function encode_table 

Source
pub fn encode_table<W: WriteBytes>(
    entries: &[Vec<DecodedData>],
    data: &mut W,
    definition: &Definition,
    patches: &Option<&DefinitionPatch>,
) -> Result<()>
Expand description

Encodes table data from decoded format back to binary.

Converts structured DecodedData rows back into binary format according to the table definition. Handles special cases like bitwise fields, enum conversions, and split colour fields.

§Arguments

  • entries - Table rows to encode, each row is a vector of DecodedData.
  • data - Output buffer implementing WriteBytes.
  • definition - Schema definition describing the table structure.
  • patches - Optional definition patches to apply.

§Special Handling

  • Split colours: Extracts r/g/b values from merged ColourRGB fields.
  • Bitwise fields: Combines consecutive boolean values into a single integer.
  • Enum fields: Converts string values back to their integer keys.
  • Strings: Unescapes special characters before writing.

§Errors

Returns an error if:

  • Row has wrong number of fields.
  • Field type doesn’t match expected type for the column.