pub fn get_variable_size_field<const N: usize, F>(
field_code: i32,
host_fn: F,
) -> Result<([u8; N], usize)>Expand description
Helper function for retrieving variable-size fields.
This function encapsulates the common pattern for variable-size fields where:
- A buffer of maximum size is allocated
- A host function is called to retrieve the field
- The actual number of bytes written is returned (not validated for exact match)
- Both the buffer and the actual length are returned
This is used for fields like Amount and Blob where the actual size can vary.
§Type Parameters
N- The maximum size of the buffer (compile-time constant)F- The type of the host function closure
§Arguments
field_code- The field code identifying which field to retrievehost_fn- A closure that calls the appropriate host function- Takes: (field_code: i32, buffer_ptr: *mut u8, buffer_size: usize) -> i32
- Returns: result code (number of bytes written or error code)
§Returns
Returns Result<([u8; N], usize)> containing the buffer and actual length if successful
§Example
ⓘ
let (buffer, len) = get_variable_size_field::<48>(
field_code,
|fc, buf, size| unsafe { get_current_ledger_obj_field(fc, buf, size) },
)?;