Struct dharitri_wasm::types::ManagedBuffer
source · pub struct ManagedBuffer<M: ManagedTypeApi> { /* private fields */ }Expand description
A byte buffer managed by an external API.
Implementations§
source§impl<M: ManagedTypeApi> ManagedBuffer<M>
impl<M: ManagedTypeApi> ManagedBuffer<M>
pub fn new(api: M) -> Self
pub fn new_from_bytes(api: M, bytes: &[u8]) -> Self
source§impl<M: ManagedTypeApi> ManagedBuffer<M>
impl<M: ManagedTypeApi> ManagedBuffer<M>
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn to_boxed_bytes(&self) -> BoxedBytes
sourcepub fn load_slice(
&self,
starting_position: usize,
dest_slice: &mut [u8]
) -> Result<(), InvalidSliceError>
pub fn load_slice( &self, starting_position: usize, dest_slice: &mut [u8] ) -> Result<(), InvalidSliceError>
TODO: investigate the impact of using Result<(), ()> on the wasm output.
pub fn copy_slice( &self, starting_position: usize, slice_len: usize ) -> Option<ManagedBuffer<M>>
pub fn overwrite(&mut self, value: &[u8])
pub fn append(&mut self, other: &ManagedBuffer<M>)
pub fn append_bytes(&mut self, slice: &[u8])
sourcepub fn append_u32_be(&mut self, item: u32)
pub fn append_u32_be(&mut self, item: u32)
Utility function: helps serialize lengths (or any other value of type usize) easier.
pub fn parse_as_u64(&self) -> Option<u64>
Trait Implementations§
source§impl<M: ManagedTypeApi> Clone for ManagedBuffer<M>
impl<M: ManagedTypeApi> Clone for ManagedBuffer<M>
source§impl<M: Debug + ManagedTypeApi> Debug for ManagedBuffer<M>
impl<M: Debug + ManagedTypeApi> Debug for ManagedBuffer<M>
source§impl<M: ManagedTypeApi> From<&ManagedBuffer<M>> for BigInt<M>
impl<M: ManagedTypeApi> From<&ManagedBuffer<M>> for BigInt<M>
source§fn from(item: &ManagedBuffer<M>) -> Self
fn from(item: &ManagedBuffer<M>) -> Self
Converts to this type from the input type.
source§impl<M: ManagedTypeApi> From<&ManagedBuffer<M>> for BigUint<M>
impl<M: ManagedTypeApi> From<&ManagedBuffer<M>> for BigUint<M>
source§fn from(item: &ManagedBuffer<M>) -> Self
fn from(item: &ManagedBuffer<M>) -> Self
Converts to this type from the input type.
source§impl<M: ManagedTypeApi> From<ManagedBuffer<M>> for BigInt<M>
impl<M: ManagedTypeApi> From<ManagedBuffer<M>> for BigInt<M>
source§fn from(item: ManagedBuffer<M>) -> Self
fn from(item: ManagedBuffer<M>) -> Self
Converts to this type from the input type.
source§impl<M: ManagedTypeApi> From<ManagedBuffer<M>> for BigUint<M>
impl<M: ManagedTypeApi> From<ManagedBuffer<M>> for BigUint<M>
source§fn from(item: ManagedBuffer<M>) -> Self
fn from(item: ManagedBuffer<M>) -> Self
Converts to this type from the input type.
source§impl<M> From<ManagedBuffer<M>> for ManagedSCError<M>where
M: ManagedTypeApi,
impl<M> From<ManagedBuffer<M>> for ManagedSCError<M>where
M: ManagedTypeApi,
source§fn from(message: ManagedBuffer<M>) -> Self
fn from(message: ManagedBuffer<M>) -> Self
Converts to this type from the input type.
source§impl<M: ManagedTypeApi> From<ManagedBuffer<M>> for StorageKey<M>
impl<M: ManagedTypeApi> From<ManagedBuffer<M>> for StorageKey<M>
source§fn from(buffer: ManagedBuffer<M>) -> Self
fn from(buffer: ManagedBuffer<M>) -> Self
Converts to this type from the input type.
source§impl<M: ManagedTypeApi> From<ManagedBuffer<M>> for TokenIdentifier<M>
impl<M: ManagedTypeApi> From<ManagedBuffer<M>> for TokenIdentifier<M>
source§fn from(buffer: ManagedBuffer<M>) -> Self
fn from(buffer: ManagedBuffer<M>) -> Self
Converts to this type from the input type.
source§impl<M: ManagedTypeApi> ManagedDefault<M> for ManagedBuffer<M>
impl<M: ManagedTypeApi> ManagedDefault<M> for ManagedBuffer<M>
fn managed_default(api: M) -> Self
source§impl<M> ManagedFrom<M, &[u8]> for ManagedBuffer<M>where
M: ManagedTypeApi,
impl<M> ManagedFrom<M, &[u8]> for ManagedBuffer<M>where
M: ManagedTypeApi,
fn managed_from(api: M, bytes: &[u8]) -> Self
source§impl<M, const N: usize> ManagedFrom<M, &[u8; N]> for ManagedBuffer<M>where
M: ManagedTypeApi,
impl<M, const N: usize> ManagedFrom<M, &[u8; N]> for ManagedBuffer<M>where
M: ManagedTypeApi,
Syntactic sugar only.
fn managed_from(api: M, bytes: &[u8; N]) -> Self
source§impl<M> ManagedFrom<M, BoxedBytes> for ManagedBuffer<M>where
M: ManagedTypeApi,
impl<M> ManagedFrom<M, BoxedBytes> for ManagedBuffer<M>where
M: ManagedTypeApi,
fn managed_from(api: M, bytes: BoxedBytes) -> Self
source§impl<M: ManagedTypeApi> ManagedFrom<M, ManagedBuffer<M>> for TokenIdentifier<M>
impl<M: ManagedTypeApi> ManagedFrom<M, ManagedBuffer<M>> for TokenIdentifier<M>
fn managed_from(_: M, buffer: ManagedBuffer<M>) -> Self
source§impl<M> ManagedFrom<M, Vec<u8>> for ManagedBuffer<M>where
M: ManagedTypeApi,
impl<M> ManagedFrom<M, Vec<u8>> for ManagedBuffer<M>where
M: ManagedTypeApi,
fn managed_from(api: M, bytes: Vec<u8>) -> Self
source§impl<M: ManagedTypeApi> ManagedType<M> for ManagedBuffer<M>
impl<M: ManagedTypeApi> ManagedType<M> for ManagedBuffer<M>
fn type_manager(&self) -> M
source§impl<M: ManagedTypeApi> ManagedVecItem<M> for ManagedBuffer<M>
impl<M: ManagedTypeApi> ManagedVecItem<M> for ManagedBuffer<M>
source§const PAYLOAD_SIZE: usize = 4usize
const PAYLOAD_SIZE: usize = 4usize
Size of the data stored in the underlying
ManagedBuffer.source§const SKIPS_RESERIALIZATION: bool = false
const SKIPS_RESERIALIZATION: bool = false
If true, then the encoding of the item is identical to the payload,
and no further conversion is necessary
(the underlying buffer can be used as-is during serialization).
False for all managed types, but true for basic types (like
u32).fn from_byte_reader<Reader: FnMut(&mut [u8])>(api: M, reader: Reader) -> Self
fn to_byte_writer<R, Writer: FnMut(&[u8]) -> R>(&self, writer: Writer) -> R
source§impl<M: ManagedTypeApi> NestedDecode for ManagedBuffer<M>
impl<M: ManagedTypeApi> NestedDecode for ManagedBuffer<M>
source§fn dep_decode<I: NestedDecodeInput>(input: &mut I) -> Result<Self, DecodeError>
fn dep_decode<I: NestedDecodeInput>(input: &mut I) -> Result<Self, DecodeError>
Attempt to deserialise the value from input,
using the format of an object nested inside another structure.
In case of success returns the deserialized value and the number of bytes consumed during the operation.
source§fn dep_decode_or_exit<I: NestedDecodeInput, ExitCtx: Clone>(
input: &mut I,
c: ExitCtx,
exit: fn(_: ExitCtx, _: DecodeError) -> !
) -> Self
fn dep_decode_or_exit<I: NestedDecodeInput, ExitCtx: Clone>( input: &mut I, c: ExitCtx, exit: fn(_: ExitCtx, _: DecodeError) -> ! ) -> Self
Version of
top_decode that exits quickly in case of error.
Its purpose is to create smaller implementations
in cases where the application is supposed to exit directly on decode error.source§impl<M: ManagedTypeApi> NestedEncode for ManagedBuffer<M>
impl<M: ManagedTypeApi> NestedEncode for ManagedBuffer<M>
source§fn dep_encode<O: NestedEncodeOutput>(
&self,
dest: &mut O
) -> Result<(), EncodeError>
fn dep_encode<O: NestedEncodeOutput>( &self, dest: &mut O ) -> Result<(), EncodeError>
NestedEncode to output, using the format of an object nested inside another structure.
Does not provide compact version.
source§fn dep_encode_or_exit<O, ExitCtx>(
&self,
dest: &mut O,
c: ExitCtx,
exit: fn(_: ExitCtx, _: EncodeError) -> !
)where
O: NestedEncodeOutput,
ExitCtx: Clone,
fn dep_encode_or_exit<O, ExitCtx>(
&self,
dest: &mut O,
c: ExitCtx,
exit: fn(_: ExitCtx, _: EncodeError) -> !
)where
O: NestedEncodeOutput,
ExitCtx: Clone,
Version of
top_decode that exits quickly in case of error.
Its purpose is to create smaller implementations
in cases where the application is supposed to exit directly on decode error.source§impl<M: ManagedTypeApi> NestedEncodeOutput for ManagedBuffer<M>
impl<M: ManagedTypeApi> NestedEncodeOutput for ManagedBuffer<M>
fn push_specialized<T, C, F>( &mut self, context: C, value: &T, else_serialization: F ) -> Result<(), EncodeError>
source§impl<M: ManagedTypeApi, const N: usize> PartialEq<&[u8; N]> for ManagedBuffer<M>
impl<M: ManagedTypeApi, const N: usize> PartialEq<&[u8; N]> for ManagedBuffer<M>
source§impl<M: ManagedTypeApi> PartialEq<[u8]> for ManagedBuffer<M>
impl<M: ManagedTypeApi> PartialEq<[u8]> for ManagedBuffer<M>
source§impl<M: ManagedTypeApi> PartialEq for ManagedBuffer<M>
impl<M: ManagedTypeApi> PartialEq for ManagedBuffer<M>
source§impl<M: ManagedTypeApi> TopDecode for ManagedBuffer<M>
impl<M: ManagedTypeApi> TopDecode for ManagedBuffer<M>
source§fn top_decode<I: TopDecodeInput>(input: I) -> Result<Self, DecodeError>
fn top_decode<I: TopDecodeInput>(input: I) -> Result<Self, DecodeError>
Attempt to deserialize the value from input.
source§fn top_decode_or_exit<I, ExitCtx>(
input: I,
c: ExitCtx,
exit: fn(_: ExitCtx, _: DecodeError) -> !
) -> Selfwhere
I: TopDecodeInput,
ExitCtx: Clone,
fn top_decode_or_exit<I, ExitCtx>(
input: I,
c: ExitCtx,
exit: fn(_: ExitCtx, _: DecodeError) -> !
) -> Selfwhere
I: TopDecodeInput,
ExitCtx: Clone,
Version of
top_decode that exits quickly in case of error.
Its purpose is to create smaller implementations
in cases where the application is supposed to exit directly on decode error.source§impl<M> TopDecodeInput for ManagedBuffer<M>where
M: ManagedTypeApi,
impl<M> TopDecodeInput for ManagedBuffer<M>where
M: ManagedTypeApi,
type NestedBuffer = ManagedBufferNestedDecodeInput<M>
source§fn into_boxed_slice_u8(self) -> Box<[u8]>
fn into_boxed_slice_u8(self) -> Box<[u8]>
Provides the underlying data as an owned byte slice box.
Consumes the input object in the process.
source§fn into_u64(self) -> u64
fn into_u64(self) -> u64
Retrieves the underlying data as a pre-parsed u64.
Expected to panic if the conversion is not possible. Read more
fn into_specialized<T, F>(self, else_deser: F) -> Result<T, DecodeError>
fn into_nested_buffer(self) -> Self::NestedBuffer
source§fn into_i64(self) -> i64
fn into_i64(self) -> i64
Retrieves the underlying data as a pre-parsed i64.
Expected to panic if the conversion is not possible. Read more
source§fn into_specialized_or_exit<T, F, ExitCtx>(
self,
c: ExitCtx,
exit: fn(_: ExitCtx, _: DecodeError) -> !,
else_deser: F
) -> Twhere
T: TryStaticCast,
ExitCtx: Clone,
F: FnOnce(Self, ExitCtx, fn(_: ExitCtx, _: DecodeError) -> !) -> T,
fn into_specialized_or_exit<T, F, ExitCtx>(
self,
c: ExitCtx,
exit: fn(_: ExitCtx, _: DecodeError) -> !,
else_deser: F
) -> Twhere
T: TryStaticCast,
ExitCtx: Clone,
F: FnOnce(Self, ExitCtx, fn(_: ExitCtx, _: DecodeError) -> !) -> T,
Note: currently not in use.
source§impl<M: ManagedTypeApi> TopEncode for ManagedBuffer<M>
impl<M: ManagedTypeApi> TopEncode for ManagedBuffer<M>
source§fn top_encode<O: TopEncodeOutput>(&self, output: O) -> Result<(), EncodeError>
fn top_encode<O: TopEncodeOutput>(&self, output: O) -> Result<(), EncodeError>
Attempt to serialize the value to ouput.
source§fn top_encode_or_exit<O, ExitCtx>(
&self,
output: O,
c: ExitCtx,
exit: fn(_: ExitCtx, _: EncodeError) -> !
)where
O: TopEncodeOutput,
ExitCtx: Clone,
fn top_encode_or_exit<O, ExitCtx>(
&self,
output: O,
c: ExitCtx,
exit: fn(_: ExitCtx, _: EncodeError) -> !
)where
O: TopEncodeOutput,
ExitCtx: Clone,
Version of
top_decode that exits quickly in case of error.
Its purpose is to create smaller bytecode implementations
in cases where the application is supposed to exit directly on decode error.source§impl<M: ManagedTypeApi> TopEncodeOutput for &mut ManagedBuffer<M>
impl<M: ManagedTypeApi> TopEncodeOutput for &mut ManagedBuffer<M>
§type NestedBuffer = ManagedBuffer<M>
type NestedBuffer = ManagedBuffer<M>
Type of
NestedEncodeOutput that can be spawned to gather serializations of children.fn set_slice_u8(self, bytes: &[u8])
fn set_u64(self, value: u64)
fn set_i64(self, value: i64)
source§fn set_specialized<T, F>(
self,
value: &T,
else_serialization: F
) -> Result<(), EncodeError>
fn set_specialized<T, F>( self, value: &T, else_serialization: F ) -> Result<(), EncodeError>
Allows special handling of special types.
Also requires an alternative serialization, in case the special handling is not covered.
The alternative serialization,
else_serialization is only called when necessary and
is normally compiled out via monomorphization.fn start_nested_encode(&self) -> Self::NestedBuffer
fn finalize_nested_encode(self, nb: Self::NestedBuffer)
fn set_boxed_bytes(self, bytes: Box<[u8]>)
source§impl<M: ManagedTypeApi> TryStaticCast for ManagedBuffer<M>
impl<M: ManagedTypeApi> TryStaticCast for ManagedBuffer<M>
fn type_eq<U>() -> boolwhere
U: TryStaticCast,
fn try_cast<U>(self) -> Option<U>where
U: TryStaticCast,
fn try_cast_ref<U>(&self) -> Option<&U>where
U: TryStaticCast,
source§impl<M: ManagedTypeApi> TypeAbi for ManagedBuffer<M>
impl<M: ManagedTypeApi> TypeAbi for ManagedBuffer<M>
fn type_name() -> String
source§fn provide_type_descriptions<TDC: TypeDescriptionContainer>(
accumulator: &mut TDC
)
fn provide_type_descriptions<TDC: TypeDescriptionContainer>( accumulator: &mut TDC )
A type can provide more than its own description.
For instance, a struct can also provide the descriptions of the type of its fields.
TypeAbi doesn’t care for the exact accumulator type,
which is abstracted by the TypeDescriptionContainer trait.
impl<M: ManagedTypeApi> Eq for ManagedBuffer<M>
Auto Trait Implementations§
impl<M> RefUnwindSafe for ManagedBuffer<M>where
M: RefUnwindSafe,
impl<M> Send for ManagedBuffer<M>where
M: Send,
impl<M> Sync for ManagedBuffer<M>where
M: Sync,
impl<M> Unpin for ManagedBuffer<M>where
M: Unpin,
impl<M> UnwindSafe for ManagedBuffer<M>where
M: UnwindSafe,
Blanket Implementations§
source§impl<M, T> AsManagedRef<M, T> for Twhere
M: ManagedTypeApi,
T: ManagedType<M>,
impl<M, T> AsManagedRef<M, T> for Twhere
M: ManagedTypeApi,
T: ManagedType<M>,
fn as_managed_ref(&self) -> ManagedRef<M, T>
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more