mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 03:21:06 +00:00
reorganize native-support exports
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
|
||||
//! Vec<u8> serialiser.
|
||||
|
||||
use runtime_support::Vec;
|
||||
use runtime_support::vec::Vec;
|
||||
use slicable::Slicable;
|
||||
|
||||
/// Trait to allow itself to be serialised into a `Vec<u8>`
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
//! Serialiser and prepender.
|
||||
|
||||
use runtime_support::Vec;
|
||||
use runtime_support::vec::Vec;
|
||||
use slicable::Slicable;
|
||||
|
||||
/// Trait to allow itselg to be serialised and prepended by a given slice.
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
|
||||
//! Serialisation.
|
||||
|
||||
use runtime_support::{Vec, size_of, transmute, uninitialized, slice};
|
||||
use runtime_support::vec::Vec;
|
||||
use runtime_support::{mem, slice};
|
||||
use joiner::Joiner;
|
||||
use endiansensitive::EndianSensitive;
|
||||
|
||||
@@ -45,10 +46,11 @@ pub trait NonTrivialSlicable: Slicable {}
|
||||
|
||||
impl<T: EndianSensitive> Slicable for T {
|
||||
fn set_as_slice<F: FnOnce(&mut[u8]) -> bool>(fill_slice: F) -> Option<Self> {
|
||||
let size = size_of::<T>();
|
||||
let mut result: T = unsafe { uninitialized() };
|
||||
let size = mem::size_of::<T>();
|
||||
let mut result: T = unsafe { mem::uninitialized() };
|
||||
let result_slice = unsafe {
|
||||
slice::from_raw_parts_mut(transmute::<*mut T, *mut u8>(&mut result), size)
|
||||
let ptr = &mut result as *mut _ as *mut u8;
|
||||
slice::from_raw_parts_mut(ptr, size)
|
||||
};
|
||||
if fill_slice(result_slice) {
|
||||
Some(result.from_le())
|
||||
@@ -57,16 +59,17 @@ impl<T: EndianSensitive> Slicable for T {
|
||||
}
|
||||
}
|
||||
fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
let size = size_of::<Self>();
|
||||
let size = mem::size_of::<Self>();
|
||||
self.as_le_then(|le| {
|
||||
let value_slice = unsafe {
|
||||
slice::from_raw_parts(transmute::<*const Self, *const u8>(le), size)
|
||||
let ptr = le as *const _ as *const u8;
|
||||
slice::from_raw_parts(ptr, size)
|
||||
};
|
||||
f(value_slice)
|
||||
})
|
||||
}
|
||||
fn size_of(_value: &[u8]) -> Option<usize> {
|
||||
Some(size_of::<Self>())
|
||||
Some(mem::size_of::<Self>())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,13 +20,13 @@ use slicable::Slicable;
|
||||
|
||||
/// Simple deserialiser.
|
||||
pub struct StreamReader<'a> {
|
||||
data: &'a[u8],
|
||||
data: &'a [u8],
|
||||
offset: usize,
|
||||
}
|
||||
|
||||
impl<'a> StreamReader<'a> {
|
||||
/// Create a new deserialiser based on the `data`.
|
||||
pub fn new(data: &'a[u8]) -> Self {
|
||||
pub fn new(data: &'a [u8]) -> Self {
|
||||
StreamReader {
|
||||
data: data,
|
||||
offset: 0,
|
||||
|
||||
Reference in New Issue
Block a user