• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.circleci/H01-Oct-2021-

codec/H01-Oct-2021-

desc/H01-Oct-2021-

dynamic/H01-Oct-2021-

grpcreflect/H01-Oct-2021-

internal/H01-Oct-2021-

.gitignoreH A D01-Oct-202140

.travis.ymlH A D01-Oct-2021621

LICENSEH A D01-Oct-202111.1 KiB

MakefileH A D01-Oct-20212.4 KiB

README.mdH A D01-Oct-20215.4 KiB

go.modH A D01-Oct-2021587

go.sumH A D01-Oct-202112.1 KiB

README.md

1# Protocol Buffer and gRPC Reflection
2[![Build Status](https://circleci.com/gh/jhump/protoreflect/tree/master.svg?style=svg)](https://circleci.com/gh/jhump/protoreflect/tree/master)
3[![Go Report Card](https://goreportcard.com/badge/github.com/jhump/protoreflect)](https://goreportcard.com/report/github.com/jhump/protoreflect)
4
5This repo provides reflection APIs for [protocol buffers](https://developers.google.com/protocol-buffers/) (also known as "protobufs" for short)
6and [gRPC](https://grpc.io/). The core of reflection in protobufs is the
7[descriptor](https://github.com/google/protobuf/blob/199d82fde1734ab5bc931cd0de93309e50cd7ab9/src/google/protobuf/descriptor.proto).
8A descriptor is itself a protobuf message that describes a `.proto` source file or any element
9therein. So a collection of descriptors can describe an entire schema of protobuf types, including
10RPC services.
11
12[![GoDoc](https://godoc.org/github.com/jhump/protoreflect?status.svg)](https://godoc.org/github.com/jhump/protoreflect)
13
14----
15## Descriptors: The Language Model of Protocol Buffers
16
17```go
18import "github.com/jhump/protoreflect/desc"
19```
20
21The `desc` package herein introduces a `Descriptor` interface and implementations of it that
22correspond to each of the descriptor types. These new types are effectively smart wrappers around
23the [generated protobuf types](https://github.com/golang/protobuf/blob/master/protoc-gen-go/descriptor/descriptor.pb.go)
24that make them *much* more useful and easier to use.
25
26You can construct descriptors from file descriptor sets (which can be generated by `protoc`), and
27you can also load descriptors for messages and services that are linked into the current binary.
28"What does it mean for messages and services to be linked in?" you may ask. It means your binary
29imports a package that was generated by `protoc`. When you generate Go code from your `.proto`
30sources, the resulting package has descriptor information embedded in it. The `desc` package allows
31you to easily extract those embedded descriptors.
32
33Descriptors can also be acquired directly from `.proto` source files (using the `protoparse` sub-package)
34or by programmatically constructing them (using the `builder` sub-package).
35
36*[Read more ≫](https://godoc.org/github.com/jhump/protoreflect/desc)*
37
38```go
39import "github.com/jhump/protoreflect/desc/protoparse"
40```
41
42The `protoparse` package allows for parsing of `.proto` source files into rich descriptors. Without
43this package, you must invoke `protoc` to either generate a file descriptor set file or to generate
44Go code (which has descriptor information embedded in it). This package allows reading the source
45directly without having to invoke `protoc`.
46
47*[Read more ≫](https://godoc.org/github.com/jhump/protoreflect/desc/protoparse)*
48
49```go
50import "github.com/jhump/protoreflect/desc/protoprint"
51```
52
53The `protoprint` package allows for printing of descriptors to `.proto` source files. This is
54effectively the inverse of the `protoparse` package. Combined with the `builder` package, this
55is a useful tool for programmatically generating protocol buffer sources.
56
57*[Read more ≫](https://godoc.org/github.com/jhump/protoreflect/desc/protoprint)*
58
59```go
60import "github.com/jhump/protoreflect/desc/builder"
61```
62
63The `builder` package allows for programmatic construction of rich descriptors. Descriptors can
64be constructed programmatically by creating trees of descriptor protos and using the `desc` package
65to link those into rich descriptors. But constructing a valid tree of descriptor protos is far from
66trivial.
67
68So this package provides generous API to greatly simplify that task. It also allows for converting
69rich descriptors into builders, which means you can programmatically modify/tweak existing
70descriptors.
71
72*[Read more ≫](https://godoc.org/github.com/jhump/protoreflect/desc/builder)*
73
74----
75## Dynamic Messages and Stubs
76
77```go
78import "github.com/jhump/protoreflect/dynamic"
79```
80
81The `dynamic` package provides a dynamic message implementation. It implements `proto.Message` but
82is backed by a message descriptor and a map of fields->values, instead of a generated struct. This
83is useful for acting generically with protocol buffer messages, without having to generate and link
84in Go code for every kind of message. This is particularly useful for general-purpose tools that
85need to operate on arbitrary protocol buffer schemas. This is made possible by having the tools load
86descriptors at runtime.
87
88*[Read more ≫](https://godoc.org/github.com/jhump/protoreflect/dynamic)*
89
90```go
91import "github.com/jhump/protoreflect/dynamic/grpcdynamic"
92```
93
94There is also sub-package named `grpcdynamic`, which provides a dynamic stub implementation. The stub can
95be used to issue RPC methods using method descriptors instead of generated client interfaces.
96
97*[Read more ≫](https://godoc.org/github.com/jhump/protoreflect/dynamic/grpcdynamic)*
98
99----
100## gRPC Server Reflection
101
102```go
103import "github.com/jhump/protoreflect/grpcreflect"
104```
105
106The `grpcreflect` package provides an easy-to-use client for the
107[gRPC reflection service](https://github.com/grpc/grpc-go/blob/6bd4f6eb1ea9d81d1209494242554dcde44429a4/reflection/grpc_reflection_v1alpha/reflection.proto#L36),
108making it much easier to query for and work with the schemas of remote services.
109
110It also provides some helper methods for querying for rich service descriptors for the
111services registered in a gRPC server.
112
113*[Read more ≫](https://godoc.org/github.com/jhump/protoreflect/grpcreflect)*
114