feat: add bytes

This commit is contained in:
2020-09-20 23:02:17 +08:00
parent d55b768421
commit ccc820145e
3 changed files with 56 additions and 0 deletions

24
bytes/src/main.rs Normal file
View File

@@ -0,0 +1,24 @@
use bytes::{Bytes, BytesMut, Buf, BufMut};
fn main() {
println!("Run #test_bytes()");
test_bytes();
println!("Run #test_bytes_mut()");
test_bytes_mut();
}
fn test_bytes() {
let mut buf = Bytes::from(&b"1122334455"[..]);
let v1 = buf.get_u16();
let v2 = buf.get_u16();
println!("v1: {}, v2: {}", v1, v2);
}
fn test_bytes_mut() {
let mut buf = BytesMut::with_capacity(2);
println!("[{}], len: {}", hex::encode(buf.bytes()), buf.len());
buf.put_u64(112233445566778899);
println!("[{}], len: {}", hex::encode(buf.bytes()), buf.len());
buf.put_u16(1);
println!("[{}], len: {}", hex::encode(buf.bytes()), buf.len());
}