pbinfo

package
v0.35.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package pbinfo provides convenience types for looking up protobuf elements.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FullyQualifiedType

func FullyQualifiedType(segments ...string) string

fullyQualifiedType constructs a fully-qualified type name suitable for use with pbinfo.Info.

func ReduceServName

func ReduceServName(svc, pkg string) string

ReduceServName removes redundant components from the service name. For example, FooServiceV2 -> Foo. The returned name is used as part of longer names, like FooClient. If the package name and the service name is the same, ReduceServName returns empty string, so we get foo.Client instead of foo.FooClient.

Types

type ImportSpec

type ImportSpec struct {
	Name, Path string
}

type Info

type Info struct {
	// Maps services and messages to the file containing them,
	// so we can figure out the import.
	ParentFile map[proto.Message]*descriptor.FileDescriptorProto

	// Maps a protobuf element to the enclosing scope.
	// If enum E is defined in message M which is in file F,
	// ParentElement[E]=M, ParentElement[M]=nil, and ParentFile[M]=F
	ParentElement map[ProtoType]ProtoType

	// Maps type names to their messages.
	Type map[string]ProtoType

	// Maps service names to their descriptors.
	Serv map[string]*descriptor.ServiceDescriptorProto
}

Info provides lookup tables for various protobuf properties. For example, we can look up a type by name without iterating the entire descriptor.

func Of

func Of(files []*descriptor.FileDescriptorProto) Info

Of creates Info from given protobuf files.

func (*Info) ImportSpec

func (in *Info) ImportSpec(e ProtoType) (ImportSpec, error)

ImportSpec reports the ImportSpec for package containing protobuf element e. Deprecated: Use NameSpec instead.

func (*Info) NameSpec

func (in *Info) NameSpec(e ProtoType) (string, ImportSpec, error)

NameSpec reports the name and ImportSpec of e.

The reported name is the same with how protoc-gen-go refers to e. E.g. if type B is nested under A, then the name of type B is "A_B".

type ProtoType

type ProtoType interface {
	proto.Message
	GetName() string
}

ProtoType represents a type in protobuf descriptors. It is an interface implemented by DescriptorProto and EnumDescriptorProto.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL