From 1836b3ebb91173a90fdbf052064e3ef26b608aef Mon Sep 17 00:00:00 2001 From: sergeych Date: Sun, 17 Dec 2023 01:17:28 +0300 Subject: [PATCH] cleanups and typos --- README.md | 12 ++++++------ src/bipack_sink.rs | 2 +- src/bipack_source.rs | 6 +++--- src/crc.rs | 8 ++++---- src/de.rs | 8 ++++---- src/fixint.rs | 2 +- src/lib.rs | 14 +++++++------- src/ser.rs | 8 ++++---- 8 files changed, 30 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index a335a9b..249cfd8 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # bipack_ru: Rust Bipack implementation -Bipack serialization format is a compact binary format that was created as areplacement 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) +Bipack serialization format is a compact binary format that was created as a replacement for a +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`. @@ -46,9 +46,9 @@ pub struct DefinitelyBigEndian { ## Fixed or variable length arrays? -When encoding arrays, the rule is simple: +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) diff --git a/src/bipack_sink.rs b/src/bipack_sink.rs index c91611c..3c01702 100644 --- a/src/bipack_sink.rs +++ b/src/bipack_sink.rs @@ -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)?; diff --git a/src/bipack_source.rs b/src/bipack_source.rs index f946599..150c5f8 100644 --- a/src/bipack_source.rs +++ b/src/bipack_source.rs @@ -19,7 +19,7 @@ use crate::bipack_source::BipackError::NoDataError; /// Result of error-aware bipack function pub type Result = std::result::Result; -/// 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 { diff --git a/src/crc.rs b/src/crc.rs index 8103669..75df332 100644 --- a/src/crc.rs +++ b/src/crc.rs @@ -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; } diff --git a/src/de.rs b/src/de.rs index d02a7de..85460eb 100644 --- a/src/de.rs +++ b/src/de.rs @@ -161,7 +161,7 @@ impl<'de, 'a, T: BipackSource> de::Deserializer<'de> for &'a mut Deserializer } } -impl<'de, 'a, T: BipackSource> serde::de::EnumAccess<'de> for &'a mut Deserializer { +impl<'de, 'a, T: BipackSource> de::EnumAccess<'de> for &'a mut Deserializer { 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 { +impl<'de, 'a, T: BipackSource> de::VariantAccess<'de> for &'a mut Deserializer { type Error = BipackError; #[inline] @@ -213,7 +213,7 @@ impl<'a, T: BipackSource> SimpleSeq<'a, T> { fn new(de: &'a mut Deserializer, 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); diff --git a/src/fixint.rs b/src/fixint.rs index 451b2b7..33d6e4b 100644 --- a/src/fixint.rs +++ b/src/fixint.rs @@ -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 diff --git a/src/lib.rs b/src/lib.rs index 9af98a7..1e83e31 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 diff --git a/src/ser.rs b/src/ser.rs index 1a637cd..57a9c27 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -19,7 +19,7 @@ pub fn to_bytes(value: &T) -> Result> } 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);