mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-01-30 03:32:49 +00:00
internal/filedesc, internal/filetype: rename {Desc,Type}Builder as Builder
Reduce the stutter in the name since the type of Builder is obvious from the package it is from. Change-Id: I0046a5122717536cc6bb5ebdb32b67a1560cfc23 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/189020 Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
parent
954bd92c19
commit
52ec1759a4
@ -13,8 +13,8 @@ import (
|
||||
preg "google.golang.org/protobuf/reflect/protoregistry"
|
||||
)
|
||||
|
||||
// DescBuilder construct a protoreflect.FileDescriptor from the raw descriptor.
|
||||
type DescBuilder struct {
|
||||
// Builder construct a protoreflect.FileDescriptor from the raw descriptor.
|
||||
type Builder struct {
|
||||
// GoPackagePath is the Go package path that is invoking this builder.
|
||||
GoPackagePath string
|
||||
|
||||
@ -48,15 +48,15 @@ type DescBuilder struct {
|
||||
}
|
||||
}
|
||||
|
||||
// resolverByIndex is an interface DescBuilder.FileRegistry may implement.
|
||||
// resolverByIndex is an interface Builder.FileRegistry may implement.
|
||||
// If so, it permits looking up an enum or message dependency based on the
|
||||
// sub-list and element index into filetype.TypeBuilder.DependencyIndexes.
|
||||
// sub-list and element index into filetype.Builder.DependencyIndexes.
|
||||
type resolverByIndex interface {
|
||||
FindEnumByIndex(int32, int32, []Enum, []Message) pref.EnumDescriptor
|
||||
FindMessageByIndex(int32, int32, []Enum, []Message) pref.MessageDescriptor
|
||||
}
|
||||
|
||||
// Indexes of each sub-list in filetype.TypeBuilder.DependencyIndexes.
|
||||
// Indexes of each sub-list in filetype.Builder.DependencyIndexes.
|
||||
const (
|
||||
listFieldDeps int32 = iota
|
||||
listExtTargets
|
||||
@ -65,13 +65,13 @@ const (
|
||||
listMethOutDeps
|
||||
)
|
||||
|
||||
// Build constructs a FileDescriptor given the parameters set in DescBuilder.
|
||||
// Build constructs a FileDescriptor given the parameters set in Builder.
|
||||
// It assumes that the inputs are well-formed and panics if any inconsistencies
|
||||
// are encountered.
|
||||
//
|
||||
// If NumEnums+NumMessages+NumExtensions+NumServices is zero,
|
||||
// then Build automatically derives them from the raw descriptor.
|
||||
func (db DescBuilder) Build() (out struct {
|
||||
func (db Builder) Build() (out struct {
|
||||
File pref.FileDescriptor
|
||||
|
||||
// Enums is all enum descriptors in "flattened ordering".
|
||||
@ -113,7 +113,7 @@ func (db DescBuilder) Build() (out struct {
|
||||
// unmarshalCounts counts the number of enum, message, extension, and service
|
||||
// declarations in the raw message, which is either a FileDescriptorProto
|
||||
// or a MessageDescriptorProto depending on whether isFile is set.
|
||||
func (db *DescBuilder) unmarshalCounts(b []byte, isFile bool) {
|
||||
func (db *Builder) unmarshalCounts(b []byte, isFile bool) {
|
||||
for len(b) > 0 {
|
||||
num, typ, n := wire.ConsumeTag(b)
|
||||
b = b[n:]
|
||||
|
@ -16,14 +16,14 @@ import (
|
||||
// fileRaw is a data struct used when initializing a file descriptor from
|
||||
// a raw FileDescriptorProto.
|
||||
type fileRaw struct {
|
||||
builder DescBuilder
|
||||
builder Builder
|
||||
allEnums []Enum
|
||||
allMessages []Message
|
||||
allExtensions []Extension
|
||||
allServices []Service
|
||||
}
|
||||
|
||||
func newRawFile(db DescBuilder) *File {
|
||||
func newRawFile(db Builder) *File {
|
||||
fd := &File{fileRaw: fileRaw{builder: db}}
|
||||
fd.initDecls(db.NumEnums, db.NumMessages, db.NumExtensions, db.NumServices)
|
||||
fd.unmarshalSeed(db.RawDescriptor)
|
||||
|
@ -678,7 +678,7 @@ func appendOptions(dst, src []byte) []byte {
|
||||
//
|
||||
// The type of message to unmarshal to is passed as a pointer since the
|
||||
// vars in descopts may not yet be populated at the time this function is called.
|
||||
func (db *DescBuilder) optionsUnmarshaler(p *pref.ProtoMessage, b []byte) func() pref.ProtoMessage {
|
||||
func (db *Builder) optionsUnmarshaler(p *pref.ProtoMessage, b []byte) func() pref.ProtoMessage {
|
||||
if b == nil {
|
||||
return nil
|
||||
}
|
||||
|
@ -198,14 +198,14 @@ func TestFile(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("proto.Marshal() error: %v", err)
|
||||
}
|
||||
fd2 := filedesc.DescBuilder{RawDescriptor: b}.Build().File
|
||||
fd2 := filedesc.Builder{RawDescriptor: b}.Build().File
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
desc pref.FileDescriptor
|
||||
}{
|
||||
{"protodesc.NewFile", fd1},
|
||||
{"filedesc.DescBuilder.Build", fd2},
|
||||
{"filedesc.Builder.Build", fd2},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
piface "google.golang.org/protobuf/runtime/protoiface"
|
||||
)
|
||||
|
||||
// TypeBuilder constructs type descriptors from a raw file descriptor
|
||||
// Builder constructs type descriptors from a raw file descriptor
|
||||
// and associated Go types for each enum and message declaration.
|
||||
//
|
||||
//
|
||||
@ -55,9 +55,9 @@ import (
|
||||
// The traversal starts at the root file descriptor and yields each direct
|
||||
// declaration within each node before traversing into sub-declarations
|
||||
// that children themselves may have.
|
||||
type TypeBuilder struct {
|
||||
type Builder struct {
|
||||
// File is the underlying file descriptor builder.
|
||||
File fdesc.DescBuilder
|
||||
File fdesc.Builder
|
||||
|
||||
// GoTypes is a unique set of the Go types for all declarations and
|
||||
// dependencies. Each type is represented as a zero value of the Go type.
|
||||
@ -116,7 +116,7 @@ type TypeBuilder struct {
|
||||
}
|
||||
}
|
||||
|
||||
func (tb TypeBuilder) Build() (out struct {
|
||||
func (tb Builder) Build() (out struct {
|
||||
File pref.FileDescriptor
|
||||
|
||||
// Enums is all enum types in "flattened ordering".
|
||||
|
@ -56,7 +56,7 @@ func legacyLoadFileDesc(b []byte) protoreflect.FileDescriptor {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fd := filedesc.DescBuilder{
|
||||
fd := filedesc.Builder{
|
||||
RawDescriptor: b2,
|
||||
FileRegistry: resolverOnly{protoregistry.GlobalFiles}, // do not register back to global registry
|
||||
}.Build().File
|
||||
|
@ -62,8 +62,8 @@ type (
|
||||
// being a compilation failure (guaranteed by the Go specification).
|
||||
EnforceVersion uint
|
||||
|
||||
DescBuilder = filedesc.DescBuilder
|
||||
TypeBuilder = filetype.TypeBuilder
|
||||
DescBuilder = filedesc.Builder
|
||||
TypeBuilder = filetype.Builder
|
||||
Pointer = impl.Pointer
|
||||
MessageInfo = impl.MessageInfo
|
||||
MessageState = impl.MessageState
|
||||
|
Loading…
x
Reference in New Issue
Block a user