GithubHelp home page GithubHelp logo

speak2erase / alox-48 Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 1.0 239 KB

Serde powered Ruby Marshal (de)serializing library

License: GNU General Public License v3.0

Rust 100.00%
serde binary-format marshal ruby rust serialization

alox-48's Introduction

alox-48

alox-48 (short for aluminum oxide 48) is a crate for deserializing (soon serializing as well) Ruby's Marshal data format, using serde. It requires rust nightly as of 2/8/23 for min-specialization.

alox-48 intends to provide almost perfect round-trip deserialization, with some exceptions:

  • Object links are not preserved. Object links are a way for Ruby to compact data in Marshal. They rely heavily on Ruby having a GC and thus do not map well to Rust.
  • Classes and Modules are unsupported.
  • Bignum is unsupported.

Why min-specialization

alox-48 uses min-specialization to extend serde in order to preserve types that may be lost in deserialization. There are a lot of data types in Marshal that do not map well to serde's data model, or rust's data model.

This includes:

  • Symbols
  • Userdata
  • Objects
  • Strings with non-utf8 encoding

It does this via the VistorExt trait:

pub trait VisitorExt<'de>: Visitor<'de> {
    fn visit_userdata<E>(self, class: &'de str, data: &'de [u8]) -> Result<Self::Value, E>
    where
        E: SerdeError;

    fn visit_object<A>(self, class: &'de str, fields: A) -> Result<Self::Value, A::Error>
    where
        A: MapAccess<'de>;

    fn visit_symbol<E>(self, sym: &'de str) -> Result<Self::Value, E>
    where
        E: SerdeError;

    fn visit_ruby_string<A>(self, str: &'de [u8], fields: A) -> Result<Self::Value, A::Error>
    where
        A: MapAccess<'de>;
}

You are free to implement this trait on any of your types. It'll only work with the deserializer from this crate, though.

Value

alox-48 provides a Value enum to work with untyped data.

pub enum Value {
    Nil,
    Bool(bool),
    Float(f64),
    Integer(i64),
    String(RbString),
    Symbol(Symbol),
    Array(RbArray),
    Hash(RbHash),
    Userdata(Userdata),
    Object(Object),
}

Value relies heavily on VistorExt to make sure types stay the same and data is not lost in deserialization.

alox-48's People

Contributors

speak2erase avatar white-axe avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

white-axe

alox-48's Issues

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.