tor-bytes: Add initial support for the bytes crate
This commit is contained in:
parent
b679ab216c
commit
8db525dab4
|
@ -14,6 +14,7 @@ generic-array = "0.14.4"
|
||||||
crypto-mac = "0.9.1"
|
crypto-mac = "0.9.1"
|
||||||
thiserror = "1.0.20"
|
thiserror = "1.0.20"
|
||||||
signature = "1.2.2"
|
signature = "1.2.2"
|
||||||
|
bytes = "*"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
hex-literal = "0.3.1"
|
hex-literal = "0.3.1"
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
//! this is where I'm putting them.
|
//! this is where I'm putting them.
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use bytes;
|
||||||
use generic_array::GenericArray;
|
use generic_array::GenericArray;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
@ -25,6 +26,12 @@ impl Writer for Vec<u8> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Writer for bytes::BytesMut {
|
||||||
|
fn write_all(&mut self, bytes: &[u8]) {
|
||||||
|
self.extend_from_slice(bytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
impl<'a> Writeable for [u8] {
|
impl<'a> Writeable for [u8] {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::{Error, Readable, Result};
|
use crate::{Error, Readable, Result};
|
||||||
use arrayref::array_ref;
|
use arrayref::array_ref;
|
||||||
|
use bytes;
|
||||||
|
|
||||||
/// A type for reading messages from a slice of bytes.
|
/// A type for reading messages from a slice of bytes.
|
||||||
///
|
///
|
||||||
|
@ -54,6 +55,14 @@ impl<'a> Reader<'a> {
|
||||||
pub fn from_slice(slice: &'a [u8]) -> Self {
|
pub fn from_slice(slice: &'a [u8]) -> Self {
|
||||||
Reader { b: slice, off: 0 }
|
Reader { b: slice, off: 0 }
|
||||||
}
|
}
|
||||||
|
/// Construct a new Reader from a 'Bytes' object.
|
||||||
|
pub fn from_bytes(b: &'a bytes::Bytes) -> Self {
|
||||||
|
Self::from_slice(b.as_ref())
|
||||||
|
}
|
||||||
|
/// Construct a new Reader from a 'BytesMut' object
|
||||||
|
pub fn from_bytes_mut(b: &'a bytes::BytesMut) -> Self {
|
||||||
|
Self::from_slice(b.as_ref())
|
||||||
|
}
|
||||||
/// Return the total length of the slice in this reader, including
|
/// Return the total length of the slice in this reader, including
|
||||||
/// consumed bytes and remaining bytes.
|
/// consumed bytes and remaining bytes.
|
||||||
pub fn total_len(&self) -> usize {
|
pub fn total_len(&self) -> usize {
|
||||||
|
|
Loading…
Reference in New Issue