mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-13 06:29:25 +00:00
read for R: Read
write for W: Write
serialize for -> Vec<u8>
Also uses std::io::{self, Read, Write} consistently.
17 lines
425 B
Rust
17 lines
425 B
Rust
use std::io::{self, Write};
|
|
|
|
const VARINT_CONTINUATION_MASK: u8 = 0b1000_0000;
|
|
pub(crate) fn write_varint<W: Write>(varint: &u64, w: &mut W) -> io::Result<()> {
|
|
let mut varint = *varint;
|
|
while {
|
|
let mut b = u8::try_from(varint & u64::from(!VARINT_CONTINUATION_MASK)).unwrap();
|
|
varint >>= 7;
|
|
if varint != 0 {
|
|
b |= VARINT_CONTINUATION_MASK;
|
|
}
|
|
w.write_all(&[b])?;
|
|
varint != 0
|
|
} {}
|
|
Ok(())
|
|
}
|