rt_proto

Crates.iort_proto
lib.rsrt_proto
version0.1.7
sourcesrc
created_at2022-05-06 10:23:24.433252
updated_at2022-05-09 08:42:36.4305
descriptionrt proto for Rust
homepage
repositoryhttps://github.com/tickbh/rt_proto
max_upload_size
id581613
size51,802
问蒙框架服务 (tickbh)

documentation

README

rt_proto

tickbh rust bin protocol

suport type

base type is contain "u8", "i8", "u16", "i16", "u32", "i32", "u64", "i64", "varint", "float", "string", "raw", "map", "array"

example proto

extern crate rt_proto as rt;
use rt::{Value, Buffer};

use std::collections::{HashMap};
fn main()
{
    println!("welcome to tickdream rust protocol");

    let mut hash_value = HashMap::<Value, Value>::new();
    hash_value.insert(Value::Str("name".to_string()), Value::Str("I'm a chinese people".to_string()));
    hash_value.insert(Value::Str("sub_name".to_string()), Value::Str("tickdream".to_string()));
    hash_value.insert(Value::Str("index".to_string()), Value::U16(1 as u16));

    {
        let mut buffer = Buffer::new();
        rt::encode_proto(&mut buffer, &"cmd_test_op".to_string(), vec![Value::Map(hash_value.clone())]).unwrap();

        // just read field
        let read = rt::decode_proto(&mut buffer).unwrap();
        match read {
            (name, val) => {
                assert_eq!(name, "cmd_test_op".to_string());
                assert_eq!(val[0], Value::Map(hash_value));
                assert_eq!(val.len(), 1);
            }
        }
    }
}

it will encode Vec accords to proto name like as "cmd_test_op" define args is [map]

compatible

it will ensure data decoded maximum

  • old protocol can decode the new protocol if new protocol not change the old field info, but it will miss some info
  • new protocol can decode the old protocol all datas
Commit count: 70

cargo fmt