Browse Source

codec: codecgen: array types should have Selfer implementations take a pointer receiver

Also, fix inherent there.

Fixes #214
Ugorji Nwoke 8 years ago
parent
commit
ee76062291
1 changed files with 3 additions and 3 deletions
  1. 3 3
      codec/gen.go

+ 3 - 3
codec/gen.go

@@ -504,7 +504,7 @@ func (x *genRunner) selfer(encode bool) {
 	t0 := t
 	// always make decode use a pointer receiver,
 	// and structs always use a ptr receiver (encode|decode)
-	isptr := !encode || t.Kind() == reflect.Struct
+	isptr := !encode || (t.Kind() == reflect.Struct || t.Kind() == reflect.Array)
 	x.varsfxreset()
 	fnSigPfx := "func (x "
 	if isptr {
@@ -999,7 +999,7 @@ func (x *genRunner) encListFallback(varname string, t reflect.Type) {
 		return
 	}
 	if t.Kind() == reflect.Array && t.Elem().Kind() == reflect.Uint8 {
-		x.linef("r.EncodeStringBytes(codecSelferC_RAW%s, ([%v]byte(%s))[:])", x.xs, t.Len(), varname)
+		x.linef("r.EncodeStringBytes(codecSelferC_RAW%s, ((*[%d]byte)(%s))[:])", x.xs, t.Len(), varname)
 		return
 	}
 	i := x.varsfx()
@@ -1332,7 +1332,7 @@ func (x *genRunner) decListFallback(varname string, rtid uintptr, t reflect.Type
 		return
 	}
 	if t.Kind() == reflect.Array && t.Elem().Kind() == reflect.Uint8 {
-		x.linef("r.DecodeBytes( ((*[%s]byte)(%s))[:], true)", t.Len(), varname)
+		x.linef("r.DecodeBytes( ((*[%d]byte)(%s))[:], true)", t.Len(), varname)
 		return
 	}
 	type tstruc struct {