Implement the requested changes in the generator modules.
Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
@@ -84,7 +84,7 @@ pub fn write_message(msg_proto: &DescriptorProto, output: &mut String) {
|
||||
let field_name = field_proto.name().unwrap();
|
||||
|
||||
let tag = field_proto.number().unwrap();
|
||||
let f_type = field_proto.r#type().unwrap() as i32;
|
||||
let f_type = field_proto.rype().unwrap() as i32;
|
||||
let f_label = field_proto.label().unwrap() as i32;
|
||||
let oneof_index = field_proto.oneof_index().ok();
|
||||
let is_map = field_proto
|
||||
@@ -284,7 +284,7 @@ pub fn write_message(msg_proto: &DescriptorProto, output: &mut String) {
|
||||
field_name.clone()
|
||||
};
|
||||
let tag = field_proto.number().unwrap();
|
||||
let f_type = field_proto.r#type().unwrap() as i32;
|
||||
let f_type = field_proto.rype().unwrap() as i32;
|
||||
let (rust_type, method) = map_type_to_rust_builder(f_type);
|
||||
builder_fields.push((field_name, safe_name, tag as u32, rust_type, method));
|
||||
}
|
||||
@@ -342,14 +342,14 @@ pub fn write_message(msg_proto: &DescriptorProto, output: &mut String) {
|
||||
output.push_str(&format!(" pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {{\n self.builder.finish()\n }}\n}}\n\n"));
|
||||
|
||||
output.push_str(&format!(
|
||||
"#[cfg(feature = \"alloc\")]\npub struct Owned{} {{\n",
|
||||
pub struct Owned{} {{\n",
|
||||
msg_name
|
||||
));
|
||||
output.push_str(" pub data: bytes::Bytes,\n");
|
||||
output.push_str("}\n\n");
|
||||
|
||||
output.push_str(&format!(
|
||||
"#[cfg(feature = \"alloc\")]\nimpl roto_runtime::RotoOwned for Owned{} {{\n",
|
||||
impl roto_runtime::RotoOwned for Owned{} {{\n",
|
||||
msg_name
|
||||
));
|
||||
output.push_str(&format!(" type Reader<'a> = {}<'a>;\n", msg_name));
|
||||
@@ -362,7 +362,7 @@ pub fn write_message(msg_proto: &DescriptorProto, output: &mut String) {
|
||||
output.push_str("}\n\n");
|
||||
|
||||
output.push_str(&format!(
|
||||
"#[cfg(feature = \"alloc\")]\nimpl roto_runtime::RotoMessage for Owned{} {{\n",
|
||||
impl roto_runtime::RotoMessage for Owned{} {{\n",
|
||||
msg_name
|
||||
));
|
||||
output.push_str(" fn decode(buf: bytes::Bytes) -> roto_runtime::Result<Self> {\n");
|
||||
|
||||
@@ -7,19 +7,19 @@ use roto_runtime::ProtoAccessor;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::str;
|
||||
|
||||
const DATA_IMPORTS: &str = "use roto_runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator, RotoMessage};\nuse core::str;\n#[cfg(feature = \"alloc\")]\nuse bytes::{Bytes, BytesMut, Buf, BufMut};\n";
|
||||
const SERVICE_IMPORTS: &str = "#[cfg(feature = \"alloc\")]\nuse tonic::{Request, Response, Status};\n\
|
||||
#[cfg(feature = \"alloc\")]\nuse tokio_stream::Stream;\n\
|
||||
#[cfg(feature = \"alloc\")]\nuse std::pin::Pin;\n\
|
||||
#[cfg(feature = \"alloc\")]\nuse std::sync::Arc;\n\
|
||||
#[cfg(feature = \"alloc\")]\nuse std::task::{Context, Poll};\n\
|
||||
#[cfg(feature = \"alloc\")]\nuse std::future::Future;\n\
|
||||
#[cfg(feature = \"alloc\")]\nuse tonic::body::BoxBody;\n\
|
||||
#[cfg(feature = \"alloc\")]\nuse tower::Service;\n\
|
||||
#[cfg(feature = \"alloc\")]\nuse futures_util::StreamExt;\n\
|
||||
#[cfg(feature = \"alloc\")]\nuse http_body_util::BodyExt;\n\
|
||||
#[cfg(feature = \"alloc\")]\nuse http_body::Body;\n\
|
||||
#[cfg(feature = \"alloc\")]\nuse crate::{BufferPool, StatusBody};\n";
|
||||
const DATA_IMPORTS: &str = "use roto_runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator, RotoMessage};\nuse core::str;\nuse bytes::{Bytes, BytesMut, Buf, BufMut};\n";
|
||||
const SERVICE_IMPORTS: &str = "use tonic::{Request, Response, Status};\n\
|
||||
use tokio_stream::Stream;\n\
|
||||
use std::pin::Pin;\n\
|
||||
use std::sync::Arc;\n\
|
||||
use std::task::{Context, Poll};\n\
|
||||
use std::future::Future;\n\
|
||||
use tonic::body::BoxBody;\n\
|
||||
use tower::Service;\n\
|
||||
use futures_util::StreamExt;\n\
|
||||
use http_body_util::BodyExt;\n\
|
||||
use http_body::Body;\n\
|
||||
use crate::{BufferPool, StatusBody};\n";
|
||||
|
||||
pub fn to_pascal_case(s: &str) -> String {
|
||||
s.split('_')
|
||||
@@ -457,14 +457,14 @@ fn write_message(msg_proto: &DescriptorProto, output: &mut String) {
|
||||
output.push_str(&format!(" pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {{\n self.builder.finish()\n }}\n}}\n\n"));
|
||||
|
||||
output.push_str(&format!(
|
||||
"#[cfg(feature = \"alloc\")]\npub struct Owned{} {{\n",
|
||||
"pub struct Owned{} {{\n",
|
||||
msg_name
|
||||
));
|
||||
output.push_str(" pub data: bytes::Bytes,\n");
|
||||
output.push_str("}\n\n");
|
||||
|
||||
output.push_str(&format!(
|
||||
"#[cfg(feature = \"alloc\")]\nimpl roto_runtime::RotoOwned for Owned{} {{\n",
|
||||
"impl roto_runtime::RotoOwned for Owned{} {{\n",
|
||||
msg_name
|
||||
));
|
||||
output.push_str(&format!(" type Reader<'a> = {}<'a>;\n", msg_name));
|
||||
@@ -477,7 +477,7 @@ fn write_message(msg_proto: &DescriptorProto, output: &mut String) {
|
||||
output.push_str("}\n\n");
|
||||
|
||||
output.push_str(&format!(
|
||||
"#[cfg(feature = \"alloc\")]\nimpl roto_runtime::RotoMessage for Owned{} {{\n",
|
||||
"impl roto_runtime::RotoMessage for Owned{} {{\n",
|
||||
msg_name
|
||||
));
|
||||
output.push_str(" fn decode(buf: bytes::Bytes) -> roto_runtime::Result<Self> {\n");
|
||||
@@ -828,7 +828,7 @@ fn write_service(svc_proto: &ServiceDescriptorProto, package: &str, output: &mut
|
||||
output.push_str(SERVICE_IMPORTS);
|
||||
output.push_str("\n");
|
||||
let svc_name = to_pascal_case(svc_proto.name().unwrap());
|
||||
output.push_str("#[cfg(feature = \"alloc\")]\n");
|
||||
|
||||
output.push_str(&format!(
|
||||
"#[async_trait::async_trait]\npub trait {}: Send + Sync + 'static {{\n",
|
||||
svc_name
|
||||
@@ -875,7 +875,7 @@ fn write_service(svc_proto: &ServiceDescriptorProto, package: &str, output: &mut
|
||||
output.push_str("}\n\n");
|
||||
|
||||
let server_name = format!("{}Server", svc_name);
|
||||
output.push_str("#[cfg(feature = \"alloc\")]\n");
|
||||
|
||||
output.push_str(&format!(
|
||||
"#[derive(Clone)]\npub struct {} {{\n",
|
||||
server_name
|
||||
@@ -884,7 +884,7 @@ fn write_service(svc_proto: &ServiceDescriptorProto, package: &str, output: &mut
|
||||
output.push_str(" pool: Arc<BufferPool>,\n");
|
||||
output.push_str("}\n\n");
|
||||
|
||||
output.push_str("#[cfg(feature = \"alloc\")]\n");
|
||||
|
||||
output.push_str(&format!("impl {} {{\n", server_name));
|
||||
output.push_str(&format!(
|
||||
" pub fn new(inner: Arc<dyn {}>, pool: Arc<BufferPool>) -> Self {{\n",
|
||||
@@ -894,7 +894,7 @@ fn write_service(svc_proto: &ServiceDescriptorProto, package: &str, output: &mut
|
||||
output.push_str(" }\n");
|
||||
output.push_str("}\n\n");
|
||||
|
||||
output.push_str("#[cfg(feature = \"alloc\")]\n");
|
||||
|
||||
output.push_str(&format!(
|
||||
"impl tonic::server::NamedService for {} {{\n",
|
||||
server_name
|
||||
@@ -910,7 +910,7 @@ fn write_service(svc_proto: &ServiceDescriptorProto, package: &str, output: &mut
|
||||
));
|
||||
output.push_str("}\n\n");
|
||||
|
||||
output.push_str("#[cfg(feature = \"alloc\")]\n");
|
||||
|
||||
output.push_str(&format!(
|
||||
"impl Service<http::Request<BoxBody>> for {} {{\n",
|
||||
server_name
|
||||
|
||||
@@ -35,7 +35,7 @@ pub fn write_service(svc_proto: &ServiceDescriptorProto, package: &str, output:
|
||||
output.push_str(SERVICE_IMPORTS);
|
||||
output.push_str("\n");
|
||||
let svc_name = to_pascal_case(svc_proto.name().unwrap());
|
||||
output.push_str("#[cfg(feature = \"alloc\")]\n");
|
||||
|
||||
output.push_str(&format!(
|
||||
"#[async_trait::async_trait]\npub trait {}: Send + Sync + 'static {{\n",
|
||||
svc_name
|
||||
@@ -82,7 +82,7 @@ pub fn write_service(svc_proto: &ServiceDescriptorProto, package: &str, output:
|
||||
output.push_str("}\n\n");
|
||||
|
||||
let server_name = format!("{}Server", svc_name);
|
||||
output.push_str("#[cfg(feature = \"alloc\")]\n");
|
||||
|
||||
output.push_str(&format!(
|
||||
"#[derive(Clone)]\npub struct {} {{\n",
|
||||
server_name
|
||||
@@ -91,7 +91,7 @@ pub fn write_service(svc_proto: &ServiceDescriptorProto, package: &str, output:
|
||||
output.push_str(" pool: Arc<BufferPool>,\n");
|
||||
output.push_str("}\n\n");
|
||||
|
||||
output.push_str("#[cfg(feature = \"alloc\")]\n");
|
||||
|
||||
output.push_str(&format!("impl {} {{\n", server_name));
|
||||
output.push_str(&format!(
|
||||
" pub fn new(inner: Arc<dyn {}>, pool: Arc<BufferPool>) -> Self {{\n",
|
||||
@@ -101,7 +101,7 @@ pub fn write_service(svc_proto: &ServiceDescriptorProto, package: &str, output:
|
||||
output.push_str(" }\n");
|
||||
output.push_str("}\n\n");
|
||||
|
||||
output.push_str("#[cfg(feature = \"alloc\")]\n");
|
||||
|
||||
output.push_str(&format!(
|
||||
"impl tonic::server::NamedService for {} {{\n",
|
||||
server_name
|
||||
@@ -117,7 +117,7 @@ pub fn write_service(svc_proto: &ServiceDescriptorProto, package: &str, output:
|
||||
));
|
||||
output.push_str("}\n\n");
|
||||
|
||||
output.push_str("#[cfg(feature = \"alloc\")]\n");
|
||||
|
||||
output.push_str(&format!(
|
||||
"impl Service<http::Request<BoxBody>> for {} {{\n",
|
||||
server_name
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
pub const DATA_IMPORTS: &str = "use roto_runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator, RotoMessage};\nuse core::str;\n#[cfg(feature = \"alloc\")]\nuse bytes::{Bytes, BytesMut, Buf, BufMut};\n";
|
||||
pub const DATA_IMPORTS: &str = "use roto_runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator, RotoMessage};\nuse core::str;\nuse bytes::{Bytes, BytesMut, Buf, BufMut};\n";
|
||||
|
||||
pub fn to_pascal_case(s: &str) -> String {
|
||||
s.split('_')
|
||||
@@ -6,36 +6,11 @@ pub fn to_pascal_case(s: &str) -> String {
|
||||
let mut chars = word.chars();
|
||||
match chars.next() {
|
||||
None => String::new(),
|
||||
Some(f) => f.to_uppercase().collect::<String>() + chars.as_str(),
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn to_snake_case(s: &str) -> String {
|
||||
let mut result = String::new();
|
||||
for (i, c) in s.chars().enumerate() {
|
||||
if c.is_uppercase() {
|
||||
if i > 0 {
|
||||
result.push('_');
|
||||
}
|
||||
result.push(c.to_ascii_lowercase());
|
||||
} else {
|
||||
result.push(c);
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
EOF > /opt/workspace/codegen/src/generator/utils.rs
|
||||
pub const DATA_IMPORTS: &str = "use roto_runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator, RotoMessage};\nuse core::str;\n#[cfg(feature = \"alloc\")]\nuse bytes::{Bytes, BytesMut, Buf, BufMut};\n";
|
||||
|
||||
pub fn to_pascal_case(s: &str) -> String {
|
||||
s.split('_')
|
||||
.map(|word| {
|
||||
let mut chars = word.chars();
|
||||
match chars.next() {
|
||||
None => String::new(),
|
||||
Some(f) => f.to_uppercase().collect::<String>() + chars.as_str(),
|
||||
Some(f) => {
|
||||
let first = f.to_uppercase().collect::<String>();
|
||||
let rest = chars.as_str().to_lowercase();
|
||||
first + &rest
|
||||
}
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
|
||||
Reference in New Issue
Block a user