From ccc820145ed2dd8687782c78d79357a3178629cd Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 20 Sep 2020 23:02:17 +0800 Subject: [PATCH] feat: add bytes --- bytes/Cargo.lock | 21 +++++++++++++++++++++ bytes/Cargo.toml | 11 +++++++++++ bytes/src/main.rs | 24 ++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 bytes/Cargo.lock create mode 100644 bytes/Cargo.toml create mode 100644 bytes/src/main.rs diff --git a/bytes/Cargo.lock b/bytes/Cargo.lock new file mode 100644 index 0000000..9b5a85c --- /dev/null +++ b/bytes/Cargo.lock @@ -0,0 +1,21 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "bytes" +version = "0.1.0" +dependencies = [ + "bytes 0.5.6", + "hex", +] + +[[package]] +name = "bytes" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" + +[[package]] +name = "hex" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" diff --git a/bytes/Cargo.toml b/bytes/Cargo.toml new file mode 100644 index 0000000..678784e --- /dev/null +++ b/bytes/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "bytes" +version = "0.1.0" +authors = ["Hatter Jiang "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +bytes = "0.5.6" +hex = "0.4.2" diff --git a/bytes/src/main.rs b/bytes/src/main.rs new file mode 100644 index 0000000..8bda0f4 --- /dev/null +++ b/bytes/src/main.rs @@ -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()); +}