Skip to content

Commit

Permalink
Add a 'serde-derive' feature
Browse files Browse the repository at this point in the history
  • Loading branch information
daladim committed Dec 30, 2020
1 parent e057013 commit 1214dfd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions prost-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ doctest = false
[features]
default = ["std"]
std = ["prost/std"]
# Derive serde traits for the structs defined in this crate (unless they contain optional fields)
serde-derive = ["serde"]

[dependencies]
bytes = { version = "0.6", default-features = false }
prost = { version = "0.6.1", path = "..", default-features = false, features = ["prost-derive"] }
serde = { version = "1.0", features = ["derive"], optional = true}

[dev-dependencies]
proptest = "0.9"
40 changes: 40 additions & 0 deletions prost-types/src/protobuf.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/// The protocol compiler can output a FileDescriptorSet containing the .proto
/// files it parses.
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct FileDescriptorSet {
#[prost(message, repeated, tag="1")]
pub file: ::prost::alloc::vec::Vec<FileDescriptorProto>,
}
/// Describes a complete .proto file.
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct FileDescriptorProto {
/// file name, relative to root of source tree
#[prost(string, optional, tag="1")]
Expand Down Expand Up @@ -48,6 +50,7 @@ pub struct FileDescriptorProto {
}
/// Describes a message type.
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct DescriptorProto {
#[prost(string, optional, tag="1")]
pub name: ::core::option::Option<::prost::alloc::string::String>,
Expand Down Expand Up @@ -75,6 +78,7 @@ pub struct DescriptorProto {
/// Nested message and enum types in `DescriptorProto`.
pub mod descriptor_proto {
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtensionRange {
/// Inclusive.
#[prost(int32, optional, tag="1")]
Expand All @@ -89,6 +93,7 @@ pub mod descriptor_proto {
/// fields or extension ranges in the same message. Reserved ranges may
/// not overlap.
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct ReservedRange {
/// Inclusive.
#[prost(int32, optional, tag="1")]
Expand All @@ -99,13 +104,15 @@ pub mod descriptor_proto {
}
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtensionRangeOptions {
/// The parser stores options it doesn't recognize here. See above.
#[prost(message, repeated, tag="999")]
pub uninterpreted_option: ::prost::alloc::vec::Vec<UninterpretedOption>,
}
/// Describes a field within a message.
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct FieldDescriptorProto {
#[prost(string, optional, tag="1")]
pub name: ::core::option::Option<::prost::alloc::string::String>,
Expand Down Expand Up @@ -220,6 +227,7 @@ pub mod field_descriptor_proto {
}
/// Describes a oneof.
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct OneofDescriptorProto {
#[prost(string, optional, tag="1")]
pub name: ::core::option::Option<::prost::alloc::string::String>,
Expand All @@ -228,6 +236,7 @@ pub struct OneofDescriptorProto {
}
/// Describes an enum type.
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct EnumDescriptorProto {
#[prost(string, optional, tag="1")]
pub name: ::core::option::Option<::prost::alloc::string::String>,
Expand All @@ -254,6 +263,7 @@ pub mod enum_descriptor_proto {
/// is inclusive such that it can appropriately represent the entire int32
/// domain.
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct EnumReservedRange {
/// Inclusive.
#[prost(int32, optional, tag="1")]
Expand All @@ -265,6 +275,7 @@ pub mod enum_descriptor_proto {
}
/// Describes a value within an enum.
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct EnumValueDescriptorProto {
#[prost(string, optional, tag="1")]
pub name: ::core::option::Option<::prost::alloc::string::String>,
Expand All @@ -275,6 +286,7 @@ pub struct EnumValueDescriptorProto {
}
/// Describes a service.
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct ServiceDescriptorProto {
#[prost(string, optional, tag="1")]
pub name: ::core::option::Option<::prost::alloc::string::String>,
Expand All @@ -285,6 +297,7 @@ pub struct ServiceDescriptorProto {
}
/// Describes a method of a service.
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct MethodDescriptorProto {
#[prost(string, optional, tag="1")]
pub name: ::core::option::Option<::prost::alloc::string::String>,
Expand Down Expand Up @@ -336,6 +349,7 @@ pub struct MethodDescriptorProto {
// to automatically assign option numbers.

#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct FileOptions {
/// Sets the Java package where classes generated from this .proto will be
/// placed. By default, the proto package is used, but this is often
Expand Down Expand Up @@ -461,6 +475,7 @@ pub mod file_options {
}
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct MessageOptions {
/// Set true to use the old proto1 MessageSet wire format for extensions.
/// This is provided for backwards-compatibility with the MessageSet wire
Expand Down Expand Up @@ -521,6 +536,7 @@ pub struct MessageOptions {
pub uninterpreted_option: ::prost::alloc::vec::Vec<UninterpretedOption>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct FieldOptions {
/// The ctype option instructs the C++ code generator to use a different
/// representation of the field than it normally would. See the specific
Expand Down Expand Up @@ -613,12 +629,14 @@ pub mod field_options {
}
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct OneofOptions {
/// The parser stores options it doesn't recognize here. See above.
#[prost(message, repeated, tag="999")]
pub uninterpreted_option: ::prost::alloc::vec::Vec<UninterpretedOption>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct EnumOptions {
/// Set this option to true to allow mapping different tag names to the same
/// value.
Expand All @@ -635,6 +653,7 @@ pub struct EnumOptions {
pub uninterpreted_option: ::prost::alloc::vec::Vec<UninterpretedOption>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct EnumValueOptions {
/// Is this enum value deprecated?
/// Depending on the target platform, this can emit Deprecated annotations
Expand All @@ -647,6 +666,7 @@ pub struct EnumValueOptions {
pub uninterpreted_option: ::prost::alloc::vec::Vec<UninterpretedOption>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct ServiceOptions {
// Note: Field numbers 1 through 32 are reserved for Google's internal RPC
// framework. We apologize for hoarding these numbers to ourselves, but
Expand All @@ -664,6 +684,7 @@ pub struct ServiceOptions {
pub uninterpreted_option: ::prost::alloc::vec::Vec<UninterpretedOption>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct MethodOptions {
// Note: Field numbers 1 through 32 are reserved for Google's internal RPC
// framework. We apologize for hoarding these numbers to ourselves, but
Expand Down Expand Up @@ -704,6 +725,7 @@ pub mod method_options {
/// or produced by Descriptor::CopyTo()) will never have UninterpretedOptions
/// in them.
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct UninterpretedOption {
#[prost(message, repeated, tag="2")]
pub name: ::prost::alloc::vec::Vec<uninterpreted_option::NamePart>,
Expand All @@ -730,6 +752,7 @@ pub mod uninterpreted_option {
/// E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents
/// "foo.(bar.baz).qux".
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct NamePart {
#[prost(string, required, tag="1")]
pub name_part: ::prost::alloc::string::String,
Expand All @@ -743,6 +766,7 @@ pub mod uninterpreted_option {
/// Encapsulates information about the original source file from which a
/// FileDescriptorProto was generated.
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct SourceCodeInfo {
/// A Location identifies a piece of source code in a .proto file which
/// corresponds to a particular definition. This information is intended
Expand Down Expand Up @@ -793,6 +817,7 @@ pub struct SourceCodeInfo {
/// Nested message and enum types in `SourceCodeInfo`.
pub mod source_code_info {
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct Location {
/// Identifies which part of the FileDescriptorProto was defined at this
/// location.
Expand Down Expand Up @@ -885,6 +910,7 @@ pub mod source_code_info {
/// file. A GeneratedCodeInfo message is associated with only one generated
/// source file, but may contain references to different source .proto files.
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct GeneratedCodeInfo {
/// An Annotation connects some span of text in generated code to an element
/// of its generating .proto file.
Expand All @@ -894,6 +920,7 @@ pub struct GeneratedCodeInfo {
/// Nested message and enum types in `GeneratedCodeInfo`.
pub mod generated_code_info {
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct Annotation {
/// Identifies the element in the original source .proto file. This field
/// is formatted the same as SourceCodeInfo.Location.path.
Expand Down Expand Up @@ -994,6 +1021,7 @@ pub mod generated_code_info {
/// }
///
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct Any {
/// A URL/resource name that uniquely identifies the type of the serialized
/// protocol buffer message. This string must contain at least
Expand Down Expand Up @@ -1032,6 +1060,7 @@ pub struct Any {
/// `SourceContext` represents information about the source of a
/// protobuf element, like the file in which it is defined.
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct SourceContext {
/// The path-qualified name of the .proto file that contained the associated
/// protobuf element. For example: `"google/protobuf/source_context.proto"`.
Expand All @@ -1040,6 +1069,7 @@ pub struct SourceContext {
}
/// A protocol buffer message type.
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct Type {
/// The fully qualified message name.
#[prost(string, tag="1")]
Expand All @@ -1062,6 +1092,7 @@ pub struct Type {
}
/// A single field of a message type.
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct Field {
/// The field type.
#[prost(enumeration="field::Kind", tag="1")]
Expand Down Expand Up @@ -1157,6 +1188,7 @@ pub mod field {
}
/// Enum type definition.
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct Enum {
/// Enum type name.
#[prost(string, tag="1")]
Expand All @@ -1176,6 +1208,7 @@ pub struct Enum {
}
/// Enum value definition.
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct EnumValue {
/// Enum value name.
#[prost(string, tag="1")]
Expand All @@ -1190,6 +1223,7 @@ pub struct EnumValue {
/// A protocol buffer option, which can be attached to a message, field,
/// enumeration, etc.
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct Option {
/// The option's name. For protobuf built-in options (options defined in
/// descriptor.proto), this is the short name. For example, `"map_entry"`.
Expand Down Expand Up @@ -1223,6 +1257,7 @@ pub enum Syntax {
/// this message itself. See https://cloud.google.com/apis/design/glossary for
/// detailed terminology.
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct Api {
/// The fully qualified name of this interface, including package name
/// followed by the interface's simple name.
Expand Down Expand Up @@ -1270,6 +1305,7 @@ pub struct Api {
}
/// Method represents a method of an API interface.
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct Method {
/// The simple name of this method.
#[prost(string, tag="1")]
Expand Down Expand Up @@ -1372,6 +1408,7 @@ pub struct Method {
/// ...
/// }
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct Mixin {
/// The fully qualified name of the interface which is included.
#[prost(string, tag="1")]
Expand Down Expand Up @@ -1442,6 +1479,7 @@ pub struct Mixin {
///
///
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct Duration {
/// Signed seconds of the span of time. Must be from -315,576,000,000
/// to +315,576,000,000 inclusive. Note: these bounds are computed from:
Expand Down Expand Up @@ -1657,6 +1695,7 @@ pub struct Duration {
/// request should verify the included field paths, and return an
/// `INVALID_ARGUMENT` error if any path is unmappable.
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct FieldMask {
/// The set of field mask paths.
#[prost(string, repeated, tag="1")]
Expand Down Expand Up @@ -1817,6 +1856,7 @@ pub enum NullValue {
///
///
#[derive(Clone, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde_derive", derive(serde::Serialize, serde::Deserialize))]
pub struct Timestamp {
/// Represents seconds of UTC time since Unix epoch
/// 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
Expand Down

0 comments on commit 1214dfd

Please sign in to comment.