use bytes::{Bytes, BytesMut}; use tokio_hglib::codec::{BlockEncoder, BlockMessage}; use tokio_util::codec::Encoder; #[test] fn encode_message() { assert_eq!( Bytes::from(b"getencoding\n".as_ref()), encode_one(BlockMessage::Command(Bytes::from(b"getencoding".as_ref()))) ); assert_eq!( Bytes::from(b"\0\0\0\x03foo".as_ref()), encode_one(BlockMessage::Data(Bytes::from(b"foo".as_ref()))) ); } fn encode_one(msg: BlockMessage) -> BytesMut { let mut codec = BlockEncoder::new(); let mut buf = BytesMut::new(); codec.encode(msg, &mut buf).unwrap(); buf }