Переглянути джерело

goprotobuf: Make UnmarshalText reset the message before unmarshaling.

This is the expected behaviour, and matches Unmarshal.

R=r
CC=golang-dev
https://codereview.appspot.com/12449043
David Symonds 12 роки тому
батько
коміт
501f7db324
1 змінених файлів з 3 додано та 1 видалено
  1. 3 1
      proto/text_parser.go

+ 3 - 1
proto/text_parser.go

@@ -658,8 +658,10 @@ func (p *textParser) readAny(v reflect.Value, props *Properties) *ParseError {
 	return p.errorf("invalid %v: %v", v.Type(), tok.value)
 	return p.errorf("invalid %v: %v", v.Type(), tok.value)
 }
 }
 
 
-// UnmarshalText reads a protocol buffer in Text format.
+// UnmarshalText reads a protocol buffer in Text format. UnmarshalText resets pb
+// before starting to unmarshal, so any existing data in pb is always removed.
 func UnmarshalText(s string, pb Message) error {
 func UnmarshalText(s string, pb Message) error {
+	pb.Reset()
 	v := reflect.ValueOf(pb)
 	v := reflect.ValueOf(pb)
 	if pe := newTextParser(s).readStruct(v.Elem(), ""); pe != nil {
 	if pe := newTextParser(s).readStruct(v.Elem(), ""); pe != nil {
 		return pe
 		return pe