Skip to content

Commit

Permalink
internal/filedesc, internal/filetype: rename {Desc,Type}Builder as Bu…
Browse files Browse the repository at this point in the history
…ilder

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 <[email protected]>
  • Loading branch information
dsnet committed Aug 5, 2019
1 parent 954bd92 commit 52ec175
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
16 changes: 8 additions & 8 deletions internal/filedesc/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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".
Expand Down Expand Up @@ -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:]
Expand Down
4 changes: 2 additions & 2 deletions internal/filedesc/desc_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/filedesc/desc_lazy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions internal/filedesc/desc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions internal/filetype/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
//
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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".
Expand Down
2 changes: 1 addition & 1 deletion internal/impl/legacy_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions runtime/protoimpl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 52ec175

Please sign in to comment.