diff --git a/protokit/Cargo.toml b/protokit/Cargo.toml index 0c80644..45cb7f8 100644 --- a/protokit/Cargo.toml +++ b/protokit/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "protokit" -version = "0.1.3" +version = "0.1.4" edition = "2021" license = "MIT" readme = "../README.MD" @@ -16,30 +16,30 @@ descriptors = ["desc/descriptors"] [dependencies.binformat] package = "protokit_binformat" path = "../protokit_binformat" -version = "0.1.3" +version = "0.1.4" [dependencies.textformat] package = "protokit_textformat" path = "../protokit_textformat" -version = "0.1.3" +version = "0.1.4" optional = true [dependencies.desc] package = "protokit_desc" path = "../protokit_desc" -version = "0.1.3" +version = "0.1.4" optional = true [dependencies.grpc] package = "protokit_grpc" path = "../protokit_grpc" -version = "0.1.3" +version = "0.1.4" optional = true [dependencies.derive] package = "protokit_derive" path = "../protokit_derive" -version = "0.1.3" +version = "0.1.4" [dependencies] anyhow = "1" diff --git a/protokit/src/lib.rs b/protokit/src/lib.rs index b2179b0..bd92fb2 100644 --- a/protokit/src/lib.rs +++ b/protokit/src/lib.rs @@ -1,11 +1,8 @@ pub use anyhow::Result; -pub use derive::{protoenum, Proto}; - pub use binformat::{self, BinProto, BytesLike, Fixed, Sigint, Varint}; - -#[cfg(feature = "textformat")] -pub use textformat::{self, TextField as _, TextProto}; - +pub use derive::{protoenum, Proto}; #[cfg(feature = "grpc")] pub use grpc; pub use indexmap::IndexMap; +#[cfg(feature = "textformat")] +pub use textformat::{self, TextField as _, TextProto}; diff --git a/protokit_binformat/Cargo.toml b/protokit_binformat/Cargo.toml index 36c361e..12b1b89 100644 --- a/protokit_binformat/Cargo.toml +++ b/protokit_binformat/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "protokit_binformat" -version = "0.1.3" +version = "0.1.4" edition = "2021" license = "MIT" readme = "../README.MD" @@ -15,7 +15,7 @@ arena = ["bumpalo", "bumpalo/boxed", "bumpalo/collections"] [dependencies.derive] package = "protokit_derive" path = "../protokit_derive" -version = "0.1.3" +version = "0.1.4" [dependencies] indexmap = "1" diff --git a/protokit_build/Cargo.toml b/protokit_build/Cargo.toml index fbc1880..b2c48a0 100644 --- a/protokit_build/Cargo.toml +++ b/protokit_build/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "protokit_build" -version = "0.1.3" +version = "0.1.4" edition = "2021" license = "MIT" readme = "../README.MD" @@ -17,15 +17,15 @@ descriptors = ["protokit_desc/descriptors"] [dependencies.protokit_binformat] path = "../protokit_binformat" -version = "0.1.3" +version = "0.1.4" [dependencies.protokit_desc] path = "../protokit_desc" -version = "0.1.3" +version = "0.1.4" [dependencies.protokit_proto] path = "../protokit_proto" -version = "0.1.3" +version = "0.1.4" default-features = false optional = true diff --git a/protokit_derive/Cargo.toml b/protokit_derive/Cargo.toml index 314aa0b..4636a09 100644 --- a/protokit_derive/Cargo.toml +++ b/protokit_derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "protokit_derive" -version = "0.1.3" +version = "0.1.4" edition = "2018" license = "MIT" readme = "../README.MD" diff --git a/protokit_desc/Cargo.toml b/protokit_desc/Cargo.toml index 25b9e54..3b4178e 100644 --- a/protokit_desc/Cargo.toml +++ b/protokit_desc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "protokit_desc" -version = "0.1.3" +version = "0.1.4" edition = "2021" license = "MIT" readme = "../README.MD" @@ -15,17 +15,17 @@ descriptors = [] [dependencies.binformat] package = "protokit_binformat" path = "../protokit_binformat" -version = "0.1.3" +version = "0.1.4" [dependencies.textformat] package = "protokit_textformat" path = "../protokit_textformat" -version = "0.1.3" +version = "0.1.4" [dependencies.derive] package = "protokit_derive" path = "../protokit_derive" -version = "0.1.3" +version = "0.1.4" [dependencies] arcstr = "1.1.4" diff --git a/protokit_desc/src/lib.rs b/protokit_desc/src/lib.rs index 24aad66..9a81c93 100644 --- a/protokit_desc/src/lib.rs +++ b/protokit_desc/src/lib.rs @@ -352,7 +352,7 @@ impl FieldDef { FieldDescriptorProtoType::TYPE_GROUP => { let mut n = desc.type_name.as_deref().unwrap(); while let Some(p) = n.find('.') { - n = &n[p + 1..] + n = &n[p + 1 ..] } name = set.cache(n); DataType::Unresolved(set.cache(desc.type_name.as_ref().unwrap()), UnresolvedHint::Group) @@ -410,7 +410,7 @@ impl FieldDef { DataType::Map(map) => { let mut name = self.name.clone().to_string(); unsafe { - name.as_bytes_mut()[..1].make_ascii_uppercase(); + name.as_bytes_mut()[.. 1].make_ascii_uppercase(); } let map_entry_name = format!("{name}Entry"); fout.type_name = Some(format!( @@ -676,10 +676,14 @@ impl ServiceDef { ) -> Self { Self { name: name.clone(), - rpc: desc.method.iter().map(|v| { - let name = set.cache(v.name.as_ref().expect("Missing service name")); - (name.clone(), RpcDef::from_descriptor(set, &name, &v)) - }).collect(), + rpc: desc + .method + .iter() + .map(|v| { + let name = set.cache(v.name.as_ref().expect("Missing service name")); + (name.clone(), RpcDef::from_descriptor(set, &name, &v)) + }) + .collect(), options: desc.options.as_deref().cloned().unwrap_or_default(), } } @@ -726,11 +730,7 @@ impl RpcDef { out } #[cfg(feature = "descriptors")] - fn from_descriptor( - set: &mut FileSetDef, - name: &ArcStr, - desc: &MethodDescriptorProto, - ) -> Self { + fn from_descriptor(set: &mut FileSetDef, name: &ArcStr, desc: &MethodDescriptorProto) -> Self { Self { name: name.clone(), req_stream: desc.client_streaming.unwrap_or_default(), @@ -1214,7 +1214,7 @@ fn try_resolve_within_scopes( let qualified = format!("{scope}{scope_dot}{symbol}"); match (names.get(qualified.as_str()), scope.rfind('.')) { (Some(v), _) => return Some(*v), - (None, Some(p)) => scope = &scope[..p], + (None, Some(p)) => scope = &scope[.. p], // Resolve globally without the prefix (None, None) => return names.get(symbol).copied(), } @@ -1230,14 +1230,14 @@ fn try_resolve_symbol( if let Some(without_dot) = symbol.strip_prefix('.') { // We're searching for global symbol. If package prefix matches, we can search for the inner part of the symbol if let Some(without_package) = without_dot.strip_prefix(file_package) { - let localized_symbol = &without_package[1..]; + let localized_symbol = &without_package[1 ..]; return names.get(localized_symbol).cloned(); } else { eprintln!("Package mismatch: {} within: {}", without_dot, &file_package); return None; } } else if let Some(localized) = symbol.strip_prefix(file_package) { - let localized_symbol = &localized[1..]; + let localized_symbol = &localized[1 ..]; return names.get(localized_symbol).cloned(); } @@ -1255,7 +1255,7 @@ fn try_resolve_symbol( ) { (Some(v), _) => return Some(v), // We need to remove subpackages, because name sections might be of nested messages, not package names - (None, Some(v)) => file_package = &file_package[..v], + (None, Some(v)) => file_package = &file_package[.. v], (None, None) => { return try_resolve_within_scopes(names, "", symbol); } diff --git a/protokit_examples/Cargo.toml b/protokit_examples/Cargo.toml index f7b83e3..851f1cf 100644 --- a/protokit_examples/Cargo.toml +++ b/protokit_examples/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "protokit_examples" -version = "0.1.3" +version = "0.1.4" edition = "2021" license = "MIT" readme = "../README.MD" @@ -13,7 +13,7 @@ publish = false [dependencies] -protokit = { path = "../protokit", version = "0.1.3", features = ["textformat", "grpc"] } +protokit = { path = "../protokit", version = "0.1.4", features = ["textformat", "grpc"] } [build-dependencies] protokit_build = { path = "../protokit_build" } diff --git a/protokit_examples/src/main.rs b/protokit_examples/src/main.rs index 7af98f0..69605ca 100644 --- a/protokit_examples/src/main.rs +++ b/protokit_examples/src/main.rs @@ -1,7 +1,7 @@ use std::io::{stdin, BufRead}; -use protokit::Proto; use protokit::textformat::reflect::Registry; +use protokit::Proto; pub mod gen { include!(concat!(env!("OUT_DIR"), "/mod.rs")); diff --git a/protokit_grpc/Cargo.toml b/protokit_grpc/Cargo.toml index a497c45..e3554a2 100644 --- a/protokit_grpc/Cargo.toml +++ b/protokit_grpc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "protokit_grpc" -version = "0.1.3" +version = "0.1.4" edition = "2021" license = "MIT" readme = "../README.MD" @@ -12,7 +12,7 @@ description = "Usable protocol buffers" [dependencies.binformat] package = "protokit_binformat" path = "../protokit_binformat" -version = "0.1.3" +version = "0.1.4" [dependencies.tonic] version = "0.9.1" diff --git a/protokit_grpc/src/lib.rs b/protokit_grpc/src/lib.rs index 5f618dc..72baa6b 100644 --- a/protokit_grpc/src/lib.rs +++ b/protokit_grpc/src/lib.rs @@ -1,7 +1,7 @@ use core::marker::PhantomData; pub use async_trait::async_trait; -use binformat::{Error, OutputStream}; +use binformat::{Error, OutputStream, SizeStack}; use bytes::Buf; pub use futures::future::LocalBoxFuture; pub use futures::stream::Stream; @@ -52,11 +52,7 @@ impl<'buf, T: binformat::BinProto<'buf>> Encoder for TonicEncoder { fn encode(&mut self, item: Self::Item, buf: &mut EncodeBuf<'_>) -> Result<(), Self::Error> { use bytes::BufMut; - - let mut tmp = OutputStream::default(); - item.encode(&mut tmp); //.expect("Message only errors if not enough space"); - buf.put_slice(&tmp.finish()); - + buf.put_slice(&binformat::encode(&item).unwrap()); Ok(()) } } diff --git a/protokit_proto/Cargo.toml b/protokit_proto/Cargo.toml index b0a2fa3..405d867 100644 --- a/protokit_proto/Cargo.toml +++ b/protokit_proto/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "protokit_proto" -version = "0.1.3" +version = "0.1.4" edition = "2021" license = "MIT" readme = "../README.MD" @@ -14,11 +14,11 @@ descriptors = ["protokit_desc/descriptors"] [dependencies.protokit_textformat] path = "../protokit_textformat" -version = "0.1.3" +version = "0.1.4" [dependencies.protokit_desc] path = "../protokit_desc" -version = "0.1.3" +version = "0.1.4" [dependencies] nom = "7.1.1" diff --git a/protokit_textformat/Cargo.toml b/protokit_textformat/Cargo.toml index e3efa77..5435985 100644 --- a/protokit_textformat/Cargo.toml +++ b/protokit_textformat/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "protokit_textformat" -version = "0.1.3" +version = "0.1.4" edition = "2021" license = "MIT" readme = "../README.MD" @@ -14,7 +14,7 @@ default = [] [dependencies.binformat] package = "protokit_binformat" path = "../protokit_binformat" -version = "0.1.3" +version = "0.1.4" [dependencies] logos = { version = "0.13.0", default-features = false, features = ["export_derive"] } diff --git a/protokit_textformat/src/lex.rs b/protokit_textformat/src/lex.rs index 93a5b7d..d07ca39 100644 --- a/protokit_textformat/src/lex.rs +++ b/protokit_textformat/src/lex.rs @@ -67,6 +67,7 @@ pub enum Token { #[cfg(test)] mod test { use logos::Lexer; + use crate::lex::Token; #[test] diff --git a/protokit_textformat/src/stream.rs b/protokit_textformat/src/stream.rs index a83d91b..3fd7441 100644 --- a/protokit_textformat/src/stream.rs +++ b/protokit_textformat/src/stream.rs @@ -81,7 +81,7 @@ impl<'buf> InputStream<'buf> { self.expect_curr(StrLit)?; while self.cur == StrLit { let buf = self.buf(); - f(&buf[1..buf.len() - 1])?; + f(&buf[1 .. buf.len() - 1])?; self.advance(); } Ok(()) @@ -91,7 +91,7 @@ impl<'buf> InputStream<'buf> { self.expect_curr(StrLit)?; while self.cur == StrLit { let buf = self.buf().as_bytes(); - f(&buf[1..buf.len() - 1])?; + f(&buf[1 .. buf.len() - 1])?; self.advance(); } Ok(()) @@ -110,7 +110,7 @@ impl<'buf> InputStream<'buf> { pub fn u64(&mut self) -> Result { let out = match self.token_and_span() { - (HexLit, h) => u64::from_str_radix(&h[2..], 16)?, + (HexLit, h) => u64::from_str_radix(&h[2 ..], 16)?, (DecLit, h) => u64::from_str_radix(h, 10)?, (OctLit, h) => u64::from_str_radix(h, 8)?, (tok, _) => return unexpected(DecLit, tok, self.lex.remainder()), @@ -121,7 +121,7 @@ impl<'buf> InputStream<'buf> { pub fn u32(&mut self) -> Result { let out = match self.token_and_span() { - (HexLit, h) => u32::from_str_radix(&h[2..], 16)?, + (HexLit, h) => u32::from_str_radix(&h[2 ..], 16)?, (DecLit, h) => u32::from_str_radix(h, 10)?, (OctLit, h) => u32::from_str_radix(h, 8)?, (tok, _) => return unexpected(DecLit, tok, self.lex.remainder()), @@ -148,18 +148,18 @@ impl<'buf> InputStream<'buf> { let neg = if self.try_consume(Minus) { -1.0 } else { 1.0 }; let res = neg * match self.token_and_span() { - (FltLit | DecLit, s) => f64::from_str(s).unwrap(), - (Ident, txt) => { - if txt.eq_ignore_ascii_case("infinity") | txt.eq_ignore_ascii_case("inf") { - f64::INFINITY - } else if txt.eq_ignore_ascii_case("nan") { - f64::NAN - } else { - return unknown(txt); + (FltLit | DecLit, s) => f64::from_str(s).unwrap(), + (Ident, txt) => { + if txt.eq_ignore_ascii_case("infinity") | txt.eq_ignore_ascii_case("inf") { + f64::INFINITY + } else if txt.eq_ignore_ascii_case("nan") { + f64::NAN + } else { + return unknown(txt); + } } - } - (k, _) => return unexpected(FltLit, k, self.lex.remainder()), - }; + (k, _) => return unexpected(FltLit, k, self.lex.remainder()), + }; self.advance(); Ok(res) @@ -234,7 +234,7 @@ impl<'r> OutputStream<'r> { pub fn ln(&mut self) { self.buf.push('\n'); - for _ in 0..self.pad { + for _ in 0 .. self.pad { self.buf.push(' '); } } diff --git a/tools/conformance/Cargo.toml b/tools/conformance/Cargo.toml index 3d9340f..bd83649 100644 --- a/tools/conformance/Cargo.toml +++ b/tools/conformance/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "conformance" -version = "0.1.3" +version = "0.1.4" edition = "2021" license = "MIT" readme = "../README.MD" @@ -19,5 +19,5 @@ byteorder = "1.4.3" protokit = { path = "../../protokit", features = ["textformat"] } [build-dependencies] -protokit_build = { path = "../../protokit_build", version = "0.1.3", features = ["protoc"] } +protokit_build = { path = "../../protokit_build", version = "0.1.4", features = ["protoc"] }