FAQ
Reviewers: r,

Message:
Hello r (cc: golang-dev@googlegroups.com),

I'd like you to review this change to
https://code.google.com/p/goprotobuf


Description:
goprotobuf: Track file and message indexes, and reserve Descriptor as a
message method name.

Please review this at http://codereview.appspot.com/6568051/

Affected files:
M protoc-gen-go/generator/generator.go


Index: protoc-gen-go/generator/generator.go
===================================================================
--- a/protoc-gen-go/generator/generator.go
+++ b/protoc-gen-go/generator/generator.go
@@ -103,6 +103,7 @@
nested []*Descriptor // Inner messages, if any.
ext []*ExtensionDescriptor // Extensions, if any.
typename []string // Cached typename vector.
+ index int // If a top-level message, the index into
message_type.
}

// TypeName returns the elements of the dotted type name.
@@ -645,8 +646,8 @@
}

// Construct the Descriptor and add it to the slice
-func addDescriptor(sl []*Descriptor, desc *descriptor.DescriptorProto,
parent *Descriptor, file *descriptor.FileDescriptorProto) []*Descriptor {
- d := &Descriptor{common{file}, desc, parent, nil, nil, nil}
+func addDescriptor(sl []*Descriptor, desc *descriptor.DescriptorProto,
parent *Descriptor, file *descriptor.FileDescriptorProto, index int)
[]*Descriptor {
+ d := &Descriptor{common{file}, desc, parent, nil, nil, nil, index}

d.ext = make([]*ExtensionDescriptor, len(desc.Extension))
for i, field := range desc.Extension {
@@ -659,18 +660,18 @@
// Return a slice of all the Descriptors defined within this file
func wrapDescriptors(file *descriptor.FileDescriptorProto) []*Descriptor {
sl := make([]*Descriptor, 0, len(file.MessageType)+10)
- for _, desc := range file.MessageType {
- sl = wrapThisDescriptor(sl, desc, nil, file)
+ for i, desc := range file.MessageType {
+ sl = wrapThisDescriptor(sl, desc, nil, file, i)
}
return sl
}

// Wrap this Descriptor, recursively
-func wrapThisDescriptor(sl []*Descriptor, desc
*descriptor.DescriptorProto, parent *Descriptor, file
*descriptor.FileDescriptorProto) []*Descriptor {
- sl = addDescriptor(sl, desc, parent, file)
+func wrapThisDescriptor(sl []*Descriptor, desc
*descriptor.DescriptorProto, parent *Descriptor, file
*descriptor.FileDescriptorProto, index int) []*Descriptor {
+ sl = addDescriptor(sl, desc, parent, file, index)
me := sl[len(sl)-1]
for _, nested := range desc.NestedType {
- sl = wrapThisDescriptor(sl, nested, me, file)
+ sl = wrapThisDescriptor(sl, nested, me, file, 0)
}
return sl
}
@@ -803,6 +804,8 @@
g.WriteString(fmt.Sprintf("%t", s))
case *bool:
g.WriteString(fmt.Sprintf("%t", *s))
+ case int:
+ g.WriteString(fmt.Sprintf("%d", s))
case *int32:
g.WriteString(fmt.Sprintf("%d", *s))
case float64:
@@ -1283,6 +1286,7 @@
"Unmarshal",
"ExtensionRangeArray",
"ExtensionMap",
+ "Descriptor",
}

// Generate the type and default constant definitions for this Descriptor.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedSep 26, '12 at 12:56a
activeSep 26, '12 at 3:51a
posts3
users2
websitegolang.org

2 users in discussion

Dsymonds: 2 posts R: 1 post

People

Translate

site design / logo © 2022 Grokbase