Skip to content

Commit

Permalink
Fix grpc encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
semtexzv committed Oct 4, 2023
1 parent 60d59e3 commit 33fdea7
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 72 deletions.
12 changes: 6 additions & 6 deletions protokit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "protokit"
version = "0.1.3"
version = "0.1.4"
edition = "2021"
license = "MIT"
readme = "../README.MD"
Expand All @@ -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"
Expand Down
9 changes: 3 additions & 6 deletions protokit/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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};
4 changes: 2 additions & 2 deletions protokit_binformat/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "protokit_binformat"
version = "0.1.3"
version = "0.1.4"
edition = "2021"
license = "MIT"
readme = "../README.MD"
Expand All @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions protokit_build/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "protokit_build"
version = "0.1.3"
version = "0.1.4"
edition = "2021"
license = "MIT"
readme = "../README.MD"
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion protokit_derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "protokit_derive"
version = "0.1.3"
version = "0.1.4"
edition = "2018"
license = "MIT"
readme = "../README.MD"
Expand Down
8 changes: 4 additions & 4 deletions protokit_desc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "protokit_desc"
version = "0.1.3"
version = "0.1.4"
edition = "2021"
license = "MIT"
readme = "../README.MD"
Expand All @@ -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"
Expand Down
30 changes: 15 additions & 15 deletions protokit_desc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -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(),
}
}
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
}
Expand All @@ -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();
}

Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions protokit_examples/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "protokit_examples"
version = "0.1.3"
version = "0.1.4"
edition = "2021"
license = "MIT"
readme = "../README.MD"
Expand All @@ -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" }
2 changes: 1 addition & 1 deletion protokit_examples/src/main.rs
Original file line number Diff line number Diff line change
@@ -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"));
Expand Down
4 changes: 2 additions & 2 deletions protokit_grpc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "protokit_grpc"
version = "0.1.3"
version = "0.1.4"
edition = "2021"
license = "MIT"
readme = "../README.MD"
Expand All @@ -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"
Expand Down
8 changes: 2 additions & 6 deletions protokit_grpc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -52,11 +52,7 @@ impl<'buf, T: binformat::BinProto<'buf>> Encoder for TonicEncoder<T> {

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(())
}
}
Expand Down
6 changes: 3 additions & 3 deletions protokit_proto/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "protokit_proto"
version = "0.1.3"
version = "0.1.4"
edition = "2021"
license = "MIT"
readme = "../README.MD"
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions protokit_textformat/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "protokit_textformat"
version = "0.1.3"
version = "0.1.4"
edition = "2021"
license = "MIT"
readme = "../README.MD"
Expand All @@ -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"] }
Expand Down
1 change: 1 addition & 0 deletions protokit_textformat/src/lex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub enum Token {
#[cfg(test)]
mod test {
use logos::Lexer;

use crate::lex::Token;

#[test]
Expand Down
Loading

0 comments on commit 33fdea7

Please sign in to comment.