How to top encode without allocating

84 Views Asked by At

I am trying to read the content of the input from a TopDecode, but erdpy contract report reports has-allocator equals true. Below is my current snippet.

impl<M: ManagedTypeApi> TopDecode for PenguinAttributes<M> {
    fn top_decode<I: elrond_codec::TopDecodeInput>(input: I) -> Result<Self, DecodeError> {
        let boxed_bytes = input.into_boxed_slice_u8();

        return Result::Ok(PenguinAttributes::empty());
    }
}

I have commented the boxed_bytes method, and has-allocator now equals false.
But how can I read the content of input withouting using allocator please ?

I am using elrond-wasm 0.29.3 and erdpy 1.2.3.

Thank you

An example of my input Hat:unequipped;Beak:Golden Beak (BEAK-a1a1a1-05).

1

There are 1 best solutions below

0
On

I achieve this by loading my bytes in an array of 512. Then, I read the array from 0 to managed_buffer.length.

impl<M: ManagedTypeApi> TopDecode for PenguinAttributes<M> {
    fn top_decode<I: elrond_codec::TopDecodeInput>(input: I) -> Result<Self, DecodeError> {
        let mut bytes: [u8; 512] = [0; 512];
        managed_buffer.load_to_byte_array(&mut bytes);

        return Result::Ok(PenguinAttributes::empty());
    }
}