2 个版本
使用旧的 Rust 2015
0.1.4 | 2018年7月31日 |
---|---|
0.1.3 | 2018年7月29日 |
排名第1508位,在开发工具类别中
每月下载量38次
80KB
1.5K SLoC
cluLamansh
使用 Lamansh 协议存储在数组中的值的二进制记录。
Lamansh 协议
let lamansh = new_custom_lamansh::<U8, U64>( // PROTOCOL SIZED U8 - 255 elements, U64 - 64 sized value len
&[/* 2 bin value, [1, 1, 1,] and [23, 55] */
1u8, /* count len_header, 8 bit */
0u8,0u8,0u8,0u8,0u8,0u8,0u8,3u8, /* count len value, 64 bit */
0u8,0u8,0u8,0u8,0u8,0u8,0u8,2u8,
1u8,1u8,1u8, /* value, max 64 bit value */
23u8,55u8
]
).unwrap();
使用
extern crate cluLamansh;
use cluLamansh::new_custom_lamansh;
use cluLamansh::lamansh::build::ToLamansh;
use cluLamansh::lamansh::sized::U64;
use cluLamansh::lamansh::sized::U8;
type CountElements = U8;
type ValueLenElements = U64;
pub fn main() {
let array = &[
&b"TEST"[..],
&b""[..],
&b"my_test"[..],
].to_lamansh::<CountElements, ValueLenElements>().unwrap();
let lamash = new_custom_lamansh::<CountElements, ValueLenElements>(array).unwrap();
let mut iter = lamash.iter();
assert_eq!(iter.next(), Some( Result::Ok( &b"TEST"[..] ) ));
assert_eq!(iter.next(), Some( Result::Ok( &b""[..] ) ));
assert_eq!(iter.next(), Some( Result::Ok( &b"my_test"[..] ) ));
assert_eq!(iter.next(), None);
}
使用缓冲区
消除缓冲区重新分配。
extern crate cluLamansh;
use cluLamansh::new_custom_lamansh;
use cluLamansh::lamansh::build::ToLamansh;
use cluLamansh::lamansh::sized::U64;
use cluLamansh::lamansh::sized::U8;
use cluLamansh::lamansh::buffer::LamanshBuffer;
type CountElements = U8;
type ValueLenElements = U64;
pub fn main() {
let mut buffer = LamanshBuffer::new();
for a in 99 .. 120 {
let string_a = a.to_string();
&[
&b"TEST"[..],
&b"TEST45"[..],
&b"TEST2"[..],
&b"TEST3"[..],
&b""[..],
string_a.as_bytes(),
].update_buffer::<CountElements, ValueLenElements>(&mut buffer).unwrap();
let lamash = new_custom_lamansh::<CountElements, ValueLenElements>(&mut buffer).unwrap();
let mut iter = lamash.iter();
assert_eq!(iter.next(), Some( Result::Ok( &b"TEST"[..] ) ));
assert_eq!(iter.next(), Some( Result::Ok( &b"TEST45"[..] ) ));
assert_eq!(iter.next(), Some( Result::Ok( &b"TEST2"[..] ) ));
assert_eq!(iter.next(), Some( Result::Ok( &b"TEST3"[..] ) ));
assert_eq!(iter.next(), Some( Result::Ok( &b""[..] ) ));
assert_eq!(iter.next(), Some( Result::Ok( string_a.as_bytes() ) ));
assert_eq!(iter.next(), None);
}
}
许可证
版权所有 2018 #UlinProject Денис Котляров
许可协议:Apache License, Version 2.0
依赖项
~120KB