JuliaIO / ProtoBuf.jl

Julia protobuf implementation
Other
205 stars 56 forks source link

Revisit codegen for self-referential messages #240

Open Drvi opened 1 year ago

Drvi commented 1 year ago

E.g.:

syntax = \"proto3\";
message ShapeMessage {
    float shape = 1;
    repeated ShapeMessage shapeChild = 2;
    optional float dbtype = 3;
}

will be translated to:

abstract type var"##AbstractShapeMessage" end
struct ShapeMessage <: var"##AbstractShapeMessage"
    shape::Float32
    shapeChild::Vector{<:ShapeMessage}
    dbtype::Float32
end

Making shapeChild an abstractly typed field. The simpler and better-performing thing would be to generate this:

struct ShapeMessage
    shape::Float32
    shapeChild::Vector{ShapeMessage}
    dbtype::Float32
end

Which seems to work fine.