# Generate Protocol Buffer .proto file from struct definition

**URL:** https://discourse.julialang.org/t/generate-protocol-buffer-proto-file-from-struct-definition/126650
**Category:** General Usage
**Created:** [March 6, 2025, 6:24pm UTC](https://discourse.julialang.org/t/generate-protocol-buffer-proto-file-from-struct-definition/126650 "2025-03-06T18:24:46Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![lstagner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lstagner/32/448_2.png) [@lstagner](https://discourse.julialang.org/u/lstagner)
#### Post date: [March 6, 2025, 6:24pm UTC](https://discourse.julialang.org/t/generate-protocol-buffer-proto-file-from-struct-definition/126650/1 "2025-03-06T18:24:46Z")

</div>

I have a project that uses Protobuf but in the future I would like to be able to generate the .proto files from a julia struct. For example I would like to be able to take

```julia
struct MyMessage
    a::Int32
    b::Vector{String}
end

```

and turn it into

```protobuf
syntax = "proto3";

message MyMessage {
    sint32 a = 1;
    repeated string b = 2;
}

```

This seems like it should be a solved problem so I thought it should already exists somewhere and I just didn’t find it.

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [March 6, 2025, 6:28pm UTC](https://discourse.julialang.org/t/generate-protocol-buffer-proto-file-from-struct-definition/126650/2 "2025-03-06T18:28:01Z")

</div>

Perplexity says:

> If you have existing Julia structs that you want to use with Protocol Buffers, you would need to manually write a corresponding .proto file that matches the structure of your Julia types.

So is it right or wrong?

According my experience you can always generate structs etc from `.proto` files, but not the other way round, because structs do not contain all the information `.proto` files need.

If you restrict yourself to a subset of the possible ways of doing it, then you could implement such a converter.
