Browse Source

goprotobuf: gofixes for reflect API changes.

R=dsymonds
CC=golang-dev
http://codereview.appspot.com/4425077
Nigel Tao 15 years ago
parent
commit
4ede8453f5
5 changed files with 12 additions and 12 deletions
  1. 2 2
      proto/encode.go
  2. 6 6
      proto/extensions.go
  3. 1 1
      proto/properties.go
  4. 1 1
      proto/text.go
  5. 2 2
      proto/text_parser.go

+ 2 - 2
proto/encode.go

@@ -303,7 +303,7 @@ func (o *Buffer) enc_struct_message(p *Properties, base uintptr) os.Error {
 	// Can the object marshal itself?
 	iv := unsafe.Unreflect(p.stype, unsafe.Pointer(base+p.offset))
 	if m, ok := iv.(Marshaler); ok {
-		if isNil(reflect.NewValue(iv)) {
+		if isNil(reflect.ValueOf(iv)) {
 			return ErrNil
 		}
 		data, err := m.Marshal()
@@ -514,7 +514,7 @@ func (o *Buffer) enc_slice_struct_message(p *Properties, base uintptr) os.Error
 		// Can the object marshal itself?
 		iv := unsafe.Unreflect(p.stype, unsafe.Pointer(&s[i]))
 		if m, ok := iv.(Marshaler); ok {
-			if reflect.NewValue(iv).IsNil() {
+			if reflect.ValueOf(iv).IsNil() {
 				return ErrNil
 			}
 			data, err := m.Marshal()

+ 6 - 6
proto/extensions.go

@@ -76,7 +76,7 @@ func isExtensionField(pb extendableProto, field int32) bool {
 // checkExtensionTypes checks that the given extension is valid for pb.
 func checkExtensionTypes(pb extendableProto, extension *ExtensionDesc) os.Error {
 	// Check the extended type.
-	if a, b := reflect.Typeof(pb), reflect.Typeof(extension.ExtendedType); a != b {
+	if a, b := reflect.TypeOf(pb), reflect.TypeOf(extension.ExtendedType); a != b {
 		return os.NewError("bad extended type; " + b.String() + " does not extend " + a.String())
 	}
 	// Check the range.
@@ -115,7 +115,7 @@ func GetExtension(pb extendableProto, extension *ExtensionDesc) (interface{}, os
 	_, n := DecodeVarint(b)
 	o := NewBuffer(b[n:])
 
-	t := reflect.Typeof(extension.ExtensionType)
+	t := reflect.TypeOf(extension.ExtensionType)
 	props := &Properties{}
 	props.Init(t, "irrelevant_name", extension.Tag, 0)
 
@@ -160,19 +160,19 @@ func SetExtension(pb extendableProto, extension *ExtensionDesc, value interface{
 	if err := checkExtensionTypes(pb, extension); err != nil {
 		return err
 	}
-	typ := reflect.Typeof(extension.ExtensionType)
-	if typ != reflect.Typeof(value) {
+	typ := reflect.TypeOf(extension.ExtensionType)
+	if typ != reflect.TypeOf(value) {
 		return os.NewError("bad extension value type")
 	}
 
 	props := new(Properties)
-	props.Init(reflect.Typeof(extension.ExtensionType), "unknown_name", extension.Tag, 0)
+	props.Init(reflect.TypeOf(extension.ExtensionType), "unknown_name", extension.Tag, 0)
 
 	p := NewBuffer(nil)
 	// The encoder must be passed a pointer to value.
 	// Allocate a copy of value so that we can use its address.
 	x := reflect.New(typ)
-	x.Elem().Set(reflect.NewValue(value))
+	x.Elem().Set(reflect.ValueOf(value))
 	if err := props.enc(p, props, x.Pointer()); err != nil {
 		return err
 	}

+ 1 - 1
proto/properties.go

@@ -531,7 +531,7 @@ func getbase(pb interface{}) (t reflect.Type, b uintptr, err os.Error) {
 	}
 
 	// get the reflect type of the struct.
-	t = reflect.Typeof(pb)
+	t = reflect.TypeOf(pb)
 	return
 }
 

+ 1 - 1
proto/text.go

@@ -198,7 +198,7 @@ func marshalText(w io.Writer, pb interface{}, compact bool) {
 	aw.complete = true
 	aw.compact = compact
 
-	v := reflect.NewValue(pb)
+	v := reflect.ValueOf(pb)
 	// We should normally be passed a struct, or a pointer to a struct,
 	// and we don't want the outer < and > in that case.
 	v = reflect.Indirect(v)

+ 2 - 2
proto/text_parser.go

@@ -356,7 +356,7 @@ func (p *textParser) readAny(v reflect.Value, props *Properties) *ParseError {
 				return p.errorf("invalid string: %v", tok.value)
 			}
 			bytes := []byte(tok.unquoted)
-			fv.Set(reflect.NewValue(bytes))
+			fv.Set(reflect.ValueOf(bytes))
 			return nil
 		}
 		// Repeated field. May already exist.
@@ -448,7 +448,7 @@ var notPtrStruct os.Error = &ParseError{"destination is not a pointer to a struc
 
 // UnmarshalText reads a protobuffer in Text format.
 func UnmarshalText(s string, pb interface{}) os.Error {
-	v := reflect.NewValue(pb)
+	v := reflect.ValueOf(pb)
 	if v.Kind() != reflect.Ptr || v.Elem().Kind() != reflect.Struct {
 		return notPtrStruct
 	}