Browse Source

codec: encRawExt takes a RawExt, not a *RawExt.

The reflect.Value passed in on an encode is always dereferenced (never a pointer)
by the time the encFnInfo methods gets called.

Fix is to use the Addr if available, or get a new addressable value,
and pass that to EncodeRawExt of the Handle.

Fix #48
Ugorji Nwoke 11 years ago
parent
commit
a7bb9614b6
1 changed files with 10 additions and 1 deletions
  1. 10 1
      codec/encode.go

+ 10 - 1
codec/encode.go

@@ -269,7 +269,16 @@ func (f encFnInfo) builtin(rv reflect.Value) {
 }
 }
 
 
 func (f encFnInfo) rawExt(rv reflect.Value) {
 func (f encFnInfo) rawExt(rv reflect.Value) {
-	f.ee.EncodeRawExt(rv.Interface().(*RawExt), f.e)
+	// rev := rv.Interface().(RawExt)
+	// f.ee.EncodeRawExt(&rev, f.e)
+	var re *RawExt
+	if rv.CanAddr() {
+		re = rv.Addr().Interface().(*RawExt)
+	} else {
+		rev := rv.Interface().(RawExt)
+		re = &rev
+	}
+	f.ee.EncodeRawExt(re, f.e)
 }
 }
 
 
 func (f encFnInfo) ext(rv reflect.Value) {
 func (f encFnInfo) ext(rv reflect.Value) {