Added Sized to aid in less typing so the trait can define common funcs.

Changed the use of Vectors to the Spellbook DynamicArray class.
This commit is contained in:
Myrddin Dundragon 2017-11-23 00:02:24 -05:00
parent 3a1b847c51
commit 6a9e75a05c
6 changed files with 102 additions and 420 deletions

View File

@ -17,6 +17,9 @@ convert_sigils = ["sigils"]
[dependencies.scribe]
git = "ssh://git@gitlab.com/CyberMages/Core/scribe.git"
[dependencies.spellbook]
git = "ssh://git@gitlab.com/CyberMages/Core/spellbook.git"
[dependencies.sigils]
git = "ssh://git@gitlab.com/CyberMages/Core/sigils.git"
optional = true

View File

@ -1,5 +1,7 @@
use std::mem;
use spellbook::components::DynamicArray;
use ::byte_sized::ByteSized;
@ -89,7 +91,7 @@ pub trait Converter
/// # Panics
/// This will panic if the buffer does not have
/// enough space to store the converted value.
fn i16_to_bytes(num: i16) -> Vec<u8>
fn i16_to_bytes(num: i16) -> DynamicArray<u8>
{
Self::u16_to_bytes(num as u16)
}
@ -100,7 +102,7 @@ pub trait Converter
/// # Panics
/// This will panic if the buffer does not have
/// enough space to store the converted value.
fn i32_to_bytes(num: i32) -> Vec<u8>
fn i32_to_bytes(num: i32) -> DynamicArray<u8>
{
Self::u32_to_bytes(num as u32)
}
@ -111,7 +113,7 @@ pub trait Converter
/// # Panics
/// This will panic if the buffer does not have
/// enough space to store the converted value.
fn i64_to_bytes(num: i64) -> Vec<u8>
fn i64_to_bytes(num: i64) -> DynamicArray<u8>
{
Self::u64_to_bytes(num as u64)
}
@ -126,7 +128,7 @@ pub trait Converter
/// This will panic if the number of bytes
/// passed in is less than the byte size of the given number
/// or more than eight.
fn isize_to_bytes(num: isize) -> Vec<u8>
fn isize_to_bytes(num: isize) -> DynamicArray<u8>
{
let temp_num: usize;
@ -140,7 +142,7 @@ pub trait Converter
/// # Panics
/// This will panic if the buffer does not have
/// enough space to store the converted value.
fn f32_to_bytes(num: f32) -> Vec<u8>
fn f32_to_bytes(num: f32) -> DynamicArray<u8>
{
unsafe
{
@ -154,7 +156,7 @@ pub trait Converter
/// # Panics
/// This will panic if the buffer does not have
/// enough space to store the converted value.
fn f64_to_bytes(num: f64) -> Vec<u8>
fn f64_to_bytes(num: f64) -> DynamicArray<u8>
{
unsafe
{
@ -202,7 +204,7 @@ pub trait Converter
/// # Panics
/// This will panic if the buffer does not have
/// enough space to store the converted value.
fn u16_to_bytes(num: u16) -> Vec<u8>;
fn u16_to_bytes(num: u16) -> DynamicArray<u8>;
/// Converts an unsigned 32-bit integer to bytes
/// and places them into the given buffer.
@ -210,7 +212,7 @@ pub trait Converter
/// # Panics
/// This will panic if the buffer does not have
/// enough space to store the converted value.
fn u32_to_bytes(num: u32) -> Vec<u8>;
fn u32_to_bytes(num: u32) -> DynamicArray<u8>;
/// Converts an unsigned 64-bit integer to bytes
/// and places them into the given buffer.
@ -218,7 +220,7 @@ pub trait Converter
/// # Panics
/// This will panic if the buffer does not have
/// enough space to store the converted value.
fn u64_to_bytes(num: u64) -> Vec<u8>;
fn u64_to_bytes(num: u64) -> DynamicArray<u8>;
/// Converts an unsigned integer to bytes
/// and places them into the given buffer.
@ -230,7 +232,7 @@ pub trait Converter
/// This will panic if the number of bytes
/// passed in is less than the byte size of the given number
/// or more than eight.
fn usize_to_bytes(num: usize) -> Vec<u8>;
fn usize_to_bytes(num: usize) -> DynamicArray<u8>;
/// Converts a String to bytes
@ -250,7 +252,7 @@ pub trait Converter
/// # Panics
/// This will panic if the buffer does not have
/// enough information to convert.
fn string_to_bytes(string: String) -> Vec<u8>;
fn string_to_bytes(string: String) -> DynamicArray<u8>;
}

View File

@ -1,3 +1,5 @@
use spellbook::components::DynamicArray;
use ::byte_sized::ByteSized;
use ::byte_sized::U64_BYTES;
use ::converter::Converter;
@ -144,25 +146,25 @@ impl Converter for BigEndian
}
fn u16_to_bytes(num: u16) -> Vec<u8>
fn u16_to_bytes(num: u16) -> DynamicArray<u8>
{
// Unpack the value into it's byte form.
unpack_big_endian!(num, u16::BYTES)
}
fn u32_to_bytes(num: u32) -> Vec<u8>
fn u32_to_bytes(num: u32) -> DynamicArray<u8>
{
// Unpack the value into it's byte form.
unpack_big_endian!(num, u32::BYTES)
}
fn u64_to_bytes(num: u64) -> Vec<u8>
fn u64_to_bytes(num: u64) -> DynamicArray<u8>
{
// Unpack the value into it's byte form.
unpack_big_endian!(num, u64::BYTES)
}
fn usize_to_bytes(num: usize) -> Vec<u8>
fn usize_to_bytes(num: usize) -> DynamicArray<u8>
{
// Unpack the value into it's byte form.
unpack_big_endian!(num, usize::BYTES)
@ -204,11 +206,11 @@ impl Converter for BigEndian
new_string
}
fn string_to_bytes(string: String) -> Vec<u8>
fn string_to_bytes(string: String) -> DynamicArray<u8>
{
let bytes: &[u8];
let byte_count: u64;
let mut buffer: Vec<u8>;
let mut buffer: DynamicArray<u8>;
// Turn the string into a byte array.
bytes = string.as_bytes();
@ -218,7 +220,7 @@ impl Converter for BigEndian
byte_count = bytes.len() as u64;
// Make sure the buffer has enough space for this string.
buffer = Vec::with_capacity(bytes.len() + U64_BYTES);
buffer = DynamicArray::with_capacity(bytes.len() + U64_BYTES);
// Add the count to the buffer.
buffer.append(&mut BigEndian::u64_to_bytes(byte_count));
@ -272,25 +274,25 @@ impl Converter for LittleEndian
}
fn u16_to_bytes(num: u16) -> Vec<u8>
fn u16_to_bytes(num: u16) -> DynamicArray<u8>
{
// Unpack the value into it's byte form.
unpack_little_endian!(num, u16::BYTES)
}
fn u32_to_bytes(num: u32) -> Vec<u8>
fn u32_to_bytes(num: u32) -> DynamicArray<u8>
{
// Unpack the value into it's byte form.
unpack_little_endian!(num, u32::BYTES)
}
fn u64_to_bytes(num: u64) -> Vec<u8>
fn u64_to_bytes(num: u64) -> DynamicArray<u8>
{
// Unpack the value into it's byte form.
unpack_little_endian!(num, u64::BYTES)
}
fn usize_to_bytes(num: usize) -> Vec<u8>
fn usize_to_bytes(num: usize) -> DynamicArray<u8>
{
// Unpack the value into it's byte form.
unpack_little_endian!(num, usize::BYTES)
@ -332,11 +334,11 @@ impl Converter for LittleEndian
new_string
}
fn string_to_bytes(string: String) -> Vec<u8>
fn string_to_bytes(string: String) -> DynamicArray<u8>
{
let bytes: &[u8];
let byte_count: u64;
let mut buffer: Vec<u8>;
let mut buffer: DynamicArray<u8>;
// Turn the string into a byte array.
bytes = string.as_bytes();
@ -346,7 +348,7 @@ impl Converter for LittleEndian
byte_count = bytes.len() as u64;
// Make sure the buffer has enough space for this string.
buffer = Vec::with_capacity(bytes.len() + U64_BYTES);
buffer = DynamicArray::with_capacity(bytes.len() + U64_BYTES);
// Add the count to the buffer.
buffer.append(&mut LittleEndian::u64_to_bytes(byte_count));

View File

@ -4,7 +4,6 @@
#![doc(html_logo_url="",
html_favicon_url="http://cybermagesllc.com/favicon.ico",
html_root_url="http://cybermagesllc.com")]
#![feature(associated_consts)]
#![warn(missing_docs)]
@ -15,6 +14,8 @@ extern crate scribe;
#[cfg(feature="sigils")]
extern crate sigils;
extern crate spellbook;
#[macro_use]

View File

@ -63,11 +63,11 @@ macro_rules! unpack_big_endian
($value: expr, $bytes: expr) =>
{
{
let mut buffer: Vec<u8>;
let mut buffer: ::spellbook::components::DynamicArray<u8>;
// Create an array with enough space for this value
// and then bit shift the value into a buffer of bytes.
buffer = Vec::with_capacity($bytes);
buffer = ::spellbook::components::DynamicArray::with_capacity($bytes);
for i in 0..$bytes
{
buffer.push(($value >> (($bytes - i) - 1) * 8) as u8);
@ -85,11 +85,11 @@ macro_rules! unpack_little_endian
($value: expr, $bytes: expr) =>
{
{
let mut buffer: Vec<u8>;
let mut buffer: ::spellbook::components::DynamicArray<u8>;
// Create an array with enough space for this value
// and then bit shift the value into a buffer of bytes.
buffer = Vec::with_capacity($bytes);
buffer = ::spellbook::components::DynamicArray::with_capacity($bytes);
for i in 0..$bytes
{
buffer.push(($value >> (i * 8)) as u8);
@ -107,7 +107,7 @@ macro_rules! swap_big_to_little_endian
($value: expr, $target_type: ty, $bytes: expr) =>
{
{
let buffer: Vec<u8>;
let buffer: ::spellbook::components::DynamicArray<u8>;
// Convert the big endian value to bytes.
buffer = unpack_big_endian!($value, $bytes);
@ -124,7 +124,7 @@ macro_rules! swap_little_to_big_endian
($value: expr, $target_type: ty, $bytes: expr) =>
{
{
let buffer: Vec<u8>;
let buffer: ::spellbook::components::DynamicArray<u8>;
// Convert the little endian value to bytes.
buffer = unpack_little_endian!($value, $bytes);

View File

@ -1,8 +1,10 @@
use spellbook::components::DynamicArray;
#[cfg(feature="convert_sigils")]
use sigils::{Zero, Number, Real};
#[cfg(feature="convert_sigils")]
use sigils::vector::{Vector, Vector2, Vector3, Vector4};
use sigils::vector::{DynamicArraytor, DynamicArraytor2, DynamicArraytor3, DynamicArraytor4};
#[cfg(feature="convert_sigils")]
use sigils::quaternion::Quaternion;
@ -17,11 +19,14 @@ use ::endian::Endianess;
// From and Into are not used because we need to also
// know the endianess to use for converting.
/// A type that can be converted to and from bytes.
pub trait Transmutable
pub trait Transmutable: Sized
{
/// Transmute an array of bytes in the
/// platform's endian to this type.
fn from_bytes(buffer: &[u8]) -> Self;
fn from_bytes(buffer: &[u8]) -> Self
{
Self::from_endian_bytes(buffer, Endianess::Platform)
}
/// Transmute an array of bytes in the
/// given endian to this type.
@ -30,20 +35,29 @@ pub trait Transmutable
/// Transmute this type to an array of bytes in
/// the Platform's endian.
fn to_bytes(self) -> Vec<u8>;
fn to_bytes(self) -> DynamicArray<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
/// Transmute this type to an array of bytes in
/// the desired endian.
fn to_endian_bytes(self, endianess: Endianess) -> Vec<u8>;
fn to_endian_bytes(self, endianess: Endianess) -> DynamicArray<u8>
{
self.as_endian_bytes(endianess)
}
/// Transmute this type to an array of bytes in
/// the Platform's endian.
fn as_bytes(&self) -> Vec<u8>;
fn as_bytes(&self) -> DynamicArray<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
/// Transmute this type to an array of bytes in
/// the desired endian.
fn as_endian_bytes(&self, endianess: Endianess) -> Vec<u8>;
fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray<u8>;
/// Get the current size of this Transmutable in bytes.
@ -122,11 +136,6 @@ macro_rules! handle_endianess_from_bytes
impl Transmutable for u8
{
fn from_bytes(buffer: &[u8]) -> Self
{
Self::from_endian_bytes(buffer, Endianess::Platform)
}
#[allow(unused_variables)]
fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self
{
@ -139,23 +148,8 @@ impl Transmutable for u8
buffer[0]
}
fn to_bytes(self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn to_endian_bytes(self, endianess: Endianess) -> Vec<u8>
{
self.as_endian_bytes(endianess)
}
fn as_bytes(&self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
#[allow(unused_variables)]
fn as_endian_bytes(&self, endianess: Endianess) -> Vec<u8>
fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray<u8>
{
// A single byte has no endian form.
vec![*self]
@ -169,11 +163,6 @@ impl Transmutable for u8
impl Transmutable for u16
{
fn from_bytes(buffer: &[u8]) -> Self
{
Self::from_endian_bytes(buffer, Endianess::Platform)
}
fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self
{
// Make sure that there is enough data to read
@ -184,22 +173,7 @@ impl Transmutable for u16
handle_endianess_from_bytes!(buffer, endianess, bytes_to_u16)
}
fn to_bytes(self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn to_endian_bytes(self, endianess: Endianess) -> Vec<u8>
{
self.as_endian_bytes(endianess)
}
fn as_bytes(&self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn as_endian_bytes(&self, endianess: Endianess) -> Vec<u8>
fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray<u8>
{
// Return the Endianess conversion.
handle_endianess_to_bytes!(self, endianess, u16_to_bytes)
@ -213,11 +187,6 @@ impl Transmutable for u16
impl Transmutable for u32
{
fn from_bytes(buffer: &[u8]) -> Self
{
Self::from_endian_bytes(buffer, Endianess::Platform)
}
fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self
{
// Make sure that there is enough data to read
@ -228,22 +197,7 @@ impl Transmutable for u32
handle_endianess_from_bytes!(buffer, endianess, bytes_to_u32)
}
fn to_bytes(self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn to_endian_bytes(self, endianess: Endianess) -> Vec<u8>
{
self.as_endian_bytes(endianess)
}
fn as_bytes(&self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn as_endian_bytes(&self, endianess: Endianess) -> Vec<u8>
fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray<u8>
{
// Convert this to bytes and add it to the buffer.
handle_endianess_to_bytes!(self, endianess, u32_to_bytes)
@ -257,11 +211,6 @@ impl Transmutable for u32
impl Transmutable for u64
{
fn from_bytes(buffer: &[u8]) -> Self
{
Self::from_endian_bytes(buffer, Endianess::Platform)
}
fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self
{
// Make sure that there is enough data to read
@ -272,22 +221,7 @@ impl Transmutable for u64
handle_endianess_from_bytes!(buffer, endianess, bytes_to_u64)
}
fn to_bytes(self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn to_endian_bytes(self, endianess: Endianess) -> Vec<u8>
{
self.as_endian_bytes(endianess)
}
fn as_bytes(&self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn as_endian_bytes(&self, endianess: Endianess) -> Vec<u8>
fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray<u8>
{
// Convert this to bytes and add it to the buffer.
handle_endianess_to_bytes!(self, endianess, u64_to_bytes)
@ -301,11 +235,6 @@ impl Transmutable for u64
impl Transmutable for usize
{
fn from_bytes(buffer: &[u8]) -> Self
{
Self::from_endian_bytes(buffer, Endianess::Platform)
}
fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self
{
// Make sure that there is enough data to read
@ -316,22 +245,7 @@ impl Transmutable for usize
handle_endianess_from_bytes!(buffer, endianess, bytes_to_usize)
}
fn to_bytes(self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn to_endian_bytes(self, endianess: Endianess) -> Vec<u8>
{
self.as_endian_bytes(endianess)
}
fn as_bytes(&self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn as_endian_bytes(&self, endianess: Endianess) -> Vec<u8>
fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray<u8>
{
// Convert this to bytes and add it to the buffer.
handle_endianess_to_bytes!(self, endianess, usize_to_bytes)
@ -345,11 +259,6 @@ impl Transmutable for usize
impl Transmutable for i8
{
fn from_bytes(buffer: &[u8]) -> Self
{
Self::from_endian_bytes(buffer, Endianess::Platform)
}
#[allow(unused_variables)]
fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self
{
@ -360,23 +269,8 @@ impl Transmutable for i8
buffer[0] as i8
}
fn to_bytes(self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn to_endian_bytes(self, endianess: Endianess) -> Vec<u8>
{
self.as_endian_bytes(endianess)
}
fn as_bytes(&self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
#[allow(unused_variables)]
fn as_endian_bytes(&self, endianess: Endianess) -> Vec<u8>
fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray<u8>
{
vec![*self as u8]
}
@ -389,11 +283,6 @@ impl Transmutable for i8
impl Transmutable for i16
{
fn from_bytes(buffer: &[u8]) -> Self
{
Self::from_endian_bytes(buffer, Endianess::Platform)
}
fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self
{
// Make sure that there is enough data to read
@ -404,22 +293,7 @@ impl Transmutable for i16
handle_endianess_from_bytes!(buffer, endianess, bytes_to_i16)
}
fn to_bytes(self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn to_endian_bytes(self, endianess: Endianess) -> Vec<u8>
{
self.as_endian_bytes(endianess)
}
fn as_bytes(&self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn as_endian_bytes(&self, endianess: Endianess) -> Vec<u8>
fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray<u8>
{
// Convert this to bytes and add it to the buffer.
handle_endianess_to_bytes!(self, endianess, i16_to_bytes)
@ -433,11 +307,6 @@ impl Transmutable for i16
impl Transmutable for i32
{
fn from_bytes(buffer: &[u8]) -> Self
{
Self::from_endian_bytes(buffer, Endianess::Platform)
}
fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self
{
// Make sure that there is enough data to read
@ -448,22 +317,7 @@ impl Transmutable for i32
handle_endianess_from_bytes!(buffer, endianess, bytes_to_i32)
}
fn to_bytes(self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn to_endian_bytes(self, endianess: Endianess) -> Vec<u8>
{
self.as_endian_bytes(endianess)
}
fn as_bytes(&self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn as_endian_bytes(&self, endianess: Endianess) -> Vec<u8>
fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray<u8>
{
// Convert this to bytes and add it to the buffer.
handle_endianess_to_bytes!(self, endianess, i32_to_bytes)
@ -477,11 +331,6 @@ impl Transmutable for i32
impl Transmutable for i64
{
fn from_bytes(buffer: &[u8]) -> Self
{
Self::from_endian_bytes(buffer, Endianess::Platform)
}
fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self
{
// Make sure that there is enough data to read
@ -492,22 +341,7 @@ impl Transmutable for i64
handle_endianess_from_bytes!(buffer, endianess, bytes_to_i64)
}
fn to_bytes(self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn to_endian_bytes(self, endianess: Endianess) -> Vec<u8>
{
self.as_endian_bytes(endianess)
}
fn as_bytes(&self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn as_endian_bytes(&self, endianess: Endianess) -> Vec<u8>
fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray<u8>
{
// Convert this to bytes and add it to the buffer.
handle_endianess_to_bytes!(self, endianess, i64_to_bytes)
@ -521,11 +355,6 @@ impl Transmutable for i64
impl Transmutable for isize
{
fn from_bytes(buffer: &[u8]) -> Self
{
Self::from_endian_bytes(buffer, Endianess::Platform)
}
fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self
{
// Make sure that there is enough data to read
@ -536,22 +365,7 @@ impl Transmutable for isize
handle_endianess_from_bytes!(buffer, endianess, bytes_to_isize)
}
fn to_bytes(self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn to_endian_bytes(self, endianess: Endianess) -> Vec<u8>
{
self.as_endian_bytes(endianess)
}
fn as_bytes(&self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn as_endian_bytes(&self, endianess: Endianess) -> Vec<u8>
fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray<u8>
{
// Convert this to bytes and add it to the buffer.
handle_endianess_to_bytes!(self, endianess, isize_to_bytes)
@ -565,11 +379,6 @@ impl Transmutable for isize
impl Transmutable for f32
{
fn from_bytes(buffer: &[u8]) -> Self
{
Self::from_endian_bytes(buffer, Endianess::Platform)
}
fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self
{
// Make sure that there is enough data to read
@ -580,22 +389,7 @@ impl Transmutable for f32
handle_endianess_from_bytes!(buffer, endianess, bytes_to_f32)
}
fn to_bytes(self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn to_endian_bytes(self, endianess: Endianess) -> Vec<u8>
{
self.as_endian_bytes(endianess)
}
fn as_bytes(&self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn as_endian_bytes(&self, endianess: Endianess) -> Vec<u8>
fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray<u8>
{
// Convert this to bytes and add it to the buffer.
handle_endianess_to_bytes!(self, endianess, f32_to_bytes)
@ -609,11 +403,6 @@ impl Transmutable for f32
impl Transmutable for f64
{
fn from_bytes(buffer: &[u8]) -> Self
{
Self::from_endian_bytes(buffer, Endianess::Platform)
}
fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self
{
// Make sure that there is enough data to read
@ -624,22 +413,7 @@ impl Transmutable for f64
handle_endianess_from_bytes!(buffer, endianess, bytes_to_f64)
}
fn to_bytes(self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn to_endian_bytes(self, endianess: Endianess) -> Vec<u8>
{
self.as_endian_bytes(endianess)
}
fn as_bytes(&self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn as_endian_bytes(&self, endianess: Endianess) -> Vec<u8>
fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray<u8>
{
// Convert this to bytes and add it to the buffer.
handle_endianess_to_bytes!(self, endianess, f64_to_bytes)
@ -653,33 +427,13 @@ impl Transmutable for f64
impl Transmutable for String
{
fn from_bytes(buffer: &[u8]) -> Self
{
Self::from_endian_bytes(buffer, Endianess::Platform)
}
fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self
{
// Convert the given bytes to this type and return it.
handle_endianess_from_bytes!(buffer, endianess, bytes_to_string)
}
fn to_bytes(self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn to_endian_bytes(self, endianess: Endianess) -> Vec<u8>
{
self.as_endian_bytes(endianess)
}
fn as_bytes(&self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn as_endian_bytes(&self, endianess: Endianess) -> Vec<u8>
fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray<u8>
{
// Convert this to bytes and add it to the buffer.
// We are not using the macro because *String is a str.
@ -714,22 +468,17 @@ impl Transmutable for String
}
#[cfg(feature="convert_sigils")]
impl<T> Transmutable for Vector2<T> where T: Number + ByteSized + Transmutable
impl<T> Transmutable for DynamicArraytor2<T> where T: Number + ByteSized + Transmutable
{
fn from_bytes(buffer: &[u8]) -> Self
{
Self::from_endian_bytes(buffer, Endianess::Platform)
}
fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self
{
let byte_size: usize;
let num_bytes: usize;
let mut vec: Vector2<T>;
let mut vec: DynamicArraytor2<T>;
// Determine the number of bytes requires to
// represent a Vector2.
vec = Vector2::<T>::zero();
// represent a DynamicArraytor2.
vec = DynamicArraytor2::<T>::zero();
byte_size = T::get_byte_size();
num_bytes = byte_size * vec.get_size() as usize;
@ -745,35 +494,20 @@ impl<T> Transmutable for Vector2<T> where T: Number + ByteSized + Transmutable
vec
}
fn to_bytes(self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn to_endian_bytes(self, endianess: Endianess) -> Vec<u8>
{
self.as_endian_bytes(endianess)
}
fn as_bytes(&self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn as_endian_bytes(&self, endianess: Endianess) -> Vec<u8>
fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray<u8>
{
let byte_size: usize;
let num_bytes: usize;
let mut buffer: Vec<u8>;
let mut buffer: DynamicArray<u8>;
// Determine the number of bytes requires to
// represent a Vector2.
// represent a DynamicArraytor2.
byte_size = T::get_byte_size();
num_bytes = byte_size * self.get_size() as usize;
// Make sure that there is enough space to store
// the bytes from this type.
buffer = Vec::with_capacity(num_bytes);
buffer = DynamicArray::with_capacity(num_bytes);
// Convert this to bytes and add it to the buffer.
buffer.append(&mut self.x.as_endian_bytes(endianess));
@ -790,22 +524,17 @@ impl<T> Transmutable for Vector2<T> where T: Number + ByteSized + Transmutable
}
#[cfg(feature="convert_sigils")]
impl<T> Transmutable for Vector3<T> where T: Number + ByteSized + Transmutable
impl<T> Transmutable for DynamicArraytor3<T> where T: Number + ByteSized + Transmutable
{
fn from_bytes(buffer: &[u8]) -> Self
{
Self::from_endian_bytes(buffer, Endianess::Platform)
}
fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self
{
let byte_size: usize;
let num_bytes: usize;
let mut vec: Vector3<T>;
let mut vec: DynamicArraytor3<T>;
// Determine the number of bytes requires to
// represent a Vector3.
vec = Vector3::<T>::zero();
// represent a DynamicArraytor3.
vec = DynamicArraytor3::<T>::zero();
byte_size = T::get_byte_size();
num_bytes = byte_size * vec.get_size() as usize;
@ -823,35 +552,20 @@ impl<T> Transmutable for Vector3<T> where T: Number + ByteSized + Transmutable
vec
}
fn to_bytes(self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn to_endian_bytes(self, endianess: Endianess) -> Vec<u8>
{
self.as_endian_bytes(endianess)
}
fn as_bytes(&self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn as_endian_bytes(&self, endianess: Endianess) -> Vec<u8>
fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray<u8>
{
let byte_size: usize;
let num_bytes: usize;
let mut buffer: Vec<u8>;
let mut buffer: DynamicArray<u8>;
// Determine the number of bytes requires to
// represent a Vector3.
// represent a DynamicArraytor3.
byte_size = T::get_byte_size();
num_bytes = byte_size * self.get_size() as usize;
// Make sure that there is enough space to store
// the bytes from this type.
buffer = Vec::with_capacity(num_bytes);
buffer = DynamicArray::with_capacity(num_bytes);
// Convert this to bytes and add it to the buffer.
buffer.append(&mut self.x.as_endian_bytes(endianess));
@ -869,22 +583,17 @@ impl<T> Transmutable for Vector3<T> where T: Number + ByteSized + Transmutable
}
#[cfg(feature="convert_sigils")]
impl<T> Transmutable for Vector4<T> where T: Number + ByteSized + Transmutable
impl<T> Transmutable for DynamicArraytor4<T> where T: Number + ByteSized + Transmutable
{
fn from_bytes(buffer: &[u8]) -> Self
{
Self::from_endian_bytes(buffer, Endianess::Platform)
}
fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self
{
let byte_size: usize;
let num_bytes: usize;
let mut vec: Vector4<T>;
let mut vec: DynamicArraytor4<T>;
// Determine the number of bytes requires to
// represent a Vector4.
vec = Vector4::<T>::zero();
// represent a DynamicArraytor4.
vec = DynamicArraytor4::<T>::zero();
byte_size = T::get_byte_size();
num_bytes = byte_size * vec.get_size() as usize;
@ -904,35 +613,20 @@ impl<T> Transmutable for Vector4<T> where T: Number + ByteSized + Transmutable
vec
}
fn to_bytes(self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn to_endian_bytes(self, endianess: Endianess) -> Vec<u8>
{
self.as_endian_bytes(endianess)
}
fn as_bytes(&self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn as_endian_bytes(&self, endianess: Endianess) -> Vec<u8>
fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray<u8>
{
let byte_size: usize;
let num_bytes: usize;
let mut buffer: Vec<u8>;
let mut buffer: DynamicArray<u8>;
// Determine the number of bytes requires to
// represent a Vector4.
// represent a DynamicArraytor4.
byte_size = T::get_byte_size();
num_bytes = byte_size * self.get_size() as usize;
// Make sure that there is enough space to store
// the bytes from this type.
buffer = Vec::with_capacity(num_bytes);
buffer = DynamicArray::with_capacity(num_bytes);
// Convert this to bytes and add it to the buffer.
buffer.append(&mut self.x.as_endian_bytes(endianess));
@ -954,11 +648,6 @@ impl<T> Transmutable for Vector4<T> where T: Number + ByteSized + Transmutable
impl<T> Transmutable for Quaternion<T>
where T: Real + ByteSized + Transmutable
{
fn from_bytes(buffer: &[u8]) -> Self
{
Self::from_endian_bytes(buffer, Endianess::Platform)
}
fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self
{
let byte_size: usize;
@ -978,31 +667,16 @@ impl<T> Transmutable for Quaternion<T>
// Convert the given bytes to this type and return it.
quat.scalar = T::from_endian_bytes(&buffer[0..byte_size], endianess);
quat.vector =
Vector3::<T>::from_endian_bytes(&buffer[byte_size..num_bytes],
DynamicArraytor3::<T>::from_endian_bytes(&buffer[byte_size..num_bytes],
endianess);
quat
}
fn to_bytes(self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn to_endian_bytes(self, endianess: Endianess) -> Vec<u8>
{
self.as_endian_bytes(endianess)
}
fn as_bytes(&self) -> Vec<u8>
{
self.as_endian_bytes(Endianess::Platform)
}
fn as_endian_bytes(&self, endianess: Endianess) -> Vec<u8>
fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray<u8>
{
let byte_size: usize;
let num_bytes: usize;
let mut buffer: Vec<u8>;
let mut buffer: DynamicArray<u8>;
// Determine the number of bytes requires to
// represent a Quaternion.
@ -1011,7 +685,7 @@ impl<T> Transmutable for Quaternion<T>
// Make sure that there is enough space to store
// the bytes from this type.
buffer = Vec::with_capacity(num_bytes);
buffer = DynamicArray::with_capacity(num_bytes);
// Convert this to bytes and add it to the buffer.
buffer.append(&mut self.scalar.as_endian_bytes(endianess));