Implement Abomonation for dynamic matrices
This commit is contained in:
parent
49f12a379d
commit
7c3a05f668
|
@ -5,6 +5,9 @@ use core::dimension::{Dim, DimName, Dynamic, U1};
|
||||||
use core::storage::{Storage, StorageMut, Owned, OwnedStorage};
|
use core::storage::{Storage, StorageMut, Owned, OwnedStorage};
|
||||||
use core::default_allocator::DefaultAllocator;
|
use core::default_allocator::DefaultAllocator;
|
||||||
|
|
||||||
|
#[cfg(feature = "abomonation-serialize")]
|
||||||
|
use abomonation::Abomonation;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* Storage.
|
* Storage.
|
||||||
|
@ -171,3 +174,18 @@ unsafe impl<N: Scalar, R: DimName> OwnedStorage<N, R, Dynamic> for MatrixVec<N,
|
||||||
&mut self.data[..]
|
&mut self.data[..]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "abomonation-serialize")]
|
||||||
|
impl<N: Abomonation, R: Dim, C: Dim> Abomonation for MatrixVec<N, R, C> {
|
||||||
|
unsafe fn entomb(&self, writer: &mut Vec<u8>) {
|
||||||
|
self.data.entomb(writer)
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn embalm(&mut self) {
|
||||||
|
self.data.embalm()
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn exhume<'a, 'b>(&'a mut self, bytes: &'b mut [u8]) -> Option<&'b mut [u8]> {
|
||||||
|
self.data.exhume(bytes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ extern crate abomonation;
|
||||||
|
|
||||||
use rand::random;
|
use rand::random;
|
||||||
use abomonation::{Abomonation, encode, decode};
|
use abomonation::{Abomonation, encode, decode};
|
||||||
use nalgebra::{Matrix3x4, Point3};
|
use nalgebra::{DMatrix, Matrix3x4, Point3};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn abomonate_matrix3x4() {
|
fn abomonate_matrix3x4() {
|
||||||
|
@ -16,6 +16,11 @@ fn abomonate_point3() {
|
||||||
assert_encode_and_decode(&random::<Point3<f64>>());
|
assert_encode_and_decode(&random::<Point3<f64>>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn abomonate_dmatrix() {
|
||||||
|
assert_encode_and_decode(&DMatrix::<f32>::new_random(3, 5));
|
||||||
|
}
|
||||||
|
|
||||||
fn assert_encode_and_decode<T: Abomonation + PartialEq>(data: &T) {
|
fn assert_encode_and_decode<T: Abomonation + PartialEq>(data: &T) {
|
||||||
let mut bytes = Vec::new();
|
let mut bytes = Vec::new();
|
||||||
unsafe { encode(data, &mut bytes); }
|
unsafe { encode(data, &mut bytes); }
|
||||||
|
|
Loading…
Reference in New Issue