Code Monkey home page Code Monkey logo

rust-jce's Introduction

Rust-Jce

jce is a Jce encoding/decoding implementation for the Rust programing language.

Why jce?

  • Written in pure rust
  • Easy-to-use

Structs

use jce::JceStruct;
#[derive(JceStruct, PartialEq, Debug)]
struct Person {
    name: String, // tag = 0
    age: u8, // tag = 1
    #[jce(tag = "5")]
    male: bool, // tag = 5
    phone: u64, // tag = 6
    #[jce(tag = "11")]
    home: Home, // tag = 11
}

#[derive(JceStruct, PartialEq, Debug)]
struct Home {
    location: String, // tag = 0
}

fn main() {
    let person = Person {
        name: "Jack".into(),
        age: 12,
        male: true,
        phone: 1145141919810,
        home: Home {
            location: "下北泽".into()
        }
    };

    let mut b = vec![0u8; 0];
    person.encode(&mut b).unwrap();
    println!("{:?}", &*b);
    let decode = Person::decode(&*b).unwrap();

    assert_eq!(person, decode);
}

Fields

Jce Type Rust Type
BYTE i8 / u8
SHORT i16 / u16
INT i32 / u32
LONG i64 / u64
FLOAT f32
DOUBLE f64
SHORT_BYTES / LONG_BYTES Vec<u8> / Bytes / String
MAP HashMap<K, V>
LIST Vec<T>
STRUCT_START + STRUCT_END JceStruct
EMPTY None::<T>
SINGLE_LIST Vec<u8> / Bytes

rust-jce's People

Contributors

laolittle avatar

Stargazers

crayon avatar  avatar 凊弦凝绝 avatar

Watchers

 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.