cleanups and typos

This commit is contained in:
Sergey Chernov 2023-12-17 01:17:28 +03:00
parent 94c91e788e
commit 1836b3ebb9
8 changed files with 30 additions and 30 deletions

View File

@ -1,8 +1,8 @@
# bipack_ru: Rust Bipack implementation
Bipack serialization format is a compact binary format that was created as a replacement for a
BOSS format, mode compact, faster, and not revealing inner data structure as much as possible.
It is used in our next generation data protection systems, in DiWAN products as a base format and also in my newe communication package like [kiloparsec](https://gitea.sergeych.net/sergeych/kiloparsec)
BOSS format, more compact, faster, and not revealing inner data structure as much as possible.
It is used in our next generation data protection systems, in DiWAN products as a base format and also in my new communication package like [kiloparsec](https://gitea.sergeych.net/sergeych/kiloparsec)
(and in underlying [crypto2](https://gitea.sergeych.net/sergeych/crypto2)) which are intended
to replace older `Parsec` protocols family to cope with modern crazy world challenges.
@ -29,7 +29,7 @@ fn test() -> Result<(),Error> {
serde module supports all Rust formats except floats/doubles which are not yet used and
standardised by bipack format.
standardized by bipack format.
- All integers, signed and unsigned, are encoded with variable-length `smartint`.
@ -48,7 +48,7 @@ pub struct DefinitelyBigEndian {
When encoding arrays, the rule is simple:
- dynamic arrays (arrays, vectors, etc) are encoding with size, as variable-length
- dynamic arrays (arrays, vectors, etc.) are encoded with size, as variable-length
- fixed-size arrays, like tuples `(1,2,3,4,5)`, or something like `[u32; 5]` are encoded as fixed-size entities.
# Direct usage (no serde)

View File

@ -112,7 +112,7 @@ pub trait BipackSink {
let value = number.into_u64();
let mut encode_seq = |ty: u8, bytes: &[u64]| -> Result<()> {
if bytes.len() == 0 { self.put_u8(0)?; } else {
if bytes[0] as u64 > V0LIMIT { panic!("first byte is too big (internal error)"); }
if bytes[0] > V0LIMIT { panic!("first byte is too big (internal error)"); }
self.put_u8((ty & 0x03) | ((bytes[0] as u8) << 2))?;
for i in 1..bytes.len() {
self.put_u8(bytes[i] as u8)?;

View File

@ -19,7 +19,7 @@ use crate::bipack_source::BipackError::NoDataError;
/// Result of error-aware bipack function
pub type Result<T> = std::result::Result<T, BipackError>;
/// There is not enought data to fulfill the request
/// There is not enough data to fulfill the request
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum BipackError {
@ -49,7 +49,7 @@ impl Display for BipackError {
/// it is easy to implements your own.
///
/// To implement source for other type, implement just [BipackSource::get_u8],
/// [BipackSource::eof] or mayve also
/// [BipackSource::eof] or maybe also
/// [BipackSource::get_fixed_bytes] for effectiveness.
///
/// Unlike the [crate::bipack_sink::BipackSink] the source is returning errors. This is because
@ -86,7 +86,7 @@ pub trait BipackSource {
Ok(self.get_u8()? as i8)
}
/// Unpack variable-length packed unsigned value, used aslo internally to store size
/// Unpack variable-length packed unsigned value, used also internally to store size
/// of arrays, binary data, strings, etc. To pack use
/// [crate::bipack_sink::BipackSink::put_unsigned()].
fn get_unsigned(self: &mut Self) -> Result<u64> {

View File

@ -16,12 +16,12 @@ impl Crc8 {
t = (t << 1) ^ tmp;
for j in 0..i {
idx = (i+j) as u8;
table[(idx) as usize] = table[j as usize] ^ t;
table[idx as usize] = table[j as usize] ^ t;
}
i *= 2;
}
return Crc8{ table : table};
return Crc8{ table };
}
pub fn create_lsb(polynomial :u8) -> Crc8 {
@ -44,7 +44,7 @@ impl Crc8 {
i >>= 1;
}
return Crc8{ table : table };
return Crc8{ table };
}
/// Update CRC using previously calculated value and return new one.
@ -52,7 +52,7 @@ impl Crc8 {
let mut crc_tmp = crc;
for i in 0..buffer.len() {
crc_tmp = self.table[((crc_tmp ^ buffer[i])) as usize];
crc_tmp = self.table[(crc_tmp ^ buffer[i]) as usize];
}
return crc_tmp;
}

View File

@ -161,7 +161,7 @@ impl<'de, 'a, T: BipackSource> de::Deserializer<'de> for &'a mut Deserializer<T>
}
}
impl<'de, 'a, T: BipackSource> serde::de::EnumAccess<'de> for &'a mut Deserializer<T> {
impl<'de, 'a, T: BipackSource> de::EnumAccess<'de> for &'a mut Deserializer<T> {
type Error = BipackError;
type Variant = Self;
@ -175,7 +175,7 @@ impl<'de, 'a, T: BipackSource> serde::de::EnumAccess<'de> for &'a mut Deserializ
}
}
impl<'de, 'a, T: BipackSource> serde::de::VariantAccess<'de> for &'a mut Deserializer<T> {
impl<'de, 'a, T: BipackSource> de::VariantAccess<'de> for &'a mut Deserializer<T> {
type Error = BipackError;
#[inline]
@ -213,7 +213,7 @@ impl<'a, T: BipackSource> SimpleSeq<'a, T> {
fn new(de: &'a mut Deserializer<T>, size: usize) -> Self {
SimpleSeq {
de,
size: size,
size,
}
}
}
@ -318,7 +318,7 @@ mod tests {
#[test]
fn test_map() -> Result<()> {
let mut src = HashMap::new();
src.insert("foo".to_string(), 1);
// src.insert("foo".to_string(), 1);
src.insert("foo".to_string(), 42);
src.insert("bar".to_string(), 1);
src.insert("baz".to_string(), 17);

View File

@ -1,7 +1,7 @@
//! # Fixed Size Integers
//!
//! In some cases, the use of variably length encoded data may not be
//! preferrable. These modules, for use with `#[serde(with = ...)]`
//! preferable. These modules, for use with `#[serde(with = ...)]`
//! "opt out" of variable length encoding.
//!
//! Support explicitly not provided for `usize` or `isize`, as

View File

@ -28,24 +28,24 @@
//!
//! ## Utilities
//!
//! - to siplify encoding of unsigned ints the [bipack_sink::IntoU64] trait is used with
//! imlementation for usual u* types.
//! - to simplify encoding of unsigned ints the [bipack_sink::IntoU64] trait is used with
//! implementation for usual u* types.
//!
//! - [tools::to_dump] utility function converts binary data into human-readable dump as in old goot
//! - [tools::to_dump] utility function converts binary data into human-readable dump as in old good
//! times (address, bytes, ASCII characters).
//!
//! - [tools::StringBuilder] minimalistic growing strings builder.
//!
//! ## About Bipack format
//!
//! This is a binary format created wround the idea of bit-effectiveness and not disclosing
//! inner data structure. Unlike many known binary and text formats, liek JSON, BSON, BOSS, and
//! This is a binary format created around the idea of bit-effectiveness and not disclosing
//! inner data structure. Unlike many known binary and text formats, like JSON, BSON, BOSS, and
//! many others, it does not includes field names into packed binaries.
//!
//! It also uses ratinally packed variable length format very effective for unsigned integers of
//! It also uses rationally-packed variable length format very effective for unsigned integers of
//! various sizes. This implementation supports sizes for u8, u16, u32 and u64. It is capable of
//! holding longer values too but for big numbers the fixed size encoding is mostly more effective.
//! This rarional encoding format is called `smartint` and is internally used everywhere when one
//! This rational encoding format is called `smartint` and is internally used everywhere when one
//! need to pack unsigned number, unless the fixed size is important.
//!
//! ### Varint encoding

View File

@ -19,7 +19,7 @@ pub fn to_bytes<T>(value: &T) -> Result<Vec<u8>>
}
pub fn to_buffer<'a, T: Serialize>(value: &T, buffer: & 'a mut [u8]) -> Result<& 'a [u8]> {
let mut serializer = Serializer { output: BufferSink { buffer: buffer, pos: 0}};
let mut serializer = Serializer { output: BufferSink { buffer, pos: 0}};
value.serialize(&mut serializer)?;
Ok(serializer.output.result_slice())
}
@ -360,7 +360,7 @@ mod test {
use crate::tools::{to_dump, to_hex};
#[test]
fn test_struct() -> std::result::Result<(), BipackError> {
fn test_struct() -> Result<(), BipackError> {
#[derive(Serialize)]
struct Test {
int: u32,
@ -384,7 +384,7 @@ mod test {
}
#[test]
fn test_enum() -> std::result::Result<(), FromUtf8Error> {
fn test_enum() -> Result<(), FromUtf8Error> {
#[derive(Serialize)]
enum E {
Unit,
@ -428,7 +428,7 @@ mod test {
#[test]
fn test_map() -> error::Result<()> {
let mut src = HashMap::new();
src.insert("foo", 1);
// src.insert("foo", 1);
src.insert("foo", 42);
src.insert("bar", 1);
src.insert("baz", 17);