Merge pull request #425 from sigp/ssz-v0.8

Changes for publishing ssz to crates.io
This commit is contained in:
Paul Hauner 2019-07-11 09:22:07 +10:00 committed by GitHub
commit 08868a6e7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 26 deletions

View File

@ -4,6 +4,7 @@ version = "0.1.0"
authors = ["Paul Hauner <paul@sigmaprime.io>"]
edition = "2018"
description = "SimpleSerialize (SSZ) as used in Ethereum 2.0"
license = "Apache-2.0"
[lib]
name = "ssz"
@ -14,12 +15,10 @@ harness = false
[dev-dependencies]
criterion = "0.2"
eth2_ssz_derive = { path = "../ssz_derive" }
eth2_ssz_derive = "0.1.0"
[dependencies]
bytes = "0.4.9"
ethereum-types = "0.5"
hashing = { path = "../hashing" }
int_to_bytes = { path = "../int_to_bytes" }
hex = "0.3"
yaml-rust = "0.4"

View File

@ -4,6 +4,7 @@ version = "0.1.0"
authors = ["Paul Hauner <paul@sigmaprime.io>"]
edition = "2018"
description = "Procedural derive macros to accompany the eth2_ssz crate."
license = "Apache-2.0"
[lib]
name = "ssz_derive"
@ -12,4 +13,3 @@ proc-macro = true
[dependencies]
syn = "0.15"
quote = "0.6"
eth2_ssz = { path = "../ssz" }

View File

@ -1,4 +1,7 @@
#![recursion_limit = "128"]
//! Provides procedural derive macros for the `Encode` and `Decode` traits of the `eth2_ssz` crate.
//!
//! Supports field attributes, see each derive macro for more information.
extern crate proc_macro;
@ -61,6 +64,10 @@ fn should_skip_serializing(field: &syn::Field) -> bool {
/// Implements `ssz::Encode` for some `struct`.
///
/// Fields are encoded in the order they are defined.
///
/// ## Field attributes
///
/// - `#[ssz(skip_serializing)]`: the field will not be serialized.
#[proc_macro_derive(Encode, attributes(ssz))]
pub fn ssz_encode_derive(input: TokenStream) -> TokenStream {
let item = parse_macro_input!(input as DeriveInput);
@ -132,6 +139,12 @@ fn should_skip_deserializing(field: &syn::Field) -> bool {
/// Implements `ssz::Decode` for some `struct`.
///
/// Fields are decoded in the order they are defined.
///
/// ## Field attributes
///
/// - `#[ssz(skip_deserializing)]`: during de-serialization the field will be instantiated from a
/// `Default` implementation. The decoder will assume that the field was not serialized at all
/// (e.g., if it has been serialized, an error will be raised instead of `Default` overriding it).
#[proc_macro_derive(Decode)]
pub fn ssz_decode_derive(input: TokenStream) -> TokenStream {
let item = parse_macro_input!(input as DeriveInput);

View File

@ -1,22 +0,0 @@
use ssz::Encode;
use ssz_derive::Encode;
#[derive(Debug, PartialEq, Encode)]
pub struct Foo {
a: u16,
b: Vec<u8>,
c: u16,
}
#[test]
fn encode() {
let foo = Foo {
a: 42,
b: vec![0, 1, 2, 3],
c: 11,
};
let bytes = vec![42, 0, 8, 0, 0, 0, 11, 0, 0, 1, 2, 3];
assert_eq!(foo.as_ssz_bytes(), bytes);
}