Skip to content

Compensate array_order_serde calculation based on number of levels of array selectionn in the subroute #752

@andrewdavidmackenzie

Description

@andrewdavidmackenzie

connector.rs

                    // What type of array serialization / deserialization will we need between these two data types
                    // at runtime TODO - take into account the subroute on the output
                    // calculate how many levels of array nesting it removes via number of '/' / levels?
                    // let array_level_serde = connection.from_io.datatype().array_order()? - connection.to_io.datatype().array_order()?;
                    let array_level_serde = connection.to_io.datatype().array_order()?;

Turns out this is done at runtime:

fn type_convert_and_send(function: &mut Function, destination: &OutputConnection, value: &Value) {
        if destination.is_generic() {
            function.send(destination.io_number, value);
        } else {
            match Self::array_order(value) - destination.array_level_serde {
                0 => function.send(destination.io_number, value),
                1 => function.send_iter(destination.io_number, value),
                2 => for array in value.as_array().unwrap().iter() {
                    function.send_iter(destination.io_number, array)
                },
                -1 => function.send(destination.io_number, &json!([value])),
                -2 => function.send(destination.io_number, &json!([[value]])),
                _ => error!("Unable to handle difference in array order")
            }
        }
    }

this could all be pre-calculated at compile time and avoid the need for

Self::array_order(value)

in run_state.rs - UNLESS it depends on what is output (i..e can vary at runtime?)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions