re-structure blob, structured serialization

This commit is contained in:
Gregory Terzian 2019-09-01 03:18:42 +08:00
parent 7aa68c8fe7
commit 6e8a85482c
31 changed files with 997 additions and 489 deletions

View file

@ -170,6 +170,13 @@ impl PipelineNamespace {
index: MessagePortRouterIndex(self.next_index()),
}
}
fn next_blob_id(&mut self) -> BlobId {
BlobId {
namespace_id: self.id,
index: BlobIndex(self.next_index()),
}
}
}
thread_local!(pub static PIPELINE_NAMESPACE: Cell<Option<PipelineNamespace>> = Cell::new(None));
@ -373,6 +380,37 @@ impl fmt::Display for MessagePortRouterId {
}
}
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub struct BlobIndex(pub NonZeroU32);
malloc_size_of_is_0!(BlobIndex);
#[derive(
Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, Ord, PartialEq, PartialOrd, Serialize,
)]
pub struct BlobId {
pub namespace_id: PipelineNamespaceId,
pub index: BlobIndex,
}
impl BlobId {
pub fn new() -> BlobId {
PIPELINE_NAMESPACE.with(|tls| {
let mut namespace = tls.get().expect("No namespace set for this thread!");
let next_blob_id = namespace.next_blob_id();
tls.set(Some(namespace));
next_blob_id
})
}
}
impl fmt::Display for BlobId {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let PipelineNamespaceId(namespace_id) = self.namespace_id;
let BlobIndex(index) = self.index;
write!(fmt, "({},{})", namespace_id, index.get())
}
}
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub struct HistoryStateIndex(pub NonZeroU32);
malloc_size_of_is_0!(HistoryStateIndex);