From 0dccea370e8269cb7a5d09efc4a83a389247ad8e Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Sat, 25 May 2019 22:58:44 +1200 Subject: [PATCH 1/3] Use Bytes for the Rust type for protobuf bytes Signed-off-by: Nick Cameron --- README.md | 2 +- prost-build/src/code_generator.rs | 2 +- prost-derive/src/field/scalar.rs | 11 +++++---- prost-derive/src/lib.rs | 2 +- prost-types/src/protobuf.rs | 4 ++-- src/encoding.rs | 40 +++++++++++++++++++++++++------ src/types.rs | 4 ++-- 7 files changed, 46 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 2e8b0194b..72c8ad830 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ Scalar value types are converted as follows: | `sfixed64` | `i64` | | `bool` | `bool` | | `string` | `String` | -| `bytes` | `Vec` | +| `bytes` | `Bytes` | #### Enumerations diff --git a/prost-build/src/code_generator.rs b/prost-build/src/code_generator.rs index 593bba807..eff109145 100644 --- a/prost-build/src/code_generator.rs +++ b/prost-build/src/code_generator.rs @@ -714,7 +714,7 @@ impl<'a> CodeGenerator<'a> { Type::Int64 | Type::Sfixed64 | Type::Sint64 => String::from("i64"), Type::Bool => String::from("bool"), Type::String => String::from("std::string::String"), - Type::Bytes => String::from("std::vec::Vec"), + Type::Bytes => String::from("::bytes::Bytes"), Type::Group | Type::Message => self.resolve_ident(field.type_name()), } } diff --git a/prost-derive/src/field/scalar.rs b/prost-derive/src/field/scalar.rs index a4533ff47..61fadaf40 100644 --- a/prost-derive/src/field/scalar.rs +++ b/prost-derive/src/field/scalar.rs @@ -2,7 +2,7 @@ use std::fmt; use failure::{bail, format_err, Error}; use proc_macro2::{Span, TokenStream}; -use quote::{quote, ToTokens}; +use quote::{quote, ToTokens, TokenStreamExt}; use syn::{ self, parse_str, FloatSuffix, Ident, IntSuffix, Lit, LitByteStr, Meta, MetaList, MetaNameValue, NestedMeta, Path, @@ -466,7 +466,7 @@ impl Ty { pub fn rust_type(&self) -> TokenStream { match *self { Ty::String => quote!(::std::string::String), - Ty::Bytes => quote!(::std::vec::Vec), + Ty::Bytes => quote!(::bytes::Bytes), _ => self.rust_ref_type(), } } @@ -749,10 +749,10 @@ impl DefaultValue { quote!(::std::string::String::new()) } DefaultValue::String(ref value) => quote!(#value.to_owned()), - DefaultValue::Bytes(ref value) if value.is_empty() => quote!(::std::vec::Vec::new()), + DefaultValue::Bytes(ref value) if value.is_empty() => quote!(::bytes::Bytes::new()), DefaultValue::Bytes(ref value) => { let lit = LitByteStr::new(value, Span::call_site()); - quote!(#lit.to_owned()) + quote!(::bytes::Bytes::from(#lit)) } ref other => other.typed(), @@ -780,7 +780,8 @@ impl ToTokens for DefaultValue { DefaultValue::Bool(value) => value.to_tokens(tokens), DefaultValue::String(ref value) => value.to_tokens(tokens), DefaultValue::Bytes(ref value) => { - LitByteStr::new(value, Span::call_site()).to_tokens(tokens) + let byte_str = LitByteStr::new(value, Span::call_site()); + tokens.append_all(quote!(#byte_str as &[u8])); } DefaultValue::Enumeration(ref value) => value.to_tokens(tokens), DefaultValue::Path(ref value) => value.to_tokens(tokens), diff --git a/prost-derive/src/lib.rs b/prost-derive/src/lib.rs index e37b263ac..827b80ca7 100644 --- a/prost-derive/src/lib.rs +++ b/prost-derive/src/lib.rs @@ -112,7 +112,7 @@ fn try_message(input: TokenStream) -> Result { .into_iter() .map(|tag| quote!(#tag)) .intersperse(quote!(|)); - quote!(#(#tags)* => #merge.map_err(|mut error| { + quote!(#(#tags)* => #merge.map_err(|mut error: _prost::DecodeError| { error.push(STRUCT_NAME, stringify!(#field_ident)); error }),) diff --git a/prost-types/src/protobuf.rs b/prost-types/src/protobuf.rs index 07a70e61c..ebfb45500 100644 --- a/prost-types/src/protobuf.rs +++ b/prost-types/src/protobuf.rs @@ -686,7 +686,7 @@ pub struct UninterpretedOption { #[prost(double, optional, tag="6")] pub double_value: ::std::option::Option, #[prost(bytes, optional, tag="7")] - pub string_value: ::std::option::Option>, + pub string_value: ::std::option::Option<::bytes::Bytes>, #[prost(string, optional, tag="8")] pub aggregate_value: ::std::option::Option, } @@ -992,7 +992,7 @@ pub struct Any { pub type_url: std::string::String, /// Must be a valid serialized protocol buffer of the above specified type. #[prost(bytes, tag="2")] - pub value: std::vec::Vec, + pub value: ::bytes::Bytes, } /// `SourceContext` represents information about the source of a /// protobuf element, like the file in which it is defined. diff --git a/src/encoding.rs b/src/encoding.rs index 9d8511810..13ee88e43 100644 --- a/src/encoding.rs +++ b/src/encoding.rs @@ -7,11 +7,17 @@ use std::str; use std::u32; use std::usize; -use ::bytes::{Buf, BufMut}; +use ::bytes::{Buf, BufMut, Bytes}; use crate::DecodeError; use crate::Message; +// TODO +// tests/bench +// profile with large byte strings +// strings +// anywhere where we're converting back and forth? + /// Encodes an integer value into LEB128 variable length format, and writes it to the buffer. /// The buffer must have enough remaining space (maximum 10 bytes). #[inline] @@ -732,7 +738,27 @@ pub mod string { // String::as_mut_vec is unsafe because it doesn't check that the bytes // inserted into it the resulting vec are valid UTF-8. We check // explicitly in order to ensure this is safe. - super::bytes::merge(wire_type, value.as_mut_vec(), buf)?; + + check_wire_type(WireType::LengthDelimited, wire_type)?; + let len = decode_varint(buf)?; + if len > buf.remaining() as u64 { + return Err(DecodeError::new("buffer underflow")); + } + + let vec_value = value.as_mut_vec(); + let mut remaining = len as usize; + while remaining > 0 { + let len = { + let bytes = buf.bytes(); + debug_assert!(!bytes.is_empty(), "Buf::bytes returned empty slice"); + let len = min(remaining, bytes.len()); + let bytes = &bytes[..len]; + vec_value.extend_from_slice(bytes); + len + }; + remaining -= len; + buf.advance(len); + } str::from_utf8(value.as_bytes()) .map_err(|_| DecodeError::new("invalid string value: data is not UTF-8 encoded"))?; } @@ -745,18 +771,18 @@ pub mod string { pub mod bytes { use super::*; - pub fn encode(tag: u32, value: &Vec, buf: &mut B) + pub fn encode(tag: u32, value: &Bytes, buf: &mut B) where B: BufMut, { encode_key(tag, WireType::LengthDelimited, buf); encode_varint(value.len() as u64, buf); - buf.put_slice(value); + buf.put(value); } pub fn merge( wire_type: WireType, - value: &mut Vec, + value: &mut Bytes, buf: &mut B, ) -> Result<(), DecodeError> where @@ -784,7 +810,7 @@ pub mod bytes { Ok(()) } - length_delimited!(Vec); + length_delimited!(Bytes); } pub mod message { @@ -1481,6 +1507,6 @@ mod test { (i64, sfixed64), (bool, bool), (String, string), - (Vec, bytes) + (Bytes, bytes) ]); } diff --git a/src/types.rs b/src/types.rs index 5a675f300..280bd2764 100644 --- a/src/types.rs +++ b/src/types.rs @@ -5,7 +5,7 @@ //! the `prost-types` crate in order to avoid a cyclic dependency between `prost` and //! `prost-build`. -use ::bytes::{Buf, BufMut}; +use ::bytes::{Buf, BufMut, Bytes}; use crate::encoding::*; use crate::DecodeError; @@ -308,7 +308,7 @@ impl Message for String { } /// `google.protobuf.BytesValue` -impl Message for Vec { +impl Message for Bytes { fn encode_raw(&self, buf: &mut B) where B: BufMut, From 6d5da1088a8627a59a96168e652b562de7e17737 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Mon, 27 May 2019 11:53:38 +1200 Subject: [PATCH 2/3] Use a wrapper type instead of String Signed-off-by: Nick Cameron --- prost-build/src/code_generator.rs | 15 +- prost-build/src/message_graph.rs | 9 +- prost-derive/src/field/scalar.rs | 44 ++-- prost-types/src/compiler.rs | 14 +- prost-types/src/protobuf.rs | 114 +++++----- src/encoding.rs | 50 +---- src/lib.rs | 2 + src/string.rs | 353 ++++++++++++++++++++++++++++++ src/types.rs | 4 +- 9 files changed, 475 insertions(+), 130 deletions(-) create mode 100644 src/string.rs diff --git a/prost-build/src/code_generator.rs b/prost-build/src/code_generator.rs index eff109145..d15e9496f 100644 --- a/prost-build/src/code_generator.rs +++ b/prost-build/src/code_generator.rs @@ -6,6 +6,7 @@ use std::iter; use itertools::{Either, Itertools}; use log::debug; use multimap::MultiMap; +use prost::BytesString; use prost_types::field_descriptor_proto::{Label, Type}; use prost_types::source_code_info::Location; use prost_types::{ @@ -56,7 +57,7 @@ impl<'a> CodeGenerator<'a> { .location .sort_by_key(|location| location.path.clone()); - let syntax = match file.syntax.as_ref().map(String::as_str) { + let syntax = match file.syntax.as_ref().map(BytesString::as_ref) { None | Some("proto2") => Syntax::Proto2, Some("proto3") => Syntax::Proto3, Some(s) => panic!("unknown syntax: {}", s), @@ -64,7 +65,7 @@ impl<'a> CodeGenerator<'a> { let mut code_gen = CodeGenerator { config, - package: file.package.unwrap(), + package: file.package.unwrap().to_string(), source_info, syntax, message_graph, @@ -191,7 +192,7 @@ impl<'a> CodeGenerator<'a> { match field .type_name .as_ref() - .and_then(|type_name| map_types.get(type_name)) + .and_then(|type_name| map_types.get::(type_name.as_ref())) { Some(&(ref key, ref value)) => { self.append_map_field(&fq_message_name, field, key, value) @@ -636,9 +637,9 @@ impl<'a> CodeGenerator<'a> { let comments = Comments::from_location(self.location()); self.path.pop(); - let name = method.name.take().unwrap(); - let input_proto_type = method.input_type.take().unwrap(); - let output_proto_type = method.output_type.take().unwrap(); + let name = method.name.take().unwrap().to_string(); + let input_proto_type = method.input_type.take().unwrap().to_string(); + let output_proto_type = method.output_type.take().unwrap().to_string(); let input_type = self.resolve_ident(&input_proto_type); let output_type = self.resolve_ident(&output_proto_type); let client_streaming = method.client_streaming(); @@ -713,7 +714,7 @@ impl<'a> CodeGenerator<'a> { Type::Int32 | Type::Sfixed32 | Type::Sint32 | Type::Enum => String::from("i32"), Type::Int64 | Type::Sfixed64 | Type::Sint64 => String::from("i64"), Type::Bool => String::from("bool"), - Type::String => String::from("std::string::String"), + Type::String => String::from("::prost::BytesString"), Type::Bytes => String::from("::bytes::Bytes"), Type::Group | Type::Message => self.resolve_ident(field.type_name()), } diff --git a/prost-build/src/message_graph.rs b/prost-build/src/message_graph.rs index 6ae20e1d0..bb01663e8 100644 --- a/prost-build/src/message_graph.rs +++ b/prost-build/src/message_graph.rs @@ -4,14 +4,15 @@ use petgraph::algo::has_path_connecting; use petgraph::graph::NodeIndex; use petgraph::Graph; +use prost::BytesString; use prost_types::{field_descriptor_proto, DescriptorProto, FileDescriptorProto}; /// `MessageGraph` builds a graph of messages whose edges correspond to nesting. /// The goal is to recognize when message types are recursively nested, so /// that fields can be boxed when necessary. pub struct MessageGraph { - index: HashMap, - graph: Graph, + index: HashMap, + graph: Graph, } impl MessageGraph { @@ -31,7 +32,7 @@ impl MessageGraph { msg_graph } - fn get_or_insert_index(&mut self, msg_name: String) -> NodeIndex { + fn get_or_insert_index(&mut self, msg_name: BytesString) -> NodeIndex { let MessageGraph { ref mut index, ref mut graph, @@ -49,7 +50,7 @@ impl MessageGraph { /// Since repeated messages are already put in a Vec, boxing them isn’t necessary even if the reference is recursive. fn add_message(&mut self, package: &str, msg: &DescriptorProto) { let msg_name = format!("{}.{}", package, msg.name.as_ref().unwrap()); - let msg_index = self.get_or_insert_index(msg_name.clone()); + let msg_index = self.get_or_insert_index(msg_name.clone().into()); for field in &msg.field { if field.r#type() == field_descriptor_proto::Type::Message diff --git a/prost-derive/src/field/scalar.rs b/prost-derive/src/field/scalar.rs index 61fadaf40..8f5e9a036 100644 --- a/prost-derive/src/field/scalar.rs +++ b/prost-derive/src/field/scalar.rs @@ -124,8 +124,13 @@ impl Field { match self.kind { Kind::Plain(ref default) => { let default = default.typed(); + let deref_ident = if self.ty == Ty::String { + quote!(&*#ident) + } else { + ident.clone() + }; quote! { - if #ident != #default { + if #deref_ident != #default { #encode_fn(#tag, &#ident, buf); } } @@ -177,8 +182,13 @@ impl Field { match self.kind { Kind::Plain(ref default) => { let default = default.typed(); + let deref_ident = if self.ty == Ty::String { + quote!(&*#ident) + } else { + ident.clone() + }; quote! { - if #ident != #default { + if #deref_ident != #default { #encoded_len_fn(#tag, &#ident) } else { 0 @@ -196,13 +206,13 @@ impl Field { pub fn clear(&self, ident: TokenStream) -> TokenStream { match self.kind { - Kind::Plain(ref default) | Kind::Required(ref default) => { - let default = default.typed(); - match self.ty { - Ty::String | Ty::Bytes => quote!(#ident.clear()), - _ => quote!(#ident = #default), + Kind::Plain(ref default) | Kind::Required(ref default) => match self.ty { + Ty::String | Ty::Bytes => quote!(#ident.clear()), + _ => { + let default = default.typed(); + quote!(#ident = #default) } - } + }, Kind::Optional(_) => quote!(#ident = ::std::option::Option::None), Kind::Repeated | Kind::Packed => quote!(#ident.clear()), } @@ -465,7 +475,7 @@ impl Ty { // TODO: rename to 'owned_type'. pub fn rust_type(&self) -> TokenStream { match *self { - Ty::String => quote!(::std::string::String), + Ty::String => quote!(::prost::BytesString), Ty::Bytes => quote!(::bytes::Bytes), _ => self.rust_ref_type(), } @@ -746,9 +756,14 @@ impl DefaultValue { pub fn owned(&self) -> TokenStream { match *self { DefaultValue::String(ref value) if value.is_empty() => { - quote!(::std::string::String::new()) + quote!(::prost::BytesString::new()) + } + DefaultValue::String(ref value) if value.is_empty() => { + quote!(::prost::BytesString::new()) + } + DefaultValue::String(ref value) => { + quote!(::prost::BytesString::from(#value.to_owned())) } - DefaultValue::String(ref value) => quote!(#value.to_owned()), DefaultValue::Bytes(ref value) if value.is_empty() => quote!(::bytes::Bytes::new()), DefaultValue::Bytes(ref value) => { let lit = LitByteStr::new(value, Span::call_site()); @@ -760,10 +775,9 @@ impl DefaultValue { } pub fn typed(&self) -> TokenStream { - if let DefaultValue::Enumeration(_) = *self { - quote!(#self as i32) - } else { - quote!(#self) + match *self { + DefaultValue::Enumeration(_) => quote!(#self as i32), + _ => quote!(#self), } } } diff --git a/prost-types/src/compiler.rs b/prost-types/src/compiler.rs index 421bd78ba..151537c77 100644 --- a/prost-types/src/compiler.rs +++ b/prost-types/src/compiler.rs @@ -10,7 +10,7 @@ pub struct Version { /// A suffix for alpha, beta or rc release, e.g., "alpha-1", "rc2". It should /// be empty for mainline stable releases. #[prost(string, optional, tag="4")] - pub suffix: ::std::option::Option, + pub suffix: ::std::option::Option<::prost::BytesString>, } /// An encoded CodeGeneratorRequest is written to the plugin's stdin. #[derive(Clone, PartialEq, ::prost::Message)] @@ -19,10 +19,10 @@ pub struct CodeGeneratorRequest { /// code generator should generate code only for these files. Each file's /// descriptor will be included in proto_file, below. #[prost(string, repeated, tag="1")] - pub file_to_generate: ::std::vec::Vec, + pub file_to_generate: ::std::vec::Vec<::prost::BytesString>, /// The generator parameter passed on the command-line. #[prost(string, optional, tag="2")] - pub parameter: ::std::option::Option, + pub parameter: ::std::option::Option<::prost::BytesString>, /// FileDescriptorProtos for all files in files_to_generate and everything /// they import. The files will appear in topological order, so each file /// appears before any file that imports it. @@ -55,7 +55,7 @@ pub struct CodeGeneratorResponse { /// unparseable -- should be reported by writing a message to stderr and /// exiting with a non-zero status code. #[prost(string, optional, tag="1")] - pub error: ::std::option::Option, + pub error: ::std::option::Option<::prost::BytesString>, #[prost(message, repeated, tag="15")] pub file: ::std::vec::Vec, } @@ -75,7 +75,7 @@ pub mod code_generator_response { /// this writing protoc does not optimize for this -- it will read the entire /// CodeGeneratorResponse before writing files to disk. #[prost(string, optional, tag="1")] - pub name: ::std::option::Option, + pub name: ::std::option::Option<::prost::BytesString>, /// If non-empty, indicates that the named file should already exist, and the /// content here is to be inserted into that file at a defined insertion /// point. This feature allows a code generator to extend the output @@ -114,9 +114,9 @@ pub mod code_generator_response { /// /// If |insertion_point| is present, |name| must also be present. #[prost(string, optional, tag="2")] - pub insertion_point: ::std::option::Option, + pub insertion_point: ::std::option::Option<::prost::BytesString>, /// The file contents. #[prost(string, optional, tag="15")] - pub content: ::std::option::Option, + pub content: ::std::option::Option<::prost::BytesString>, } } diff --git a/prost-types/src/protobuf.rs b/prost-types/src/protobuf.rs index ebfb45500..bafe45070 100644 --- a/prost-types/src/protobuf.rs +++ b/prost-types/src/protobuf.rs @@ -10,13 +10,13 @@ pub struct FileDescriptorSet { pub struct FileDescriptorProto { /// file name, relative to root of source tree #[prost(string, optional, tag="1")] - pub name: ::std::option::Option, + pub name: ::std::option::Option<::prost::BytesString>, /// e.g. "foo", "foo.bar", etc. #[prost(string, optional, tag="2")] - pub package: ::std::option::Option, + pub package: ::std::option::Option<::prost::BytesString>, /// Names of files imported by this file. #[prost(string, repeated, tag="3")] - pub dependency: ::std::vec::Vec, + pub dependency: ::std::vec::Vec<::prost::BytesString>, /// Indexes of the public imported files in the dependency list above. #[prost(int32, repeated, packed="false", tag="10")] pub public_dependency: ::std::vec::Vec, @@ -44,13 +44,13 @@ pub struct FileDescriptorProto { /// The syntax of the proto file. /// The supported values are "proto2" and "proto3". #[prost(string, optional, tag="12")] - pub syntax: ::std::option::Option, + pub syntax: ::std::option::Option<::prost::BytesString>, } /// Describes a message type. #[derive(Clone, PartialEq, ::prost::Message)] pub struct DescriptorProto { #[prost(string, optional, tag="1")] - pub name: ::std::option::Option, + pub name: ::std::option::Option<::prost::BytesString>, #[prost(message, repeated, tag="2")] pub field: ::std::vec::Vec, #[prost(message, repeated, tag="6")] @@ -70,7 +70,7 @@ pub struct DescriptorProto { /// Reserved field names, which may not be used by fields in the same message. /// A given name may only be reserved once. #[prost(string, repeated, tag="10")] - pub reserved_name: ::std::vec::Vec, + pub reserved_name: ::std::vec::Vec<::prost::BytesString>, } pub mod descriptor_proto { #[derive(Clone, PartialEq, ::prost::Message)] @@ -105,7 +105,7 @@ pub struct ExtensionRangeOptions { #[derive(Clone, PartialEq, ::prost::Message)] pub struct FieldDescriptorProto { #[prost(string, optional, tag="1")] - pub name: ::std::option::Option, + pub name: ::std::option::Option<::prost::BytesString>, #[prost(int32, optional, tag="3")] pub number: ::std::option::Option, #[prost(enumeration="field_descriptor_proto::Label", optional, tag="4")] @@ -120,18 +120,18 @@ pub struct FieldDescriptorProto { /// message are searched, then within the parent, on up to the root /// namespace). #[prost(string, optional, tag="6")] - pub type_name: ::std::option::Option, + pub type_name: ::std::option::Option<::prost::BytesString>, /// For extensions, this is the name of the type being extended. It is /// resolved in the same manner as type_name. #[prost(string, optional, tag="2")] - pub extendee: ::std::option::Option, + pub extendee: ::std::option::Option<::prost::BytesString>, /// For numeric types, contains the original text representation of the value. /// For booleans, "true" or "false". /// For strings, contains the default text contents (not escaped in any way). /// For bytes, contains the C escaped value. All bytes >= 128 are escaped. /// TODO(kenton): Base-64 encode? #[prost(string, optional, tag="7")] - pub default_value: ::std::option::Option, + pub default_value: ::std::option::Option<::prost::BytesString>, /// If set, gives the index of a oneof in the containing type's oneof_decl /// list. This field is a member of that oneof. #[prost(int32, optional, tag="9")] @@ -141,7 +141,7 @@ pub struct FieldDescriptorProto { /// will be used. Otherwise, it's deduced from the field's name by converting /// it to camelCase. #[prost(string, optional, tag="10")] - pub json_name: ::std::option::Option, + pub json_name: ::std::option::Option<::prost::BytesString>, #[prost(message, optional, tag="8")] pub options: ::std::option::Option, } @@ -195,7 +195,7 @@ pub mod field_descriptor_proto { #[derive(Clone, PartialEq, ::prost::Message)] pub struct OneofDescriptorProto { #[prost(string, optional, tag="1")] - pub name: ::std::option::Option, + pub name: ::std::option::Option<::prost::BytesString>, #[prost(message, optional, tag="2")] pub options: ::std::option::Option, } @@ -203,7 +203,7 @@ pub struct OneofDescriptorProto { #[derive(Clone, PartialEq, ::prost::Message)] pub struct EnumDescriptorProto { #[prost(string, optional, tag="1")] - pub name: ::std::option::Option, + pub name: ::std::option::Option<::prost::BytesString>, #[prost(message, repeated, tag="2")] pub value: ::std::vec::Vec, #[prost(message, optional, tag="3")] @@ -216,7 +216,7 @@ pub struct EnumDescriptorProto { /// Reserved enum value names, which may not be reused. A given name may only /// be reserved once. #[prost(string, repeated, tag="5")] - pub reserved_name: ::std::vec::Vec, + pub reserved_name: ::std::vec::Vec<::prost::BytesString>, } pub mod enum_descriptor_proto { /// Range of reserved numeric values. Reserved values may not be used by @@ -239,7 +239,7 @@ pub mod enum_descriptor_proto { #[derive(Clone, PartialEq, ::prost::Message)] pub struct EnumValueDescriptorProto { #[prost(string, optional, tag="1")] - pub name: ::std::option::Option, + pub name: ::std::option::Option<::prost::BytesString>, #[prost(int32, optional, tag="2")] pub number: ::std::option::Option, #[prost(message, optional, tag="3")] @@ -249,7 +249,7 @@ pub struct EnumValueDescriptorProto { #[derive(Clone, PartialEq, ::prost::Message)] pub struct ServiceDescriptorProto { #[prost(string, optional, tag="1")] - pub name: ::std::option::Option, + pub name: ::std::option::Option<::prost::BytesString>, #[prost(message, repeated, tag="2")] pub method: ::std::vec::Vec, #[prost(message, optional, tag="3")] @@ -259,13 +259,13 @@ pub struct ServiceDescriptorProto { #[derive(Clone, PartialEq, ::prost::Message)] pub struct MethodDescriptorProto { #[prost(string, optional, tag="1")] - pub name: ::std::option::Option, + pub name: ::std::option::Option<::prost::BytesString>, /// Input and output type names. These are resolved in the same way as /// FieldDescriptorProto.type_name, but must refer to a message type. #[prost(string, optional, tag="2")] - pub input_type: ::std::option::Option, + pub input_type: ::std::option::Option<::prost::BytesString>, #[prost(string, optional, tag="3")] - pub output_type: ::std::option::Option, + pub output_type: ::std::option::Option<::prost::BytesString>, #[prost(message, optional, tag="4")] pub options: ::std::option::Option, /// Identifies if client streams multiple client messages @@ -314,14 +314,14 @@ pub struct FileOptions { /// inappropriate because proto packages do not normally start with backwards /// domain names. #[prost(string, optional, tag="1")] - pub java_package: ::std::option::Option, + pub java_package: ::std::option::Option<::prost::BytesString>, /// If set, all the classes from the .proto file are wrapped in a single /// outer class with the given name. This applies to both Proto1 /// (equivalent to the old "--one_java_file" option) and Proto2 (where /// a .proto always translates to a single class, but you may want to /// explicitly choose the class name). #[prost(string, optional, tag="8")] - pub java_outer_classname: ::std::option::Option, + pub java_outer_classname: ::std::option::Option<::prost::BytesString>, /// If set true, then the Java code generator will generate a separate .java /// file for each top-level message, enum, and service defined in the .proto /// file. Thus, these types will *not* be nested inside the outer class @@ -349,7 +349,7 @@ pub struct FileOptions { /// - Otherwise, the package statement in the .proto file, if present. /// - Otherwise, the basename of the .proto file, without extension. #[prost(string, optional, tag="11")] - pub go_package: ::std::option::Option, + pub go_package: ::std::option::Option<::prost::BytesString>, /// Should generic services be generated in each language? "Generic" services /// are not specific to any particular RPC system. They are generated by the /// main code generators in each language (without additional plugins). @@ -381,35 +381,35 @@ pub struct FileOptions { /// Sets the objective c class prefix which is prepended to all objective c /// generated classes from this .proto. There is no default. #[prost(string, optional, tag="36")] - pub objc_class_prefix: ::std::option::Option, + pub objc_class_prefix: ::std::option::Option<::prost::BytesString>, /// Namespace for generated classes; defaults to the package. #[prost(string, optional, tag="37")] - pub csharp_namespace: ::std::option::Option, + pub csharp_namespace: ::std::option::Option<::prost::BytesString>, /// By default Swift generators will take the proto package and CamelCase it /// replacing '.' with underscore and use that to prefix the types/symbols /// defined. When this options is provided, they will use this value instead /// to prefix the types/symbols defined. #[prost(string, optional, tag="39")] - pub swift_prefix: ::std::option::Option, + pub swift_prefix: ::std::option::Option<::prost::BytesString>, /// Sets the php class prefix which is prepended to all php generated classes /// from this .proto. Default is empty. #[prost(string, optional, tag="40")] - pub php_class_prefix: ::std::option::Option, + pub php_class_prefix: ::std::option::Option<::prost::BytesString>, /// Use this option to change the namespace of php generated classes. Default /// is empty. When this option is empty, the package name will be used for /// determining the namespace. #[prost(string, optional, tag="41")] - pub php_namespace: ::std::option::Option, + pub php_namespace: ::std::option::Option<::prost::BytesString>, /// Use this option to change the namespace of php generated metadata classes. /// Default is empty. When this option is empty, the proto file name will be used /// for determining the namespace. #[prost(string, optional, tag="44")] - pub php_metadata_namespace: ::std::option::Option, + pub php_metadata_namespace: ::std::option::Option<::prost::BytesString>, /// Use this option to change the package of ruby generated classes. Default /// is empty. When this option is not set, the package name will be used for /// determining the ruby package. #[prost(string, optional, tag="45")] - pub ruby_package: ::std::option::Option, + pub ruby_package: ::std::option::Option<::prost::BytesString>, /// The parser stores options it doesn't recognize here. /// See the documentation for the "Options" section above. #[prost(message, repeated, tag="999")] @@ -678,7 +678,7 @@ pub struct UninterpretedOption { /// The value of the uninterpreted option, in whatever type the tokenizer /// identified it as during parsing. Exactly one of these should be set. #[prost(string, optional, tag="3")] - pub identifier_value: ::std::option::Option, + pub identifier_value: ::std::option::Option<::prost::BytesString>, #[prost(uint64, optional, tag="4")] pub positive_int_value: ::std::option::Option, #[prost(int64, optional, tag="5")] @@ -688,7 +688,7 @@ pub struct UninterpretedOption { #[prost(bytes, optional, tag="7")] pub string_value: ::std::option::Option<::bytes::Bytes>, #[prost(string, optional, tag="8")] - pub aggregate_value: ::std::option::Option, + pub aggregate_value: ::std::option::Option<::prost::BytesString>, } pub mod uninterpreted_option { /// The name of the uninterpreted option. Each string represents a segment in @@ -699,7 +699,7 @@ pub mod uninterpreted_option { #[derive(Clone, PartialEq, ::prost::Message)] pub struct NamePart { #[prost(string, required, tag="1")] - pub name_part: std::string::String, + pub name_part: ::prost::BytesString, #[prost(bool, required, tag="2")] pub is_extension: bool, } @@ -840,11 +840,11 @@ pub mod source_code_info { /// /// // ignored detached comments. #[prost(string, optional, tag="3")] - pub leading_comments: ::std::option::Option, + pub leading_comments: ::std::option::Option<::prost::BytesString>, #[prost(string, optional, tag="4")] - pub trailing_comments: ::std::option::Option, + pub trailing_comments: ::std::option::Option<::prost::BytesString>, #[prost(string, repeated, tag="6")] - pub leading_detached_comments: ::std::vec::Vec, + pub leading_detached_comments: ::std::vec::Vec<::prost::BytesString>, } } /// Describes the relationship between generated code and its original source @@ -866,7 +866,7 @@ pub mod generated_code_info { pub path: ::std::vec::Vec, /// Identifies the filesystem path to the original source .proto. #[prost(string, optional, tag="2")] - pub source_file: ::std::option::Option, + pub source_file: ::std::option::Option<::prost::BytesString>, /// Identifies the starting offset in bytes in the generated code /// that relates to the identified object. #[prost(int32, optional, tag="3")] @@ -989,7 +989,7 @@ pub struct Any { /// used with implementation specific semantics. /// #[prost(string, tag="1")] - pub type_url: std::string::String, + pub type_url: ::prost::BytesString, /// Must be a valid serialized protocol buffer of the above specified type. #[prost(bytes, tag="2")] pub value: ::bytes::Bytes, @@ -1001,20 +1001,20 @@ pub struct SourceContext { /// The path-qualified name of the .proto file that contained the associated /// protobuf element. For example: `"google/protobuf/source_context.proto"`. #[prost(string, tag="1")] - pub file_name: std::string::String, + pub file_name: ::prost::BytesString, } /// A protocol buffer message type. #[derive(Clone, PartialEq, ::prost::Message)] pub struct Type { /// The fully qualified message name. #[prost(string, tag="1")] - pub name: std::string::String, + pub name: ::prost::BytesString, /// The list of fields. #[prost(message, repeated, tag="2")] pub fields: ::std::vec::Vec, /// The list of types appearing in `oneof` definitions in this type. #[prost(string, repeated, tag="3")] - pub oneofs: ::std::vec::Vec, + pub oneofs: ::std::vec::Vec<::prost::BytesString>, /// The protocol buffer options. #[prost(message, repeated, tag="4")] pub options: ::std::vec::Vec