paritytech/content

Name: content

Owner: Parity Technologies

Description: Content trait for storable types

Created: 2016-11-07 15:42:50.0

Updated: 2016-11-07 16:59:06.0

Pushed: 2016-12-16 18:40:54.0

Homepage: null

Size: 36

Language: Rust

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Content

Design goal of the Content storage/serialization backend.

Simple implementation of Content trait for any type

When implementing Content for your type, you need to provide only two methods, to_content that takes a Read, and produces a Self, and from_content, an example for u8:

 Content for u8 {
fn to_content(&self, sink: &mut Sink) -> Result<()> {
    sink.write_all(&[*self])
}
fn from_content(source: &mut Source) -> Result<Self> {
    let b = &mut [0u8];
    try!(source.read_exact(b));
    Ok(b[0])
}

The Backend trait

The backend trait makes a type act as as storage for content addressed bytestreams, be it Vec<u8> or File. But it could also be a network interface, for example.

The type is the schema

Things that implement Content, implicitly know how to serialize and deserialize themselves, including knowing their length. And since types can nest other Content types within themselves, you basically get the whole schema and de/serialization for free.

Zero copy io

When a Content is put into a store, Reads and Writes are connected directly.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.