mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-01-30 21:32:43 +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"
|
preg "google.golang.org/protobuf/reflect/protoregistry"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DescBuilder construct a protoreflect.FileDescriptor from the raw descriptor.
|
// Builder construct a protoreflect.FileDescriptor from the raw descriptor.
|
||||||
type DescBuilder struct {
|
type Builder struct {
|
||||||
// GoPackagePath is the Go package path that is invoking this builder.
|
// GoPackagePath is the Go package path that is invoking this builder.
|
||||||
GoPackagePath string
|
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
|
// 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 {
|
type resolverByIndex interface {
|
||||||
FindEnumByIndex(int32, int32, []Enum, []Message) pref.EnumDescriptor
|
FindEnumByIndex(int32, int32, []Enum, []Message) pref.EnumDescriptor
|
||||||
FindMessageByIndex(int32, int32, []Enum, []Message) pref.MessageDescriptor
|
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 (
|
const (
|
||||||
listFieldDeps int32 = iota
|
listFieldDeps int32 = iota
|
||||||
listExtTargets
|
listExtTargets
|
||||||
@ -65,13 +65,13 @@ const (
|
|||||||
listMethOutDeps
|
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
|
// It assumes that the inputs are well-formed and panics if any inconsistencies
|
||||||
// are encountered.
|
// are encountered.
|
||||||
//
|
//
|
||||||
// If NumEnums+NumMessages+NumExtensions+NumServices is zero,
|
// If NumEnums+NumMessages+NumExtensions+NumServices is zero,
|
||||||
// then Build automatically derives them from the raw descriptor.
|
// then Build automatically derives them from the raw descriptor.
|
||||||
func (db DescBuilder) Build() (out struct {
|
func (db Builder) Build() (out struct {
|
||||||
File pref.FileDescriptor
|
File pref.FileDescriptor
|
||||||
|
|
||||||
// Enums is all enum descriptors in "flattened ordering".
|
// 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
|
// unmarshalCounts counts the number of enum, message, extension, and service
|
||||||
// declarations in the raw message, which is either a FileDescriptorProto
|
// declarations in the raw message, which is either a FileDescriptorProto
|
||||||
// or a MessageDescriptorProto depending on whether isFile is set.
|
// 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 {
|
for len(b) > 0 {
|
||||||
num, typ, n := wire.ConsumeTag(b)
|
num, typ, n := wire.ConsumeTag(b)
|
||||||
b = b[n:]
|
b = b[n:]
|
||||||
|
@ -16,14 +16,14 @@ import (
|
|||||||
// fileRaw is a data struct used when initializing a file descriptor from
|
// fileRaw is a data struct used when initializing a file descriptor from
|
||||||
// a raw FileDescriptorProto.
|
// a raw FileDescriptorProto.
|
||||||
type fileRaw struct {
|
type fileRaw struct {
|
||||||
builder DescBuilder
|
builder Builder
|
||||||
allEnums []Enum
|
allEnums []Enum
|
||||||
allMessages []Message
|
allMessages []Message
|
||||||
allExtensions []Extension
|
allExtensions []Extension
|
||||||
allServices []Service
|
allServices []Service
|
||||||
}
|
}
|
||||||
|
|
||||||
func newRawFile(db DescBuilder) *File {
|
func newRawFile(db Builder) *File {
|
||||||
fd := &File{fileRaw: fileRaw{builder: db}}
|
fd := &File{fileRaw: fileRaw{builder: db}}
|
||||||
fd.initDecls(db.NumEnums, db.NumMessages, db.NumExtensions, db.NumServices)
|
fd.initDecls(db.NumEnums, db.NumMessages, db.NumExtensions, db.NumServices)
|
||||||
fd.unmarshalSeed(db.RawDescriptor)
|
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
|
// 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.
|
// 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 {
|
if b == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -198,14 +198,14 @@ func TestFile(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("proto.Marshal() error: %v", err)
|
t.Fatalf("proto.Marshal() error: %v", err)
|
||||||
}
|
}
|
||||||
fd2 := filedesc.DescBuilder{RawDescriptor: b}.Build().File
|
fd2 := filedesc.Builder{RawDescriptor: b}.Build().File
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
desc pref.FileDescriptor
|
desc pref.FileDescriptor
|
||||||
}{
|
}{
|
||||||
{"protodesc.NewFile", fd1},
|
{"protodesc.NewFile", fd1},
|
||||||
{"filedesc.DescBuilder.Build", fd2},
|
{"filedesc.Builder.Build", fd2},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
tt := tt
|
tt := tt
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
piface "google.golang.org/protobuf/runtime/protoiface"
|
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.
|
// 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
|
// The traversal starts at the root file descriptor and yields each direct
|
||||||
// declaration within each node before traversing into sub-declarations
|
// declaration within each node before traversing into sub-declarations
|
||||||
// that children themselves may have.
|
// that children themselves may have.
|
||||||
type TypeBuilder struct {
|
type Builder struct {
|
||||||
// File is the underlying file descriptor builder.
|
// 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
|
// 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.
|
// 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
|
File pref.FileDescriptor
|
||||||
|
|
||||||
// Enums is all enum types in "flattened ordering".
|
// Enums is all enum types in "flattened ordering".
|
||||||
|
@ -56,7 +56,7 @@ func legacyLoadFileDesc(b []byte) protoreflect.FileDescriptor {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fd := filedesc.DescBuilder{
|
fd := filedesc.Builder{
|
||||||
RawDescriptor: b2,
|
RawDescriptor: b2,
|
||||||
FileRegistry: resolverOnly{protoregistry.GlobalFiles}, // do not register back to global registry
|
FileRegistry: resolverOnly{protoregistry.GlobalFiles}, // do not register back to global registry
|
||||||
}.Build().File
|
}.Build().File
|
||||||
|
@ -62,8 +62,8 @@ type (
|
|||||||
// being a compilation failure (guaranteed by the Go specification).
|
// being a compilation failure (guaranteed by the Go specification).
|
||||||
EnforceVersion uint
|
EnforceVersion uint
|
||||||
|
|
||||||
DescBuilder = filedesc.DescBuilder
|
DescBuilder = filedesc.Builder
|
||||||
TypeBuilder = filetype.TypeBuilder
|
TypeBuilder = filetype.Builder
|
||||||
Pointer = impl.Pointer
|
Pointer = impl.Pointer
|
||||||
MessageInfo = impl.MessageInfo
|
MessageInfo = impl.MessageInfo
|
||||||
MessageState = impl.MessageState
|
MessageState = impl.MessageState
|
||||||
|
Loading…
x
Reference in New Issue
Block a user