fn encode<T: AbiEncoding>(types: Vec<T>) -> yul::Statement {
    // the name of the function we're generating
    let func_name = names::encode_name(&types);

    // create a vector of identifiers and a vector of tuples, which contain
    // expressions that correspond to the identifiers.
    //
    // The identifier vector is injected into the parameter section of our
    // encoding function and the expressions are used to reference the parameters
    // while encoding.
    let (params, typed_params): (Vec<_>, Vec<_>) = types
        .iter()
        .enumerate()
        .map(|(i, typ)| {
            let ident = identifier! { (format!("val_{}", i)) };
            let expr = identifier_expression! { [ident.clone()] };
            (ident, (expr, typ))
        })
        .unzip();

    // get the size of the static section
    let (_, static_size) = utils::abi_head_offsets(&types);
    let static_size = literal_expression! { (static_size) };

    // we need to keep track of the dynamic section size to properly encode
    // dynamically-sized array headers.
    let mut dyn_sizes = vec![];
    // we also keep a separate vector of dynamically-sized arrays, which we
    // encode after finishing the static section.
    let mut dyn_array_params = vec![];

    // map the typed params to encoding statements for headers and statically-sized
    // values
    let static_encode_stmts = typed_params
        .into_iter()
        .map(|(param, typ)| match typ.abi_type() {
            AbiType::Array {
                inner,
                size: AbiArraySize::Static { size },
            } => encode_static_array(param, *inner, size),
            AbiType::Array {
                inner,
                size: AbiArraySize::Dynamic,
            } => {
                let dyn_offset =
                    expression! { add([static_size.clone()], [data_operations::sum(dyn_sizes.clone())]) };
                let inner = *inner;
                dyn_sizes.push(dyn_array_data_size(param.clone(), inner.clone()));
                dyn_array_params.push((param, inner));
                encode_uint(dyn_offset)
            }
            AbiType::Tuple { elems } => encode_tuple(param, elems),
            AbiType::Uint { .. } => encode_uint(param),
        })
        .collect::<Vec<_>>();

    // map the dynamically-sized arrays to encoding statemnts
    let dyn_encode_stmts = dyn_array_params
        .into_iter()
        .map(|(param, inner)| encode_dyn_array(param, inner))
        .collect::<Vec<_>>();

    function_definition! {
        function [func_name]([params...]) -> ptr {
            (ptr := avail())
            [static_encode_stmts...]
            [dyn_encode_stmts...]
        }
    }
}
/// Generates an encoding function for any set of type parameters.
Generates an encoding function for any set of type parameters.
Generates an encoding function for any set of type parameters .
fn encode<T: AbiEncoding>(types: Vec<T>) -> yul::Statement {
    // the name of the function we're generating
    let func_name = names::encode_name(&types);
    // create a vector of identifiers and a vector of tuples, which contain
    // expressions that correspond to the identifiers.
    //
    // The identifier vector is injected into the parameter section of our
    // encoding function and the expressions are used to reference the parameters
    // while encoding.
    let (params, typed_params): (Vec<_>, Vec<_>) = types
        .iter()
        .enumerate()
        .map(|(i, typ)| {
            let ident = identifier! { (format!("val_{}", i)) };
            let expr = identifier_expression! { [ident.clone()] };
            (ident, (expr, typ))
        })
        .unzip();
    // get the size of the static section
    let (_, static_size) = utils::abi_head_offsets(&types);
    let static_size = literal_expression! { (static_size) };
    // we need to keep track of the dynamic section size to properly encode
    // dynamically-sized array headers.
    let mut dyn_sizes = vec![];
    // we also keep a separate vector of dynamically-sized arrays, which we
    // encode after finishing the static section.
    let mut dyn_array_params = vec![];
    // map the typed params to encoding statements for headers and statically-sized
    // values
    let static_encode_stmts = typed_params
        .into_iter()
        .map(|(param, typ)| match typ.abi_type() {
            AbiType::Array {
                inner,
                size: AbiArraySize::Static { size },
            } => encode_static_array(param, *inner, size),
            AbiType::Array {
                inner,
                size: AbiArraySize::Dynamic,
            } => {
                let dyn_offset =
                    expression! { add([static_size.clone()], [data_operations::sum(dyn_sizes.clone())]) };
                let inner = *inner;
                dyn_sizes.push(dyn_array_data_size(param.clone(), inner.clone()));
                dyn_array_params.push((param, inner));
                encode_uint(dyn_offset)
            }
            AbiType::Tuple { elems } => encode_tuple(param, elems),
            AbiType::Uint { .. } => encode_uint(param),
        })
        .collect::<Vec<_>>();
    // map the dynamically-sized arrays to encoding statemnts
    let dyn_encode_stmts = dyn_array_params
        .into_iter()
        .map(|(param, inner)| encode_dyn_array(param, inner))
        .collect::<Vec<_>>();
    function_definition! {
        function [func_name]([params...]) -> ptr {
            (ptr := avail())
            [static_encode_stmts...]
            [dyn_encode_stmts...]
        }
    }
}
fn encode < T : AbiEncoding > ( types : Vec < T > ) -> yul :: Statement { // the name of the function we're generating let func_name = names :: encode_name ( & types ) ; // create a vector of identifiers and a vector of tuples, which contain // expressions that correspond to the identifiers. // // The identifier vector is injected into the parameter section of our // encoding function and the expressions are used to reference the parameters // while encoding. let ( params , typed_params ) : ( Vec < _ > , Vec < _ > ) = types . iter ( ) . enumerate ( ) . map ( | ( i , typ ) | { let ident = identifier ! { ( format ( " " i ) ) } ; let expr = identifier_expression ! { [ ident clone ( ) ] } ; ( ident , ( expr , typ ) ) } ) . unzip ( ) ; // get the size of the static section let ( _ , static_size ) = utils :: abi_head_offsets ( & types ) ; let static_size = literal_expression ! { ( static_size ) } ; // we need to keep track of the dynamic section size to properly encode // dynamically-sized array headers. let mut dyn_sizes = vec ! [ ] ; // we also keep a separate vector of dynamically-sized arrays, which we // encode after finishing the static section. let mut dyn_array_params = vec ! [ ] ; // map the typed params to encoding statements for headers and statically-sized // values let static_encode_stmts = typed_params . into_iter ( ) . map ( | ( param , typ ) | match typ . abi_type ( ) { AbiType :: Array { inner , size : AbiArraySize :: Static { size } , } => encode_static_array ( param , * inner , size ) , AbiType :: Array { inner , size : AbiArraySize :: Dynamic , } => { let dyn_offset = expression ! { add ( [ static_size clone ( ) ] [ data_operations sum ( dyn_sizes clone ( ) ) ] ) } ; let inner = * inner ; dyn_sizes . push ( dyn_array_data_size ( param . clone ( ) , inner . clone ( ) ) ) ; dyn_array_params . push ( ( param , inner ) ) ; encode_uint ( dyn_offset ) } AbiType :: Tuple { elems } => encode_tuple ( param , elems ) , AbiType :: Uint { .. } => encode_uint ( param ) , } ) . collect :: < Vec < _ > > ( ) ; // map the dynamically-sized arrays to encoding statemnts let dyn_encode_stmts = dyn_array_params . into_iter ( ) . map ( | ( param , inner ) | encode_dyn_array ( param , inner ) ) . collect :: < Vec < _ > > ( ) ; function_definition ! { function [ func_name ] ( [ params ] ) ptr { ( ptr avail ( ) ) [ static_encode_stmts ] [ dyn_encode_stmts ] } } }
Generates an encoding function for any set of type parameters.
Generates an encoding function for any set of type parameters .
types
Vec<T>
types
Vec<T>