Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use tokio::io::{AsyncRead, AsyncReadExt};
#[cfg(feature = "futures_async")]
use futures_util::{io::AsyncRead, io::AsyncReadExt};

/// A trait for reading VarInts from any other `Reader`.
/// A trait for reading [`VarInts`] from any other `Reader`.
///
/// It's recommended to use a buffered reader, as many small reads will happen.
pub trait VarIntReader {
Expand All @@ -19,7 +19,7 @@ pub trait VarIntReader {
/// In general, this always reads a whole varint. If the encoded varint's value is bigger
/// than the valid value range of `VI`, then the value is truncated.
///
/// On EOF, an io::Error with io::ErrorKind::UnexpectedEof is returned.
/// On EOF, an [`io::Error`] with [`io::ErrorKind::UnexpectedEof`] is returned.
fn read_varint<VI: VarInt>(&mut self) -> Result<VI>;
}

Expand All @@ -30,7 +30,7 @@ pub trait VarIntAsyncReader {
async fn read_varint_async<VI: VarInt>(&mut self) -> Result<VI>;
}

/// VarIntProcessor encapsulates the logic for decoding a VarInt byte-by-byte.
/// `VarIntProcessor` encapsulates the logic for decoding a [`VarInt`] byte-by-byte.
#[derive(Default)]
pub struct VarIntProcessor {
buf: [u8; 10],
Expand Down Expand Up @@ -114,11 +114,11 @@ impl<R: Read> VarIntReader for R {
}
}

/// A trait for reading FixedInts from any other `Reader`.
/// A trait for reading [`FixedInts`] from any other `Reader`.
pub trait FixedIntReader {
/// Read a fixed integer from a reader. How many bytes are read depends on `FI`.
///
/// On EOF, an io::Error with io::ErrorKind::UnexpectedEof is returned.
/// On EOF, an [`io::Error`] with [`io::ErrorKind::UnexpectedEof`] is returned.
fn read_fixedint<FI: FixedInt>(&mut self) -> Result<FI>;
}

Expand Down
6 changes: 3 additions & 3 deletions src/varint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub const MSB: u8 = 0b1000_0000;
/// bit using `&` (binary-and).
const DROP_MSB: u8 = 0b0111_1111;

/// How many bytes an integer uses when being encoded as a VarInt.
/// How many bytes an integer uses when being encoded as a `VarInt`.
#[inline]
fn required_encoded_space_unsigned(mut v: u64) -> usize {
if v == 0 {
Expand All @@ -21,14 +21,14 @@ fn required_encoded_space_unsigned(mut v: u64) -> usize {
logcounter
}

/// How many bytes an integer uses when being encoded as a VarInt.
/// How many bytes an integer uses when being encoded as a [`VarInt`].
#[inline]
fn required_encoded_space_signed(v: i64) -> usize {
required_encoded_space_unsigned(zigzag_encode(v))
}

/// Varint (variable length integer) encoding, as described in
/// https://developers.google.com/protocol-buffers/docs/encoding.
/// <https://developers.google.com/protocol-buffers/docs/encoding>.
///
/// Uses zigzag encoding (also described there) for signed integer representation.
pub trait VarInt: Sized + Copy {
Expand Down
2 changes: 1 addition & 1 deletion src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use tokio::io::{AsyncWrite, AsyncWriteExt};
#[cfg(feature = "futures_async")]
use futures_util::{io::AsyncWrite, io::AsyncWriteExt};

/// A trait for writing integers in VarInt encoding to any `Write` type. This packs encoding and
/// A trait for writing integers in [`VarInt`] encoding to any [`Write`] type. This packs encoding and
/// writing into one step.
pub trait VarIntWriter {
fn write_varint<VI: VarInt>(&mut self, n: VI) -> Result<usize>;
Expand Down