Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help on compilation error #51

Open
sfali23 opened this issue Aug 24, 2023 · 2 comments
Open

Help on compilation error #51

sfali23 opened this issue Aug 24, 2023 · 2 comments

Comments

@sfali23
Copy link

sfali23 commented Aug 24, 2023

Hi There,

I am getting a compilation error there are too many leading 'super' keywords when building following example:

event-types.proto

syntax = "proto3";

package my.event_types;

enum EventType {
  NotAnEvent = 0;
  Event1 = 1;
  Event2 = 2;
}

messages.proto

syntax = "proto3";

import "google/protobuf/timestamp.proto";

package my.messages;

message Content {
  oneof body {
    string some_string = 1;
    bool some_bool = 2;
    float some_float = 3;
  }
}

message Foo {
  string data = 1;
  google.protobuf.Timestamp timestamp = 2;
  Content content = 3;
}

requests.proto

syntax = "proto3";

import "google/protobuf/any.proto";
import "messages.proto";
import "event-types.proto";

package my.requests;

message Request {
  string requestId = 1;
  google.protobuf.Any payload = 2;
}

message AnotherRequest {
  string requestId = 1;
  my.event_types.EventType eventType = 2;
  my.messages.Foo foo = 3;
}

The generated my.requests.rs is:

#[derive(serde::Serialize, serde::Deserialize)]
#[serde(default, rename_all = "camelCase")]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Request {
    #[prost(string, tag = "1")]
    pub request_id: ::prost::alloc::string::String,
    #[prost(message, optional, tag = "2")]
    pub payload: ::core::option::Option<::prost_wkt_types::Any>,
}
#[derive(serde::Serialize, serde::Deserialize)]
#[serde(default, rename_all = "camelCase")]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AnotherRequest {
    #[prost(string, tag = "1")]
    pub request_id: ::prost::alloc::string::String,
    #[prost(enumeration = "super::event_types::EventType", tag = "2")]
    pub event_type: i32,
    #[prost(message, optional, tag = "3")]
    pub foo: ::core::option::Option<super::messages::Foo>,
}

# [allow (dead_code)] const IMPL_MESSAGE_SERDE_FOR_REQUEST : () = { use :: prost_wkt :: typetag ; # [typetag :: serde (name = "type.googleapis.com/my.requests.Request")] impl :: prost_wkt :: MessageSerde for Request { fn package_name (& self) -> & 'static str { "my.requests" } fn message_name (& self) -> & 'static str { "Request" } fn type_url (& self) -> & 'static str { "type.googleapis.com/my.requests.Request" } fn new_instance (& self , data : Vec < u8 >) -> :: std :: result :: Result < Box < dyn :: prost_wkt :: MessageSerde > , :: prost :: DecodeError > { let mut target = Self :: default () ; :: prost :: Message :: merge (& mut target , data . as_slice ()) ? ; let erased : :: std :: boxed :: Box < dyn :: prost_wkt :: MessageSerde > = :: std :: boxed :: Box :: new (target) ; Ok (erased) } fn try_encoded (& self) -> :: std :: result :: Result < :: std :: vec :: Vec < u8 > , :: prost :: EncodeError > { let mut buf = :: std :: vec :: Vec :: new () ; buf . reserve (:: prost :: Message :: encoded_len (self)) ; :: prost :: Message :: encode (self , & mut buf) ? ; Ok (buf) } } :: prost_wkt :: inventory :: submit ! { :: prost_wkt :: MessageSerdeDecoderEntry { type_url : "type.googleapis.com/my.requests.Request" , decoder : | buf : & [u8] | { let msg : Request = :: prost :: Message :: decode (buf) ? ; Ok (:: std :: boxed :: Box :: new (msg)) } } } } ;

# [allow (dead_code)] const IMPL_MESSAGE_SERDE_FOR_ANOTHER_REQUEST : () = { use :: prost_wkt :: typetag ; # [typetag :: serde (name = "type.googleapis.com/my.requests.AnotherRequest")] impl :: prost_wkt :: MessageSerde for AnotherRequest { fn package_name (& self) -> & 'static str { "my.requests" } fn message_name (& self) -> & 'static str { "AnotherRequest" } fn type_url (& self) -> & 'static str { "type.googleapis.com/my.requests.AnotherRequest" } fn new_instance (& self , data : Vec < u8 >) -> :: std :: result :: Result < Box < dyn :: prost_wkt :: MessageSerde > , :: prost :: DecodeError > { let mut target = Self :: default () ; :: prost :: Message :: merge (& mut target , data . as_slice ()) ? ; let erased : :: std :: boxed :: Box < dyn :: prost_wkt :: MessageSerde > = :: std :: boxed :: Box :: new (target) ; Ok (erased) } fn try_encoded (& self) -> :: std :: result :: Result < :: std :: vec :: Vec < u8 > , :: prost :: EncodeError > { let mut buf = :: std :: vec :: Vec :: new () ; buf . reserve (:: prost :: Message :: encoded_len (self)) ; :: prost :: Message :: encode (self , & mut buf) ? ; Ok (buf) } } :: prost_wkt :: inventory :: submit ! { :: prost_wkt :: MessageSerdeDecoderEntry { type_url : "type.googleapis.com/my.requests.AnotherRequest" , decoder : | buf : & [u8] | { let msg : AnotherRequest = :: prost :: Message :: decode (buf) ? ; Ok (:: std :: boxed :: Box :: new (msg)) } } } } ;

The compilation error is on line pub foo: ::core::option::Option<super::messages::Foo>.

How can I resolve this error?

Another question is that generated type of event_type is i32, is it possible to have something like pub event_type: ::event_types::EventType instead?

Regards Farhan

@fdeantoni
Copy link
Owner

I will need to investigate this a little further. What version of rust were you using?

@sfali23
Copy link
Author

sfali23 commented Sep 22, 2023

Here is my Cargo.tml

name = "proto-generator"
version = "0.1.0"
edition = "2021"

[dependencies]
prost = "0.11.9"
#prost-types = "0.11.9"
prost-wkt = "0.4.2"
prost-wkt-types = "0.4.2"
serde = "1.0.183"
serde_json = "1.0.104"
chrono = { version = "0.4.26", default-features = false, features = ["clock", "serde"] }

[build-dependencies]
prost-build = "0.11.9"
prost-wkt-build = "0.4.2"

Rust version is1.71.1.

Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants