Explorar el Código

goprotobuf: Rename some fields for clarity.

R=r
CC=golang-dev
http://codereview.appspot.com/6576047
David Symonds hace 13 años
padre
commit
2bba1b298b
Se han modificado 4 ficheros con 14 adiciones y 13 borrados
  1. 1 1
      proto/decode.go
  2. 1 1
      proto/lib.go
  3. 11 10
      proto/properties.go
  4. 1 1
      proto/text_parser.go

+ 1 - 1
proto/decode.go

@@ -364,7 +364,7 @@ func (o *Buffer) unmarshalType(st reflect.Type, prop *StructProperties, is_group
 		if tag <= 0 {
 		if tag <= 0 {
 			return fmt.Errorf("proto: illegal tag %d", tag)
 			return fmt.Errorf("proto: illegal tag %d", tag)
 		}
 		}
-		fieldnum, ok := prop.tags.get(tag)
+		fieldnum, ok := prop.decoderTags.get(tag)
 		if !ok {
 		if !ok {
 			// Maybe it's an extension?
 			// Maybe it's an extension?
 			if prop.extendable {
 			if prop.extendable {

+ 1 - 1
proto/lib.go

@@ -697,7 +697,7 @@ type scalarField struct {
 func buildDefaultMessage(t reflect.Type) (dm defaultMessage) {
 func buildDefaultMessage(t reflect.Type) (dm defaultMessage) {
 	sprop := GetProperties(t)
 	sprop := GetProperties(t)
 	for _, prop := range sprop.Prop {
 	for _, prop := range sprop.Prop {
-		fi, ok := sprop.tags.get(prop.Tag)
+		fi, ok := sprop.decoderTags.get(prop.Tag)
 		if !ok {
 		if !ok {
 			// XXX_unrecognized
 			// XXX_unrecognized
 			continue
 			continue

+ 11 - 10
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.
 // StructProperties represents properties for all the fields of a struct.
+// decoderTags and decoderOrigNames should only be used by the decoder.
 type StructProperties struct {
 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.
 // 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 required counts
 	// build tags
 	// build tags
 	reqCount := 0
 	reqCount := 0
-	prop.origNames = make(map[string]int)
+	prop.decoderOrigNames = make(map[string]int)
 	for i, p := range prop.Prop {
 	for i, p := range prop.Prop {
 		if strings.HasPrefix(p.Name, "XXX_") {
 		if strings.HasPrefix(p.Name, "XXX_") {
 			// Internal fields should not appear in tags/origNames maps.
 			// Internal fields should not appear in tags/origNames maps.
@@ -555,8 +556,8 @@ func getPropertiesLocked(t reflect.Type) *StructProperties {
 		if p.Required {
 		if p.Required {
 			reqCount++
 			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
 	prop.reqCount = reqCount
 
 

+ 1 - 1
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.
 // 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) {
 func structFieldByName(st reflect.Type, name string) (int, *Properties, bool) {
 	sprops := GetProperties(st)
 	sprops := GetProperties(st)
-	i, ok := sprops.origNames[name]
+	i, ok := sprops.decoderOrigNames[name]
 	if ok {
 	if ok {
 		return i, sprops.Prop[i], true
 		return i, sprops.Prop[i], true
 	}
 	}