Git Product home page Git Product logo

xdr-rs-serialize's Introduction

XDR RS Serialize

CircleCI

Xdr-rs-serialize is a library for facilitating the (de)serialization of rust objects into the XDR format.

Installation

This library can be added to your project by using cargo to install the xdr-rs-serialize crate.

cargo add xdr-rs-serialize

Usage

use xdr_rs_serialize::de::XDRIn;
use xdr_rs_serialize::error::Error;
use xdr_rs_serialize::ser::XDROut;

fn main() -> Result<(), Error> {
    let mut byte_buffer = Vec::new();
    "Hello world!".to_string().write_xdr(&mut byte_buffer)?;
    // Notice that a tuple is returned with the String result at index 0 and
    // total bytes read at index 1.
    let hello_world: String = String::read_xdr(&mut &byte_buffer)?.0;
    println!("{}", hello_world);
    Ok(())
}

For a more complex example see the code under example/

Notes

  • The XDR Quad type is currently not supported

xdr-rs-serialize's People

Contributors

kbartush avatar mazzaroth-dev avatar fracek avatar jeff1010322 avatar cdemole avatar lightyear15 avatar

Stargazers

Noel Jacob avatar  avatar  avatar GAURAV avatar  avatar

Watchers

James Cloos avatar Joseph Crosland avatar  avatar Juan Miguel Mora avatar Ethan M Lewis avatar  avatar Simon Cheng avatar

Forkers

fracek bjorn

xdr-rs-serialize's Issues

Discriminated union arms value

Describe the feature

I need to serialize/deserialize a discriminated union where the arms discriminant are not an increasing sequence:

enum FooType
{
   A = 1,
   B = 10,
   C = 100
};

union Foo (FooType code)
{
case A:
  void;
case B:
  void;
case C:
  void;
default:
  void;
};

In Rust I have the following types:

#[derive(PartialEq, Clone, Debug, XDROut, XDRIn)]
pub enum FooType {
    A = 1,
    B = 10,
    C = 100,
}


#[derive(PartialEq, Clone, Debug, XDROut, XDRIn)]
pub enum Foo {
    A(), // Discriminant: 1
    B(), // Discriminant: 10
    C(), // Discriminant: 100
    D(), // Discriminant: any
}

Is there a way already to specify the discriminant? If not, would you accept a PR to add an attribute for this?

#[derive(PartialEq, Clone, Debug, XDROut, XDRIn)]
pub enum Foo {
    #[discriminant(value = FooType::A)]
    A(), // Discriminant: 1
    #[discriminant(value = FooType::B)]
    B(), // Discriminant: 10
    #[discriminant(value = FooType::C)]
    C(), // Discriminant: 100
    // No attribute, consider as default and use 0?
    D(), // Discriminant: any
}

Optional data support

Describe the feature

The standard supports optional types, I think this can be added by adding an implementation of the relevant traits for Option<T>.

I can work on a PR for this.

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.