diff --git a/framework/base/Cargo.toml b/framework/base/Cargo.toml index 9edc7414d7..961a0c59d5 100644 --- a/framework/base/Cargo.toml +++ b/framework/base/Cargo.toml @@ -19,6 +19,7 @@ all-features = true [features] num-bigint = ["multiversx-sc-codec/num-bigint"] alloc = ["multiversx-sc-codec/alloc"] +managed-buffer-builder-cached = [] esdt-token-payment-legacy-decode = [] [dependencies] diff --git a/framework/base/src/types/managed/wrapped/builder.rs b/framework/base/src/types/managed/wrapped/builder.rs index 89bc92feb2..78f81f6e81 100644 --- a/framework/base/src/types/managed/wrapped/builder.rs +++ b/framework/base/src/types/managed/wrapped/builder.rs @@ -1,11 +1,18 @@ mod managed_buffer_builder; mod managed_buffer_builder_impl; +mod managed_buffer_builder_impl_basic; mod managed_buffer_builder_impl_cached; pub use managed_buffer_builder::ManagedBufferBuilder; pub use managed_buffer_builder_impl::ManagedBufferBuilderImpl; +pub use managed_buffer_builder_impl_basic::ManagedBufferBuilderImplBasic; pub use managed_buffer_builder_impl_cached::ManagedBufferBuilderImplCached; +#[deprecated(since = "0.48.0", note = "Renamed to ManagedBufferBuilder.")] pub type ManagedBufferCachedBuilder = ManagedBufferBuilder; +#[cfg(feature = "managed-buffer-builder-cached")] pub type ManagedBufferImplDefault = ManagedBufferBuilderImplCached; + +#[cfg(not(feature = "managed-buffer-builder-cached"))] +pub type ManagedBufferImplDefault = ManagedBufferBuilderImplBasic; diff --git a/framework/base/src/types/managed/wrapped/builder/managed_buffer_builder_impl_basic.rs b/framework/base/src/types/managed/wrapped/builder/managed_buffer_builder_impl_basic.rs new file mode 100644 index 0000000000..3c1e87c7fb --- /dev/null +++ b/framework/base/src/types/managed/wrapped/builder/managed_buffer_builder_impl_basic.rs @@ -0,0 +1,40 @@ +use crate::{api::ManagedTypeApi, types::ManagedBuffer}; + +use super::ManagedBufferBuilderImpl; + +/// Basic implementation of a ManagedBuffer builder, no caching. +/// +/// It is the ManagedBuffer itself, we just append to it each time. +pub struct ManagedBufferBuilderImplBasic +where + M: ManagedTypeApi, +{ + managed_buffer: ManagedBuffer, +} + +impl ManagedBufferBuilderImpl for ManagedBufferBuilderImplBasic +where + M: ManagedTypeApi, +{ + #[inline] + fn new_from_slice(slice: &[u8]) -> Self { + ManagedBufferBuilderImplBasic { + managed_buffer: slice.into(), + } + } + + #[inline] + fn into_managed_buffer(self) -> ManagedBuffer { + self.managed_buffer + } + + #[inline] + fn append_bytes(&mut self, bytes: &[u8]) { + self.managed_buffer.append_bytes(bytes); + } + + #[inline] + fn append_managed_buffer(&mut self, item: &ManagedBuffer) { + self.managed_buffer.append(item); + } +} diff --git a/framework/base/src/types/managed/wrapped/builder/managed_buffer_builder_impl_cached.rs b/framework/base/src/types/managed/wrapped/builder/managed_buffer_builder_impl_cached.rs index c7977d056d..ead06e151c 100644 --- a/framework/base/src/types/managed/wrapped/builder/managed_buffer_builder_impl_cached.rs +++ b/framework/base/src/types/managed/wrapped/builder/managed_buffer_builder_impl_cached.rs @@ -5,6 +5,7 @@ use crate::{ use super::ManagedBufferBuilderImpl; +/// A ManagedBuffer builder implementation that caches data to the static cache locally in the contract. pub struct ManagedBufferBuilderImplCached where M: ManagedTypeApi,