Browse Source

codec: helper_(not_)?unsafe.go has generic helper functions

Previously, *Encoder.kXXX and *Decoder.kXXX were in the helper_unsafe.go
and helper_not_unsafe.go files.

Now, those files just have helper functions and kXXX is moved to encode.go
and decode.go.
Ugorji Nwoke 6 years ago
parent
commit
880afd579f
4 changed files with 278 additions and 154 deletions
  1. 68 0
      codec/decode.go
  2. 76 0
      codec/encode.go
  3. 68 72
      codec/helper_not_unsafe.go
  4. 66 82
      codec/helper_unsafe.go

+ 68 - 0
codec/decode.go

@@ -336,6 +336,74 @@ func (d *Decoder) kErr(f *codecFnInfo, rv reflect.Value) {
 	d.errorf("no decoding function defined for kind %v", rv.Kind())
 }
 
+func (d *Decoder) raw(f *codecFnInfo, rv reflect.Value) {
+	rvSetBytes(rv, d.rawBytes())
+}
+
+func (d *Decoder) kString(f *codecFnInfo, rv reflect.Value) {
+	rvSetString(rv, string(d.d.DecodeStringAsBytes()))
+}
+
+func (d *Decoder) kBool(f *codecFnInfo, rv reflect.Value) {
+	rvSetBool(rv, d.d.DecodeBool())
+}
+
+func (d *Decoder) kTime(f *codecFnInfo, rv reflect.Value) {
+	rvSetTime(rv, d.d.DecodeTime())
+}
+
+func (d *Decoder) kFloat32(f *codecFnInfo, rv reflect.Value) {
+	rvSetFloat32(rv, d.decodeFloat32())
+}
+
+func (d *Decoder) kFloat64(f *codecFnInfo, rv reflect.Value) {
+	rvSetFloat64(rv, d.d.DecodeFloat64())
+}
+
+func (d *Decoder) kInt(f *codecFnInfo, rv reflect.Value) {
+	rvSetInt(rv, int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)))
+}
+
+func (d *Decoder) kInt8(f *codecFnInfo, rv reflect.Value) {
+	rvSetInt8(rv, int8(chkOvf.IntV(d.d.DecodeInt64(), 8)))
+}
+
+func (d *Decoder) kInt16(f *codecFnInfo, rv reflect.Value) {
+	rvSetInt16(rv, int16(chkOvf.IntV(d.d.DecodeInt64(), 16)))
+}
+
+func (d *Decoder) kInt32(f *codecFnInfo, rv reflect.Value) {
+	rvSetInt32(rv, int32(chkOvf.IntV(d.d.DecodeInt64(), 32)))
+}
+
+func (d *Decoder) kInt64(f *codecFnInfo, rv reflect.Value) {
+	rvSetInt64(rv, d.d.DecodeInt64())
+}
+
+func (d *Decoder) kUint(f *codecFnInfo, rv reflect.Value) {
+	rvSetUint(rv, uint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize)))
+}
+
+func (d *Decoder) kUintptr(f *codecFnInfo, rv reflect.Value) {
+	rvSetUintptr(rv, uintptr(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize)))
+}
+
+func (d *Decoder) kUint8(f *codecFnInfo, rv reflect.Value) {
+	rvSetUint8(rv, uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)))
+}
+
+func (d *Decoder) kUint16(f *codecFnInfo, rv reflect.Value) {
+	rvSetUint16(rv, uint16(chkOvf.UintV(d.d.DecodeUint64(), 16)))
+}
+
+func (d *Decoder) kUint32(f *codecFnInfo, rv reflect.Value) {
+	rvSetUint32(rv, uint32(chkOvf.UintV(d.d.DecodeUint64(), 32)))
+}
+
+func (d *Decoder) kUint64(f *codecFnInfo, rv reflect.Value) {
+	rvSetUint64(rv, d.d.DecodeUint64())
+}
+
 // var kIntfCtr uint64
 
 func (d *Decoder) kInterfaceNaked(f *codecFnInfo) (rvn reflect.Value) {

+ 76 - 0
codec/encode.go

@@ -208,6 +208,22 @@ func (e *Encoder) raw(f *codecFnInfo, rv reflect.Value) {
 	e.rawBytes(rv2i(rv).(Raw))
 }
 
+func (e *Encoder) kBool(f *codecFnInfo, rv reflect.Value) {
+	e.e.EncodeBool(rvGetBool(rv))
+}
+
+func (e *Encoder) kTime(f *codecFnInfo, rv reflect.Value) {
+	e.e.EncodeTime(rvGetTime(rv))
+}
+
+func (e *Encoder) kString(f *codecFnInfo, rv reflect.Value) {
+	if e.h.StringToRaw {
+		e.e.EncodeStringBytesRaw(bytesView(rvGetString(rv)))
+	} else {
+		e.e.EncodeStringEnc(cUTF8, rvGetString(rv))
+	}
+}
+
 // func (e *Encoder) kString(f *codecFnInfo, rv reflect.Value) {
 // 	if e.h.StringToRaw {
 // 		e.kStringToRaw(f, rv)
@@ -216,6 +232,66 @@ func (e *Encoder) raw(f *codecFnInfo, rv reflect.Value) {
 // 	}
 // }
 
+// func (e *Encoder) kStringToRaw(f *codecFnInfo, rv reflect.Value) {
+// 	e.e.EncodeStringBytesRaw(bytesView(rvGetString(rv)))
+// }
+
+// func (e *Encoder) kStringEnc(f *codecFnInfo, rv reflect.Value) {
+// 	e.e.EncodeStringEnc(cUTF8, rvGetString(rv))
+// }
+
+func (e *Encoder) kFloat64(f *codecFnInfo, rv reflect.Value) {
+	e.e.EncodeFloat64(rvGetFloat64(rv))
+}
+
+func (e *Encoder) kFloat32(f *codecFnInfo, rv reflect.Value) {
+	e.e.EncodeFloat32(rvGetFloat32(rv))
+}
+
+func (e *Encoder) kInt(f *codecFnInfo, rv reflect.Value) {
+	e.e.EncodeInt(int64(rvGetInt(rv)))
+}
+
+func (e *Encoder) kInt8(f *codecFnInfo, rv reflect.Value) {
+	e.e.EncodeInt(int64(rvGetInt8(rv)))
+}
+
+func (e *Encoder) kInt16(f *codecFnInfo, rv reflect.Value) {
+	e.e.EncodeInt(int64(rvGetInt16(rv)))
+}
+
+func (e *Encoder) kInt32(f *codecFnInfo, rv reflect.Value) {
+	e.e.EncodeInt(int64(rvGetInt32(rv)))
+}
+
+func (e *Encoder) kInt64(f *codecFnInfo, rv reflect.Value) {
+	e.e.EncodeInt(int64(rvGetInt64(rv)))
+}
+
+func (e *Encoder) kUint(f *codecFnInfo, rv reflect.Value) {
+	e.e.EncodeUint(uint64(rvGetUint(rv)))
+}
+
+func (e *Encoder) kUint8(f *codecFnInfo, rv reflect.Value) {
+	e.e.EncodeUint(uint64(rvGetUint8(rv)))
+}
+
+func (e *Encoder) kUint16(f *codecFnInfo, rv reflect.Value) {
+	e.e.EncodeUint(uint64(rvGetUint16(rv)))
+}
+
+func (e *Encoder) kUint32(f *codecFnInfo, rv reflect.Value) {
+	e.e.EncodeUint(uint64(rvGetUint32(rv)))
+}
+
+func (e *Encoder) kUint64(f *codecFnInfo, rv reflect.Value) {
+	e.e.EncodeUint(uint64(rvGetUint64(rv)))
+}
+
+func (e *Encoder) kUintptr(f *codecFnInfo, rv reflect.Value) {
+	e.e.EncodeUint(uint64(rvGetUintptr(rv)))
+}
+
 func (e *Encoder) kInvalid(f *codecFnInfo, rv reflect.Value) {
 	e.e.EncodeNil()
 }

+ 68 - 72
codec/helper_not_unsafe.go

@@ -198,150 +198,146 @@ func (n *decNaked) rb() reflect.Value {
 }
 
 // --------------------------
-func (d *Decoder) raw(f *codecFnInfo, rv reflect.Value) {
-	rv.SetBytes(d.rawBytes())
+func rvSetBytes(rv reflect.Value, v []byte) {
+	rv.SetBytes(v)
 }
 
-func (d *Decoder) kString(f *codecFnInfo, rv reflect.Value) {
-	rv.SetString(string(d.d.DecodeStringAsBytes()))
+func rvSetString(rv reflect.Value, v string) {
+	rv.SetString(v)
 }
 
-func (d *Decoder) kBool(f *codecFnInfo, rv reflect.Value) {
-	rv.SetBool(d.d.DecodeBool())
+func rvSetBool(rv reflect.Value, v bool) {
+	rv.SetBool(v)
 }
 
-func (d *Decoder) kTime(f *codecFnInfo, rv reflect.Value) {
-	rv.Set(reflect.ValueOf(d.d.DecodeTime()))
+func rvSetTime(rv reflect.Value, v time.Time) {
+	rv.Set(reflect.ValueOf(v))
 }
 
-func (d *Decoder) kFloat32(f *codecFnInfo, rv reflect.Value) {
-	rv.SetFloat(float64(d.decodeFloat32()))
+func rvSetFloat32(rv reflect.Value, v float32) {
+	rv.SetFloat(float64(v))
 }
 
-func (d *Decoder) kFloat64(f *codecFnInfo, rv reflect.Value) {
-	rv.SetFloat(d.d.DecodeFloat64())
+func rvSetFloat64(rv reflect.Value, v float64) {
+	rv.SetFloat(v)
 }
 
-func (d *Decoder) kInt(f *codecFnInfo, rv reflect.Value) {
-	rv.SetInt(chkOvf.IntV(d.d.DecodeInt64(), intBitsize))
+func rvSetInt(rv reflect.Value, v int) {
+	rv.SetInt(int64(v))
 }
 
-func (d *Decoder) kInt8(f *codecFnInfo, rv reflect.Value) {
-	rv.SetInt(chkOvf.IntV(d.d.DecodeInt64(), 8))
+func rvSetInt8(rv reflect.Value, v int8) {
+	rv.SetInt(int64(v))
 }
 
-func (d *Decoder) kInt16(f *codecFnInfo, rv reflect.Value) {
-	rv.SetInt(chkOvf.IntV(d.d.DecodeInt64(), 16))
+func rvSetInt16(rv reflect.Value, v int16) {
+	rv.SetInt(int64(v))
 }
 
-func (d *Decoder) kInt32(f *codecFnInfo, rv reflect.Value) {
-	rv.SetInt(chkOvf.IntV(d.d.DecodeInt64(), 32))
+func rvSetInt32(rv reflect.Value, v int32) {
+	rv.SetInt(int64(v))
 }
 
-func (d *Decoder) kInt64(f *codecFnInfo, rv reflect.Value) {
-	rv.SetInt(d.d.DecodeInt64())
+func rvSetInt64(rv reflect.Value, v int64) {
+	rv.SetInt(v)
 }
 
-func (d *Decoder) kUint(f *codecFnInfo, rv reflect.Value) {
-	rv.SetUint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))
+func rvSetUint(rv reflect.Value, v uint) {
+	rv.SetUint(uint64(v))
 }
 
-func (d *Decoder) kUintptr(f *codecFnInfo, rv reflect.Value) {
-	rv.SetUint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))
+func rvSetUintptr(rv reflect.Value, v uintptr) {
+	rv.SetUint(uint64(v))
 }
 
-func (d *Decoder) kUint8(f *codecFnInfo, rv reflect.Value) {
-	rv.SetUint(chkOvf.UintV(d.d.DecodeUint64(), 8))
+func rvSetUint8(rv reflect.Value, v uint8) {
+	rv.SetUint(uint64(v))
 }
 
-func (d *Decoder) kUint16(f *codecFnInfo, rv reflect.Value) {
-	rv.SetUint(chkOvf.UintV(d.d.DecodeUint64(), 16))
+func rvSetUint16(rv reflect.Value, v uint16) {
+	rv.SetUint(uint64(v))
 }
 
-func (d *Decoder) kUint32(f *codecFnInfo, rv reflect.Value) {
-	rv.SetUint(chkOvf.UintV(d.d.DecodeUint64(), 32))
+func rvSetUint32(rv reflect.Value, v uint32) {
+	rv.SetUint(uint64(v))
 }
 
-func (d *Decoder) kUint64(f *codecFnInfo, rv reflect.Value) {
-	rv.SetUint(d.d.DecodeUint64())
+func rvSetUint64(rv reflect.Value, v uint64) {
+	rv.SetUint(v)
 }
 
 // ----------------
 
-func (e *Encoder) kBool(f *codecFnInfo, rv reflect.Value) {
-	e.e.EncodeBool(rv.Bool())
+func rvGetBool(rv reflect.Value) bool {
+	return rv.Bool()
 }
 
-func (e *Encoder) kTime(f *codecFnInfo, rv reflect.Value) {
-	e.e.EncodeTime(rv2i(rv).(time.Time))
+func rvGetTime(rv reflect.Value) time.Time {
+	return rv2i(rv).(time.Time)
 }
 
-func (e *Encoder) kString(f *codecFnInfo, rv reflect.Value) {
-	if e.h.StringToRaw {
-		e.e.EncodeStringBytesRaw(bytesView(rv.String()))
-	} else {
-		e.e.EncodeStringEnc(cUTF8, rv.String())
-	}
+func rvGetString(rv reflect.Value) string {
+	return rv.String()
 }
 
-// func (e *Encoder) kStringToRaw(f *codecFnInfo, rv reflect.Value) {
+// func rvGetStringToRaw(rv reflect.Value) {
 // 	e.e.EncodeStringBytesRaw(bytesView(rv.String()))
 // }
 
-// func (e *Encoder) kStringEnc(f *codecFnInfo, rv reflect.Value) {
+// func rvGetStringEnc(rv reflect.Value) {
 // 	e.e.EncodeStringEnc(cUTF8, rv.String())
 // }
 
-func (e *Encoder) kFloat64(f *codecFnInfo, rv reflect.Value) {
-	e.e.EncodeFloat64(rv.Float())
+func rvGetFloat64(rv reflect.Value) float64 {
+	return rv.Float()
 }
 
-func (e *Encoder) kFloat32(f *codecFnInfo, rv reflect.Value) {
-	e.e.EncodeFloat32(float32(rv.Float()))
+func rvGetFloat32(rv reflect.Value) float32 {
+	return float32(rv.Float())
 }
 
-func (e *Encoder) kInt(f *codecFnInfo, rv reflect.Value) {
-	e.e.EncodeInt(rv.Int())
+func rvGetInt(rv reflect.Value) int {
+	return int(rv.Int())
 }
 
-func (e *Encoder) kInt8(f *codecFnInfo, rv reflect.Value) {
-	e.e.EncodeInt(rv.Int())
+func rvGetInt8(rv reflect.Value) int8 {
+	return int8(rv.Int())
 }
 
-func (e *Encoder) kInt16(f *codecFnInfo, rv reflect.Value) {
-	e.e.EncodeInt(rv.Int())
+func rvGetInt16(rv reflect.Value) int16 {
+	return int16(rv.Int())
 }
 
-func (e *Encoder) kInt32(f *codecFnInfo, rv reflect.Value) {
-	e.e.EncodeInt(rv.Int())
+func rvGetInt32(rv reflect.Value) int32 {
+	return int32(rv.Int())
 }
 
-func (e *Encoder) kInt64(f *codecFnInfo, rv reflect.Value) {
-	e.e.EncodeInt(rv.Int())
+func rvGetInt64(rv reflect.Value) int64 {
+	return rv.Int()
 }
 
-func (e *Encoder) kUint(f *codecFnInfo, rv reflect.Value) {
-	e.e.EncodeUint(rv.Uint())
+func rvGetUint(rv reflect.Value) uint {
+	return uint(rv.Uint())
 }
 
-func (e *Encoder) kUint8(f *codecFnInfo, rv reflect.Value) {
-	e.e.EncodeUint(rv.Uint())
+func rvGetUint8(rv reflect.Value) uint8 {
+	return uint8(rv.Uint())
 }
 
-func (e *Encoder) kUint16(f *codecFnInfo, rv reflect.Value) {
-	e.e.EncodeUint(rv.Uint())
+func rvGetUint16(rv reflect.Value) uint16 {
+	return uint16(rv.Uint())
 }
 
-func (e *Encoder) kUint32(f *codecFnInfo, rv reflect.Value) {
-	e.e.EncodeUint(rv.Uint())
+func rvGetUint32(rv reflect.Value) uint32 {
+	return uint32(rv.Uint())
 }
 
-func (e *Encoder) kUint64(f *codecFnInfo, rv reflect.Value) {
-	e.e.EncodeUint(rv.Uint())
+func rvGetUint64(rv reflect.Value) uint64 {
+	return rv.Uint()
 }
 
-func (e *Encoder) kUintptr(f *codecFnInfo, rv reflect.Value) {
-	e.e.EncodeUint(rv.Uint())
+func rvGetUintptr(rv reflect.Value) uintptr {
+	return uintptr(rv.Uint())
 }
 
 // ------------ map range and map indexing ----------

+ 66 - 82
codec/helper_unsafe.go

@@ -389,187 +389,171 @@ func (n *decNaked) rb() (v reflect.Value) {
 }
 
 // --------------------------
-func (d *Decoder) raw(f *codecFnInfo, rv reflect.Value) {
+func rvSetBytes(rv reflect.Value, v []byte) {
 	urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	*(*[]byte)(urv.ptr) = d.rawBytes()
+	*(*[]byte)(urv.ptr) = v
 }
 
-func (d *Decoder) kString(f *codecFnInfo, rv reflect.Value) {
+func rvSetString(rv reflect.Value, v string) {
 	urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	*(*string)(urv.ptr) = string(d.d.DecodeStringAsBytes())
+	*(*string)(urv.ptr) = v
 }
 
-func (d *Decoder) kBool(f *codecFnInfo, rv reflect.Value) {
+func rvSetBool(rv reflect.Value, v bool) {
 	urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	*(*bool)(urv.ptr) = d.d.DecodeBool()
+	*(*bool)(urv.ptr) = v
 }
 
-func (d *Decoder) kTime(f *codecFnInfo, rv reflect.Value) {
+func rvSetTime(rv reflect.Value, v time.Time) {
 	urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	*(*time.Time)(urv.ptr) = d.d.DecodeTime()
+	*(*time.Time)(urv.ptr) = v
 }
 
-func (d *Decoder) kFloat32(f *codecFnInfo, rv reflect.Value) {
+func rvSetFloat32(rv reflect.Value, v float32) {
 	urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	*(*float32)(urv.ptr) = d.decodeFloat32()
+	*(*float32)(urv.ptr) = v
 }
 
-func (d *Decoder) kFloat64(f *codecFnInfo, rv reflect.Value) {
+func rvSetFloat64(rv reflect.Value, v float64) {
 	urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	*(*float64)(urv.ptr) = d.d.DecodeFloat64()
+	*(*float64)(urv.ptr) = v
 }
 
-func (d *Decoder) kInt(f *codecFnInfo, rv reflect.Value) {
+func rvSetInt(rv reflect.Value, v int) {
 	urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	*(*int)(urv.ptr) = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize))
+	*(*int)(urv.ptr) = v
 }
 
-func (d *Decoder) kInt8(f *codecFnInfo, rv reflect.Value) {
+func rvSetInt8(rv reflect.Value, v int8) {
 	urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	*(*int8)(urv.ptr) = int8(chkOvf.IntV(d.d.DecodeInt64(), 8))
+	*(*int8)(urv.ptr) = v
 }
 
-func (d *Decoder) kInt16(f *codecFnInfo, rv reflect.Value) {
+func rvSetInt16(rv reflect.Value, v int16) {
 	urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	*(*int16)(urv.ptr) = int16(chkOvf.IntV(d.d.DecodeInt64(), 16))
+	*(*int16)(urv.ptr) = v
 }
 
-func (d *Decoder) kInt32(f *codecFnInfo, rv reflect.Value) {
+func rvSetInt32(rv reflect.Value, v int32) {
 	urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	*(*int32)(urv.ptr) = int32(chkOvf.IntV(d.d.DecodeInt64(), 32))
+	*(*int32)(urv.ptr) = v
 }
 
-func (d *Decoder) kInt64(f *codecFnInfo, rv reflect.Value) {
+func rvSetInt64(rv reflect.Value, v int64) {
 	urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	*(*int64)(urv.ptr) = d.d.DecodeInt64()
+	*(*int64)(urv.ptr) = v
 }
 
-func (d *Decoder) kUint(f *codecFnInfo, rv reflect.Value) {
+func rvSetUint(rv reflect.Value, v uint) {
 	urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	*(*uint)(urv.ptr) = uint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))
+	*(*uint)(urv.ptr) = v
 }
 
-func (d *Decoder) kUintptr(f *codecFnInfo, rv reflect.Value) {
+func rvSetUintptr(rv reflect.Value, v uintptr) {
 	urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	*(*uintptr)(urv.ptr) = uintptr(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))
+	*(*uintptr)(urv.ptr) = v
 }
 
-func (d *Decoder) kUint8(f *codecFnInfo, rv reflect.Value) {
+func rvSetUint8(rv reflect.Value, v uint8) {
 	urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	*(*uint8)(urv.ptr) = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8))
+	*(*uint8)(urv.ptr) = v
 }
 
-func (d *Decoder) kUint16(f *codecFnInfo, rv reflect.Value) {
+func rvSetUint16(rv reflect.Value, v uint16) {
 	urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	*(*uint16)(urv.ptr) = uint16(chkOvf.UintV(d.d.DecodeUint64(), 16))
+	*(*uint16)(urv.ptr) = v
 }
 
-func (d *Decoder) kUint32(f *codecFnInfo, rv reflect.Value) {
+func rvSetUint32(rv reflect.Value, v uint32) {
 	urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	*(*uint32)(urv.ptr) = uint32(chkOvf.UintV(d.d.DecodeUint64(), 32))
+	*(*uint32)(urv.ptr) = v
 }
 
-func (d *Decoder) kUint64(f *codecFnInfo, rv reflect.Value) {
+func rvSetUint64(rv reflect.Value, v uint64) {
 	urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	*(*uint64)(urv.ptr) = d.d.DecodeUint64()
+	*(*uint64)(urv.ptr) = v
 }
 
 // ------------
 
-func (e *Encoder) kBool(f *codecFnInfo, rv reflect.Value) {
+func rvGetBool(rv reflect.Value) bool {
 	v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	e.e.EncodeBool(*(*bool)(v.ptr))
+	return *(*bool)(v.ptr)
 }
 
-func (e *Encoder) kTime(f *codecFnInfo, rv reflect.Value) {
+func rvGetTime(rv reflect.Value) time.Time {
 	v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	e.e.EncodeTime(*(*time.Time)(v.ptr))
+	return *(*time.Time)(v.ptr)
 }
 
-func (e *Encoder) kString(f *codecFnInfo, rv reflect.Value) {
+func rvGetString(rv reflect.Value) string {
 	v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	if e.h.StringToRaw {
-		e.e.EncodeStringBytesRaw(bytesView(*(*string)(v.ptr)))
-	} else {
-		e.e.EncodeStringEnc(cUTF8, *(*string)(v.ptr))
-	}
+	return *(*string)(v.ptr)
 }
 
-// func (e *Encoder) kStringToRaw(f *codecFnInfo, rv reflect.Value) {
-// 	v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-// 	s := *(*string)(v.ptr)
-// 	e.e.EncodeStringBytesRaw(bytesView(s))
-// }
-
-// func (e *Encoder) kStringEnc(f *codecFnInfo, rv reflect.Value) {
-// 	v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-// 	s := *(*string)(v.ptr)
-// 	e.e.EncodeStringEnc(cUTF8, s)
-// }
-
-func (e *Encoder) kFloat64(f *codecFnInfo, rv reflect.Value) {
+func rvGetFloat64(rv reflect.Value) float64 {
 	v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	e.e.EncodeFloat64(*(*float64)(v.ptr))
+	return *(*float64)(v.ptr)
 }
 
-func (e *Encoder) kFloat32(f *codecFnInfo, rv reflect.Value) {
+func rvGetFloat32(rv reflect.Value) float32 {
 	v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	e.e.EncodeFloat32(*(*float32)(v.ptr))
+	return *(*float32)(v.ptr)
 }
 
-func (e *Encoder) kInt(f *codecFnInfo, rv reflect.Value) {
+func rvGetInt(rv reflect.Value) int {
 	v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	e.e.EncodeInt(int64(*(*int)(v.ptr)))
+	return *(*int)(v.ptr)
 }
 
-func (e *Encoder) kInt8(f *codecFnInfo, rv reflect.Value) {
+func rvGetInt8(rv reflect.Value) int8 {
 	v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	e.e.EncodeInt(int64(*(*int8)(v.ptr)))
+	return *(*int8)(v.ptr)
 }
 
-func (e *Encoder) kInt16(f *codecFnInfo, rv reflect.Value) {
+func rvGetInt16(rv reflect.Value) int16 {
 	v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	e.e.EncodeInt(int64(*(*int16)(v.ptr)))
+	return *(*int16)(v.ptr)
 }
 
-func (e *Encoder) kInt32(f *codecFnInfo, rv reflect.Value) {
+func rvGetInt32(rv reflect.Value) int32 {
 	v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	e.e.EncodeInt(int64(*(*int32)(v.ptr)))
+	return *(*int32)(v.ptr)
 }
 
-func (e *Encoder) kInt64(f *codecFnInfo, rv reflect.Value) {
+func rvGetInt64(rv reflect.Value) int64 {
 	v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	e.e.EncodeInt(int64(*(*int64)(v.ptr)))
+	return *(*int64)(v.ptr)
 }
 
-func (e *Encoder) kUint(f *codecFnInfo, rv reflect.Value) {
+func rvGetUint(rv reflect.Value) uint {
 	v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	e.e.EncodeUint(uint64(*(*uint)(v.ptr)))
+	return *(*uint)(v.ptr)
 }
 
-func (e *Encoder) kUint8(f *codecFnInfo, rv reflect.Value) {
+func rvGetUint8(rv reflect.Value) uint8 {
 	v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	e.e.EncodeUint(uint64(*(*uint8)(v.ptr)))
+	return *(*uint8)(v.ptr)
 }
 
-func (e *Encoder) kUint16(f *codecFnInfo, rv reflect.Value) {
+func rvGetUint16(rv reflect.Value) uint16 {
 	v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	e.e.EncodeUint(uint64(*(*uint16)(v.ptr)))
+	return *(*uint16)(v.ptr)
 }
 
-func (e *Encoder) kUint32(f *codecFnInfo, rv reflect.Value) {
+func rvGetUint32(rv reflect.Value) uint32 {
 	v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	e.e.EncodeUint(uint64(*(*uint32)(v.ptr)))
+	return *(*uint32)(v.ptr)
 }
 
-func (e *Encoder) kUint64(f *codecFnInfo, rv reflect.Value) {
+func rvGetUint64(rv reflect.Value) uint64 {
 	v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	e.e.EncodeUint(uint64(*(*uint64)(v.ptr)))
+	return *(*uint64)(v.ptr)
 }
 
-func (e *Encoder) kUintptr(f *codecFnInfo, rv reflect.Value) {
+func rvGetUintptr(rv reflect.Value) uintptr {
 	v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
-	e.e.EncodeUint(uint64(*(*uintptr)(v.ptr)))
+	return *(*uintptr)(v.ptr)
 }
 
 // ------------ map range and map indexing ----------