Git Product home page Git Product logo

speedy's Introduction

Build Status

A fast binary serialization framework

Documentation

The goal of this crate is to provide fast, simple and easy binary serialization.

Benchmarks

See serde-bench for benchmarks.

Example

#[macro_use]
extern crate speedy_derive;
extern crate speedy;

use std::borrow::Cow;
use speedy::{Readable, Writable, Endianness};

#[derive(PartialEq, Debug, Readable, Writable)]
enum Enum {
    A,
    B,
    C,
}

#[derive(PartialEq, Debug, Readable, Writable)]
struct Struct< 'a > {
    number: u64,
    string: String,
    vector: Vec< u8 >,
    cow: Cow< 'a, [i64] >,
    float: f32,
    enumeration: Enum
}

fn main() {
    let original = Struct {
        number: 0x12345678ABCDEF00,
        string: "A totally pointless string".to_owned(),
        vector: vec![ 1, 2, 3 ],
        cow: Cow::Borrowed( &[ 4, 5, 6 ] ),
        float: 3.1415,
        enumeration: Enum::C
    };

    let endian = Endianness::LittleEndian;
    let bytes = original.write_to_vec( endian ).unwrap();
    let deserialized: Struct =
        Struct::read_from_buffer( endian, &bytes ).unwrap();

    assert_eq!( original, deserialized );
}

Supported types

Out-of-box the following types are supported:

Type Serialized as
u8 as-is
u16 as-is
u32 as-is
u64 as-is
i8 as-is
i16 as-is
i32 as-is
i64 as-is
f32 as-is
f64 as-is
bool u8, either 0 or 1
String {length: u32, bytes: [u8]}
Cow<'a, str> {length: u32, bytes: [u8]}
Vec<T> {length: u32, values: [T]}
Cow<'a, [T]> {length: u32, values: [T]}
Range<T> (T, T)
Option<T> (1_u8, T) or 0_u8
() nothing
(T) as-is
(T, T) as-is
(T, .., T) as-is
enums {tag: u32, variant: T}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

speedy's People

Contributors

koute avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.