fdeantoni / prost-wkt

Prost Well-Known-Types serialization and deserialization.
Apache License 2.0
75 stars 37 forks source link

Help on compilation error #51

Open sfali23 opened 1 year ago

sfali23 commented 1 year ago

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 commented 1 year ago

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

sfali23 commented 1 year ago

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.