aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Symonds <dsymonds@golang.org>2012-09-26 14:53:08 +1000
committerDavid Symonds <dsymonds@golang.org>2012-09-26 14:53:08 +1000
commit2bba1b298b2bf3139277f4d033014fe81320a3ba (patch)
tree1daf5010d263045d0355bbabd4f738297858c3ac
parent4de8f72751898421f0ebdb3662bbb1516e73f474 (diff)
downloadprotobuf-2bba1b298b2bf3139277f4d033014fe81320a3ba.tar.gz
goprotobuf: Rename some fields for clarity.
R=r CC=golang-dev http://codereview.appspot.com/6576047
-rw-r--r--proto/decode.go2
-rw-r--r--proto/lib.go2
-rw-r--r--proto/properties.go21
-rw-r--r--proto/text_parser.go2
4 files changed, 14 insertions, 13 deletions
diff --git a/proto/decode.go b/proto/decode.go
index a581917..4571d74 100644
--- a/proto/decode.go
+++ b/proto/decode.go
@@ -364,7 +364,7 @@ func (o *Buffer) unmarshalType(st reflect.Type, prop *StructProperties, is_group
if tag <= 0 {
return fmt.Errorf("proto: illegal tag %d", tag)
}
- fieldnum, ok := prop.tags.get(tag)
+ fieldnum, ok := prop.decoderTags.get(tag)
if !ok {
// Maybe it's an extension?
if prop.extendable {
diff --git a/proto/lib.go b/proto/lib.go
index 28f9fff..4b3f48e 100644
--- a/proto/lib.go
+++ b/proto/lib.go
@@ -697,7 +697,7 @@ type scalarField struct {
func buildDefaultMessage(t reflect.Type) (dm defaultMessage) {
sprop := GetProperties(t)
for _, prop := range sprop.Prop {
- fi, ok := sprop.tags.get(prop.Tag)
+ fi, ok := sprop.decoderTags.get(prop.Tag)
if !ok {
// XXX_unrecognized
continue
diff --git a/proto/properties.go b/proto/properties.go
index 9bad381..ce6b0d8 100644
--- a/proto/properties.go
+++ b/proto/properties.go
@@ -114,14 +114,15 @@ func (p *tagMap) put(t int, fi int) {
}
// StructProperties represents properties for all the fields of a struct.
+// decoderTags and decoderOrigNames should only be used by the decoder.
type StructProperties struct {
- Prop []*Properties // properties for each field
- reqCount int // required count
- tags tagMap // map from proto tag to struct field number
- origNames map[string]int // map from original name to struct field number
- order []int // list of struct field numbers in tag order
- unrecField field // field id of the XXX_unrecognized []byte field
- extendable bool // is this an extendable proto
+ Prop []*Properties // properties for each field
+ reqCount int // required count
+ decoderTags tagMap // map from proto tag to struct field number
+ decoderOrigNames map[string]int // map from original name to struct field number
+ order []int // list of struct field numbers in tag order
+ unrecField field // field id of the XXX_unrecognized []byte field
+ extendable bool // is this an extendable proto
}
// Implement the sorting interface so we can sort the fields in tag order, as recommended by the spec.
@@ -545,7 +546,7 @@ func getPropertiesLocked(t reflect.Type) *StructProperties {
// build required counts
// build tags
reqCount := 0
- prop.origNames = make(map[string]int)
+ prop.decoderOrigNames = make(map[string]int)
for i, p := range prop.Prop {
if strings.HasPrefix(p.Name, "XXX_") {
// Internal fields should not appear in tags/origNames maps.
@@ -555,8 +556,8 @@ func getPropertiesLocked(t reflect.Type) *StructProperties {
if p.Required {
reqCount++
}
- prop.tags.put(p.Tag, i)
- prop.origNames[p.OrigName] = i
+ prop.decoderTags.put(p.Tag, i)
+ prop.decoderOrigNames[p.OrigName] = i
}
prop.reqCount = reqCount
diff --git a/proto/text_parser.go b/proto/text_parser.go
index 1dff7cb..1f170bf 100644
--- a/proto/text_parser.go
+++ b/proto/text_parser.go
@@ -374,7 +374,7 @@ func (p *textParser) missingRequiredFieldError(sv reflect.Value) *ParseError {
// Returns the index in the struct for the named field, as well as the parsed tag properties.
func structFieldByName(st reflect.Type, name string) (int, *Properties, bool) {
sprops := GetProperties(st)
- i, ok := sprops.origNames[name]
+ i, ok := sprops.decoderOrigNames[name]
if ok {
return i, sprops.Prop[i], true
}