- // This can panic if v is not addressable, such as by passing an array of bytes by value. We
- // could copy them and make a slice to the copy, or the user could just avoid doing this. It
- // remains to be seen.
+ if v.Kind() != reflect.Slice {
+ // Can't use []byte optimization
+ if !v.CanAddr() {
+ e.writeStringPrefix(int64(v.Len()))
+ for i := 0; i < v.Len(); i++ {
+ var b [1]byte
+ b[0] = byte(v.Index(i).Uint())
+ e.write(b[:])
+ }
+ return
+ }
+ v = v.Slice(0, v.Len())
+ }