trying to raise an error
This commit is contained in:
parent
8b01e6ac0b
commit
9c7913ac9e
|
@ -1,5 +1,5 @@
|
|||
// Support erasure coding
|
||||
use packet::{BlobRecycler, SharedBlob, BLOB_HEADER_SIZE, BLOB_SIZE};
|
||||
use packet::{BlobRecycler, SharedBlob, BLOB_DATA_SIZE, BLOB_HEADER_SIZE};
|
||||
use std::cmp;
|
||||
use std::mem;
|
||||
use std::result;
|
||||
|
|
|
@ -57,7 +57,7 @@ pub fn reconstruct_entries_from_blobs(blobs: VecDeque<SharedBlob>) -> bincode::R
|
|||
for blob in blobs {
|
||||
let entry = {
|
||||
let msg = blob.read().unwrap();
|
||||
let msg_size = msg.get_size().unwrap();
|
||||
let msg_size = msg.get_size();
|
||||
deserialize(&msg.data()[..msg_size])
|
||||
};
|
||||
|
||||
|
@ -200,7 +200,6 @@ mod tests {
|
|||
let mut transactions = vec![tx0; 362];
|
||||
transactions.extend(vec![tx1; 100]);
|
||||
let entries = next_entries(&zero, 0, transactions);
|
||||
eprintln!("entries.len() {}", entries.len());
|
||||
let blob_recycler = BlobRecycler::default();
|
||||
let mut blob_q = VecDeque::new();
|
||||
entries.to_blobs(&blob_recycler, &mut blob_q);
|
||||
|
|
|
@ -139,6 +139,12 @@ impl Default for Blob {
|
|||
}
|
||||
}
|
||||
|
||||
//#[derive(Debug)]
|
||||
//pub enum BlobError {
|
||||
// /// the Blob's meta and data are not self-consistent
|
||||
// BadState,
|
||||
//}
|
||||
|
||||
pub struct Recycler<T> {
|
||||
gc: Arc<Mutex<Vec<Arc<RwLock<T>>>>>,
|
||||
}
|
||||
|
@ -373,18 +379,32 @@ impl Blob {
|
|||
pub fn data_mut(&mut self) -> &mut [u8] {
|
||||
&mut self.data[BLOB_HEADER_SIZE..]
|
||||
}
|
||||
pub fn get_size(&self) -> Result<usize> {
|
||||
let size = self.get_data_size()? as usize;
|
||||
assert_eq!(self.meta.size, size);
|
||||
// TODO: return an error instead of panicking
|
||||
Ok(size)
|
||||
pub fn get_size(&self) -> usize {
|
||||
let size = self.get_data_size().unwrap() as usize;
|
||||
|
||||
if self.meta.size == size {
|
||||
size - BLOB_HEADER_SIZE
|
||||
} else {
|
||||
0
|
||||
}
|
||||
|
||||
// TODO: return a Result<usize> instead of
|
||||
// returning zero
|
||||
//
|
||||
//let size = self.get_data_size()? as usize;
|
||||
//if self.meta.size == size {
|
||||
// Ok(size - BLOB_HEADER_SIZE)
|
||||
//} else {
|
||||
// // these don't work...
|
||||
// Err("bad state")
|
||||
// // Err(BlobError::BadState)
|
||||
//}
|
||||
}
|
||||
pub fn set_size(&mut self, size: usize) {
|
||||
let new_size = size + BLOB_HEADER_SIZE;
|
||||
self.meta.size = new_size;
|
||||
self.set_data_size(new_size as u64).unwrap();
|
||||
}
|
||||
|
||||
pub fn recv_from(re: &BlobRecycler, socket: &UdpSocket) -> Result<SharedBlobs> {
|
||||
let mut v = VecDeque::new();
|
||||
//DOCUMENTED SIDE-EFFECT
|
||||
|
|
Loading…
Reference in New Issue