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

Prost-build generates i32 for enum fields instead of using the enum type directly in message #1201

Closed
immno opened this issue Dec 4, 2024 · 1 comment

Comments

@immno
Copy link

immno commented Dec 4, 2024

I have a .proto file:

enum AssetAttrAggregationSourceType {
    AttrMeasureDacoo = 0;
    AttrTask = 1;
    AttrMeasurePipeline = 3;
}

message AssetAttrAggregationCreateEvent {
    int64 id = 1;
    int64 sourceId = 2;
    AssetAttrAggregationSourceType sourceType = 3;
    optional int64 associationId = 4;
}

/// build.rs
/// prost = "0.13"
/// prost-types = "0.13"
/// prost-build = "0.13"
fn main() {
    let mut config = prost_build::Config::new();
    config
        .out_dir("src/queue/msg")
        .compile_protos(&["cluster_event.proto"], &["proto/"])
        .unwrap();
}

After using prost-build to generate the code, it looks like this:

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum AssetAttrAggregationSourceType {
    AttrMeasureDacoo = 0,
    AttrTask = 1,
    AttrMeasurePipeline = 3,
}

#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AssetAttrAggregationCreateEvent {
    #[prost(int64, tag = "1")]
    pub id: i64,
    #[prost(int64, tag = "2")]
    pub source_id: i64,
    #[prost(enumeration = "AssetAttrAggregationSourceType", tag = "3")]
    pub source_type: i32,
    #[prost(int64, optional, tag = "4")]
    pub association_id: ::core::option::Option<i64>
}

Why can't we generate AssetAttrAggregationCreateEvent like the following (Oneof is fine, but it's inconvenient to use now, and we need to convert From every time):

#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AssetAttrAggregationCreateEvent {
    #[prost(int64, tag = "1")]
    pub id: i64,
    #[prost(int64, tag = "2")]
    pub source_id: i64,
    #[prost(enumeration = "AssetAttrAggregationSourceType", tag = "3")]
    pub source_type: AssetAttrAggregationSourceType,
    #[prost(int64, optional, tag = "4")]
    pub association_id: ::core::option::Option<i64>
}
@caspermeijn
Copy link
Collaborator

I agree that would be more convenient. However, that is a breaking change and it requires people to work on it.

I am closing as a duplicate of: #276

If you are interested in working on a solution, you can try to contribute to this PR: #1079

@caspermeijn caspermeijn closed this as not planned Won't fix, can't repro, duplicate, stale Dec 6, 2024
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