• Stars
    star
    228
  • Rank 175,267 (Top 4 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created over 2 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A parsing/linking engine for protobuf; the guts for a pure Go replacement of protoc.

The Buf logo

Protocompile

Build Report Card GoDoc

This repo contains a parsing/linking engine for Protocol Buffers, written in pure Go. It is suitable as an alternative to protoc (Google's official reference compiler for Protocol Buffers). This is the compiler that powers Buf and its bevy of tools.

This repo is also the spiritual successor to the github.com/jhump/protoreflect/desc/protoparse package. If you are looking for a newer version of protoparse that natively works with the newer Protobuf runtime API for Go (google.golang.org/protobuf), you have found it!

Protocol Buffers

If you've come across this repo but don't know what Protocol Buffers are, you might acquaint yourself with the official documentation. Protocol Buffers, or Protobuf for short, is an IDL for describing APIs and data structures and also a binary encoding format for efficiently transmitting and storing that data.

If you want to know more about the language itself, which is what this repo implements, take a look at Buf's Protobuf Guide, which includes a very detailed language specification.

Descriptors

Descriptors are the "lingua franca" for describing Protobuf data schemas. They are the basis of runtime features like reflection and dynamic messages. They are also the output of a Protobuf compiler: a compiler can produce them and write them to a file (whose contents are the binary-encoded form of a FileDescriptorSet) or send them to a plugin to generate code for a particular programming language.

Descriptors are similar to nodes in a syntax tree: the contents of a file descriptor correspond closely to the elements in the source file from which it was generated. Also, the descriptor model's data structures are themselves defined in Protobuf.

Using This Repo

The primary API of this repo is in this root package: github.com/bufbuild/protocompile. This is the suggested entry point and provides a type named Compiler, for compiling Protobuf source files into descriptors. There are also numerous sub-packages, most of which implement various stages of the compiler. Here's an overview (not in alphabetical order):

  • protocompile: This is the entry point, used to configure and initiate a compilation operation.
  • parser: This is the first stage of the compiler. It parses Protobuf source code and produces an AST. This package can also generate a file descriptor proto from an AST.
  • ast: This package models an Abstract Syntax Tree (AST) for the Protobuf language.
  • linker: This is the second stage of the compiler. The descriptor proto (generated from an AST) is linked, producing a more useful data structure than simple descriptor protos. This step also performs numerous validations on the source, like making sure that all type references are correct and that sources don't try to define two elements with the same name.
  • options: This is the next stage of the compiler: interpreting options. The linked data structures that come from the previous stage are used to validate and interpret all options.
  • sourceinfo: This is the last stage of the compiler: generating source code info. Source code info contains metadata that maps elements in the descriptor to the location in the original source file from which it came. This includes access to comments. In order to provide correct source info for options, it must happen last, after options have been interpreted.
  • reporter: This package provides error types generated by the compiler and interfaces used by the compiler to report errors and warnings to the calling code.
  • walk: This package provides functions for walking through all of the elements in a descriptor (or descriptor proto) hierarchy.
  • protoutil: This package contains some other useful functions for interacting with Protobuf descriptors.

Migrating from protoparse

There are a few differences between this repo and its predecessor, github.com/jhump/protoreflect/desc/protoparse.

  • If you want to include "standard imports", for the well-known files that are included with protoc, you have to do so explicitly. To do this, wrap your resolver using protocompile.WithStandardImports.
  • If you used protoparse.FileContentsFromMap, in this new repo you'll use a protocompile.SourceResolver and then use protocompile.SourceAccessorFromMap as its accessor function.
  • If you used Parser.ParseToAST, you won't use the protocompile package but instead directly use parser.Parse in this repo's parser sub-package. This returns an AST for the given file contents.
  • If you used Parser.ParseFilesButDoNotLink, that is still possible in this repo, but not provided directly via a single function. Instead, you need to take a few steps:
    1. Parse the source using parser.Parse. Then use parser.ResultFromAST to construct a result that contains a file descriptor proto.
    2. Interpret whatever options can be interpreted without linking using options.InterpretUnlinkedOptions. This may leave some options in the descriptor proto uninterpreted (including all custom options).
    3. If you want source code info for the file, finally call sourceinfo.GenerateSourceInfo using the index returned from the previous step and store that in the file descriptor proto.

More Repositories

1

buf

The best way of working with Protocol Buffers.
Go
8,960
star
2

protoc-gen-validate

Protocol Buffer Validation - Being replaced by github.com/bufbuild/protovalidate
Go
3,764
star
3

protobuf-es

Protocol Buffers for ECMAScript. The only JavaScript Protobuf library that is fully-compliant with Protobuf conformance tests.
TypeScript
1,114
star
4

connect-es

Connect, gRPC, and gRPC-Web support for Protobuf and TypeScript.
TypeScript
980
star
5

protovalidate

Protocol Buffer Validation - Go, Java, Python, and C++ Beta Releases!
Go
876
star
6

protovalidate-go

Protocol Buffer Validation for Go
Go
268
star
7

knit

GraphQL-like capabilities to services using Protocol Buffers, gRPC, and Connect
Go
148
star
8

buf-language-server

Archived: LSP support is being built into the Buf CLI
Go
126
star
9

connect-query

TypeScript-first expansion pack for TanStack Query that gives you Protobuf superpowers
TypeScript
109
star
10

makego

Makefile setup for our Golang projects.
Makefile
100
star
11

connect-opentelemetry-go

OpenTelemetry tracing and metrics for Connect
Go
81
star
12

buf-examples

Example repository that uses Buf.
C#
73
star
13

connect-es-integration

Examples for using Connect with various TypeScript web frameworks and tooling
TypeScript
71
star
14

connect-demo

An example service built with Connect.
Go
66
star
15

vscode-buf

Visual Studio Code integration for Buf.
TypeScript
60
star
16

knit-go

Knit standalone gateway and Go embeddable gateway
Go
49
star
17

plugins

Remote Protobuf plugins available on the BSR
Dockerfile
49
star
18

connect-swift

Idiomatic gRPC & Connect RPCs for Swift.
Swift
48
star
19

buf-gradle-plugin

Gradle plugin for the Buf CLI
Kotlin
48
star
20

buf-tour

Go
48
star
21

rules_buf

Bazel rules for Buf.
Starlark
47
star
22

protoyaml-go

Marshal and unmarshal Protobuf as YAML with rich error messages.
Go
47
star
23

httplb

Client-side load balancing for net/http
Go
46
star
24

prototransform

Client library for Buf Reflection API, for transforming Protobuf data.
Go
45
star
25

connect-kotlin

Idiomatic gRPC & Connect RPCs for Kotlin.
Kotlin
42
star
26

buf-setup-action

TypeScript
40
star
27

connect-grpcreflect-go

gRPC-compatible server reflection for any net/http server.
Go
39
star
28

protovalidate-java

Protocol Buffer Validation for Java.
Java
37
star
29

protovalidate-python

Protocol Buffer Validation for Python.
Python
37
star
30

vim-buf

Vim integration for Buf.
Vim Script
35
star
31

connect-grpchealth-go

gRPC-compatible health checks for any net/http server.
Go
32
star
32

protoplugin

The missing library to write protoc plugins.
Go
29
star
33

buf-lint-action

TypeScript
28
star
34

buf-breaking-action

TypeScript
26
star
35

knit-ts

TypeScript client for Knit
TypeScript
25
star
36

protobuf.com

Buf's Guide to Protobuf. Home of the language spec and grammar for the Protobuf IDL.
CSS
25
star
37

connect-crosstest

Connect's gRPC and gRPC-Web interoperability test suite.
C++
23
star
38

protobuf-conformance

A repository running the Protobuf conformance tests against various libraries
TypeScript
23
star
39

modules

Collection of third-party modules managed and synced by Buf.
Go
20
star
40

bufstream-demo

A demo of Bufstream, a drop-in replacement for Apache Kafka that's 10x less expensive to operate
Go
20
star
41

protoschema-plugins

Protobuf plugins that generate various schemas from protobuf files - JSON Schema, PubSub, etc.
Go
20
star
42

registry-proto

BSR's new public API. Currently in development.
Makefile
18
star
43

intellij-buf

IntelliJ plugin for Buf
Kotlin
18
star
44

protovalidate-cc

Protocol Buffer Validation for C++.
C++
15
star
45

buf-push-action

Shell
15
star
46

buf-action

Build, format, lint, and check for breaking changes in your Protobuf schemas, and automatically publish to the Buf Schema Registry.
TypeScript
15
star
47

bufplugin-go

The Go library for plugins to the Buf platform.
Go
13
star
48

homebrew-buf

Homebrew tap for Buf.
Shell
12
star
49

docs.buf.build

The source for https://docs.buf.build.
TypeScript
11
star
50

tree-sitter-cel

Tree sitter grammar for the Common Expression Language (CEL)
C
10
star
51

wellknowntypes

All the Well-Known Types stored in per-version directories.
Go
9
star
52

connect-envoy-demo

Demonstration of how to use the new Connect-gRPC Envoy filter, available in Envoy v1.26+.
Go
8
star
53

knit-proto

Protocol definition for Knit
7
star
54

reflect-proto

Protobuf reflection API.
7
star
55

bufisk

Bazelisk, but for Buf. A user-friendly launcher for Buf.
Go
7
star
56

knit-demo

An example service built with Knit
Go
6
star
57

protobuf-language-spec

Comprehensive language specification for Protocol Buffers
6
star
58

tools

A collection of tools written at Buf.
JavaScript
5
star
59

confluent-proto

Proto definitions for integrating Confluent Schema Registry with the BSR
Makefile
4
star
60

jest-environment-jsdom

A modern jsdom test environment for Jest
TypeScript
4
star
61

base-workflows

Shared Github Actions for BufBuild Organization.
3
star
62

spdx-go

A simple Golang library that contains license information from SPDX.
Go
2
star
63

bufplugin

The APIs for plugins to the Buf platform.
Makefile
2
star
64

.github

1
star