Skip to content

Repository files navigation

protogen

protogen allows you to generate TypeScript types and zod validators from protobuf schemas.

Quickstart

Why?

Why build (yet) another type generator when more mature options like ts-proto exist?

I wanted to learn Go and a CLI seems like a great starter project. Also I'm obsessed with generators.

In terms of a real-world use case, I needed a typed communication system for a multiplayer space game I've been working on. Multiplayer games involve a lot of communication between the server and client (for player inputs and broadcasting physics updates, for example). From the start it was clear that I needed a compressed structure. Typed arrays were okay, but weren't general enough to work with many data types - encoding and decoding seemingly basic primitives (like variable length strings) involved a lot of code duplication and felt wrong.

Ultimately, I decided to use protobuf and build some kind of type generator. I'm not totally certain if this is even the right tool for the job, but I know raw JSON certainly isn't.

Supported Syntax

protogen only supports a subset of the proto3 language. I've covered the basics - you can see all supported syntax in example.proto. Anything more complicated should use a mature and battle tested library instead.

Syntax Implemented
Message ⚠️ (wip)
Reserved
Comments
Enums
Packed Encoding
Import
Maps
google.protobuf.Any
oneof
option
extend

About

Yet another type generator project

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages