|
|
@@ -23,7 +23,7 @@ package codec
|
|
|
// Currently support
|
|
|
// - slice of all builtin types,
|
|
|
// - map of all builtin types to string or interface value
|
|
|
-// - symetrical maps of all builtin types (e.g. str-str, uint8-uint8)
|
|
|
+// - symmetrical maps of all builtin types (e.g. str-str, uint8-uint8)
|
|
|
// This should provide adequate "typical" implementations.
|
|
|
//
|
|
|
// Note that fast track decode functions must handle values for which an address cannot be obtained.
|
|
|
@@ -38,6 +38,8 @@ import (
|
|
|
"sort"
|
|
|
)
|
|
|
|
|
|
+const fastpathEnabled = true
|
|
|
+
|
|
|
const fastpathCheckNilFalse = false // for reflect
|
|
|
const fastpathCheckNilTrue = true // for type switch
|
|
|
|
|
|
@@ -81,9 +83,6 @@ var fastpathAV fastpathA
|
|
|
|
|
|
// due to possible initialization loop error, make fastpath in an init()
|
|
|
func init() {
|
|
|
- if !fastpathEnabled {
|
|
|
- return
|
|
|
- }
|
|
|
i := 0
|
|
|
fn := func(v interface{}, fe func(*encFnInfo, reflect.Value), fd func(*decFnInfo, reflect.Value)) (f fastpathE) {
|
|
|
xrt := reflect.TypeOf(v)
|
|
|
@@ -373,9 +372,6 @@ func init() {
|
|
|
|
|
|
// -- -- fast path type switch
|
|
|
func fastpathEncodeTypeSwitch(iv interface{}, e *Encoder) bool {
|
|
|
- if !fastpathEnabled {
|
|
|
- return false
|
|
|
- }
|
|
|
switch v := iv.(type) {
|
|
|
|
|
|
case []interface{}:
|
|
|
@@ -1741,9 +1737,6 @@ func fastpathEncodeTypeSwitch(iv interface{}, e *Encoder) bool {
|
|
|
}
|
|
|
|
|
|
func fastpathEncodeTypeSwitchSlice(iv interface{}, e *Encoder) bool {
|
|
|
- if !fastpathEnabled {
|
|
|
- return false
|
|
|
- }
|
|
|
switch v := iv.(type) {
|
|
|
|
|
|
case []interface{}:
|
|
|
@@ -1829,9 +1822,6 @@ func fastpathEncodeTypeSwitchSlice(iv interface{}, e *Encoder) bool {
|
|
|
}
|
|
|
|
|
|
func fastpathEncodeTypeSwitchMap(iv interface{}, e *Encoder) bool {
|
|
|
- if !fastpathEnabled {
|
|
|
- return false
|
|
|
- }
|
|
|
switch v := iv.(type) {
|
|
|
|
|
|
case map[interface{}]interface{}:
|
|
|
@@ -3124,7 +3114,11 @@ func fastpathEncodeTypeSwitchMap(iv interface{}, e *Encoder) bool {
|
|
|
// -- -- fast path functions
|
|
|
|
|
|
func (f *encFnInfo) fastpathEncSliceIntfR(rv reflect.Value) {
|
|
|
- fastpathTV.EncSliceIntfV(rv.Interface().([]interface{}), fastpathCheckNilFalse, f.e)
|
|
|
+ if f.ti.mbs {
|
|
|
+ fastpathTV.EncAsMapSliceIntfV(rv.Interface().([]interface{}), fastpathCheckNilFalse, f.e)
|
|
|
+ } else {
|
|
|
+ fastpathTV.EncSliceIntfV(rv.Interface().([]interface{}), fastpathCheckNilFalse, f.e)
|
|
|
+ }
|
|
|
}
|
|
|
func (_ fastpathT) EncSliceIntfV(v []interface{}, checkNil bool, e *Encoder) {
|
|
|
ee := e.e
|
|
|
@@ -3145,8 +3139,39 @@ func (_ fastpathT) EncSliceIntfV(v []interface{}, checkNil bool, e *Encoder) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func (_ fastpathT) EncAsMapSliceIntfV(v []interface{}, checkNil bool, e *Encoder) {
|
|
|
+ ee := e.e
|
|
|
+ cr := e.cr
|
|
|
+ if checkNil && v == nil {
|
|
|
+ ee.EncodeNil()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(v)%2 == 1 {
|
|
|
+ e.errorf("mapBySlice requires even slice length, but got %v", len(v))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ee.EncodeMapStart(len(v) / 2)
|
|
|
+ for j, v2 := range v {
|
|
|
+ if cr != nil {
|
|
|
+ if j%2 == 0 {
|
|
|
+ cr.sendContainerState(containerMapKey)
|
|
|
+ } else {
|
|
|
+ cr.sendContainerState(containerMapValue)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ e.encode(v2)
|
|
|
+ }
|
|
|
+ if cr != nil {
|
|
|
+ cr.sendContainerState(containerMapEnd)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func (f *encFnInfo) fastpathEncSliceStringR(rv reflect.Value) {
|
|
|
- fastpathTV.EncSliceStringV(rv.Interface().([]string), fastpathCheckNilFalse, f.e)
|
|
|
+ if f.ti.mbs {
|
|
|
+ fastpathTV.EncAsMapSliceStringV(rv.Interface().([]string), fastpathCheckNilFalse, f.e)
|
|
|
+ } else {
|
|
|
+ fastpathTV.EncSliceStringV(rv.Interface().([]string), fastpathCheckNilFalse, f.e)
|
|
|
+ }
|
|
|
}
|
|
|
func (_ fastpathT) EncSliceStringV(v []string, checkNil bool, e *Encoder) {
|
|
|
ee := e.e
|
|
|
@@ -3167,8 +3192,39 @@ func (_ fastpathT) EncSliceStringV(v []string, checkNil bool, e *Encoder) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func (_ fastpathT) EncAsMapSliceStringV(v []string, checkNil bool, e *Encoder) {
|
|
|
+ ee := e.e
|
|
|
+ cr := e.cr
|
|
|
+ if checkNil && v == nil {
|
|
|
+ ee.EncodeNil()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(v)%2 == 1 {
|
|
|
+ e.errorf("mapBySlice requires even slice length, but got %v", len(v))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ee.EncodeMapStart(len(v) / 2)
|
|
|
+ for j, v2 := range v {
|
|
|
+ if cr != nil {
|
|
|
+ if j%2 == 0 {
|
|
|
+ cr.sendContainerState(containerMapKey)
|
|
|
+ } else {
|
|
|
+ cr.sendContainerState(containerMapValue)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ee.EncodeString(c_UTF8, v2)
|
|
|
+ }
|
|
|
+ if cr != nil {
|
|
|
+ cr.sendContainerState(containerMapEnd)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func (f *encFnInfo) fastpathEncSliceFloat32R(rv reflect.Value) {
|
|
|
- fastpathTV.EncSliceFloat32V(rv.Interface().([]float32), fastpathCheckNilFalse, f.e)
|
|
|
+ if f.ti.mbs {
|
|
|
+ fastpathTV.EncAsMapSliceFloat32V(rv.Interface().([]float32), fastpathCheckNilFalse, f.e)
|
|
|
+ } else {
|
|
|
+ fastpathTV.EncSliceFloat32V(rv.Interface().([]float32), fastpathCheckNilFalse, f.e)
|
|
|
+ }
|
|
|
}
|
|
|
func (_ fastpathT) EncSliceFloat32V(v []float32, checkNil bool, e *Encoder) {
|
|
|
ee := e.e
|
|
|
@@ -3189,8 +3245,39 @@ func (_ fastpathT) EncSliceFloat32V(v []float32, checkNil bool, e *Encoder) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func (_ fastpathT) EncAsMapSliceFloat32V(v []float32, checkNil bool, e *Encoder) {
|
|
|
+ ee := e.e
|
|
|
+ cr := e.cr
|
|
|
+ if checkNil && v == nil {
|
|
|
+ ee.EncodeNil()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(v)%2 == 1 {
|
|
|
+ e.errorf("mapBySlice requires even slice length, but got %v", len(v))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ee.EncodeMapStart(len(v) / 2)
|
|
|
+ for j, v2 := range v {
|
|
|
+ if cr != nil {
|
|
|
+ if j%2 == 0 {
|
|
|
+ cr.sendContainerState(containerMapKey)
|
|
|
+ } else {
|
|
|
+ cr.sendContainerState(containerMapValue)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ee.EncodeFloat32(v2)
|
|
|
+ }
|
|
|
+ if cr != nil {
|
|
|
+ cr.sendContainerState(containerMapEnd)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func (f *encFnInfo) fastpathEncSliceFloat64R(rv reflect.Value) {
|
|
|
- fastpathTV.EncSliceFloat64V(rv.Interface().([]float64), fastpathCheckNilFalse, f.e)
|
|
|
+ if f.ti.mbs {
|
|
|
+ fastpathTV.EncAsMapSliceFloat64V(rv.Interface().([]float64), fastpathCheckNilFalse, f.e)
|
|
|
+ } else {
|
|
|
+ fastpathTV.EncSliceFloat64V(rv.Interface().([]float64), fastpathCheckNilFalse, f.e)
|
|
|
+ }
|
|
|
}
|
|
|
func (_ fastpathT) EncSliceFloat64V(v []float64, checkNil bool, e *Encoder) {
|
|
|
ee := e.e
|
|
|
@@ -3211,8 +3298,39 @@ func (_ fastpathT) EncSliceFloat64V(v []float64, checkNil bool, e *Encoder) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func (_ fastpathT) EncAsMapSliceFloat64V(v []float64, checkNil bool, e *Encoder) {
|
|
|
+ ee := e.e
|
|
|
+ cr := e.cr
|
|
|
+ if checkNil && v == nil {
|
|
|
+ ee.EncodeNil()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(v)%2 == 1 {
|
|
|
+ e.errorf("mapBySlice requires even slice length, but got %v", len(v))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ee.EncodeMapStart(len(v) / 2)
|
|
|
+ for j, v2 := range v {
|
|
|
+ if cr != nil {
|
|
|
+ if j%2 == 0 {
|
|
|
+ cr.sendContainerState(containerMapKey)
|
|
|
+ } else {
|
|
|
+ cr.sendContainerState(containerMapValue)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ee.EncodeFloat64(v2)
|
|
|
+ }
|
|
|
+ if cr != nil {
|
|
|
+ cr.sendContainerState(containerMapEnd)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func (f *encFnInfo) fastpathEncSliceUintR(rv reflect.Value) {
|
|
|
- fastpathTV.EncSliceUintV(rv.Interface().([]uint), fastpathCheckNilFalse, f.e)
|
|
|
+ if f.ti.mbs {
|
|
|
+ fastpathTV.EncAsMapSliceUintV(rv.Interface().([]uint), fastpathCheckNilFalse, f.e)
|
|
|
+ } else {
|
|
|
+ fastpathTV.EncSliceUintV(rv.Interface().([]uint), fastpathCheckNilFalse, f.e)
|
|
|
+ }
|
|
|
}
|
|
|
func (_ fastpathT) EncSliceUintV(v []uint, checkNil bool, e *Encoder) {
|
|
|
ee := e.e
|
|
|
@@ -3233,8 +3351,39 @@ func (_ fastpathT) EncSliceUintV(v []uint, checkNil bool, e *Encoder) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func (_ fastpathT) EncAsMapSliceUintV(v []uint, checkNil bool, e *Encoder) {
|
|
|
+ ee := e.e
|
|
|
+ cr := e.cr
|
|
|
+ if checkNil && v == nil {
|
|
|
+ ee.EncodeNil()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(v)%2 == 1 {
|
|
|
+ e.errorf("mapBySlice requires even slice length, but got %v", len(v))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ee.EncodeMapStart(len(v) / 2)
|
|
|
+ for j, v2 := range v {
|
|
|
+ if cr != nil {
|
|
|
+ if j%2 == 0 {
|
|
|
+ cr.sendContainerState(containerMapKey)
|
|
|
+ } else {
|
|
|
+ cr.sendContainerState(containerMapValue)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ee.EncodeUint(uint64(v2))
|
|
|
+ }
|
|
|
+ if cr != nil {
|
|
|
+ cr.sendContainerState(containerMapEnd)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func (f *encFnInfo) fastpathEncSliceUint16R(rv reflect.Value) {
|
|
|
- fastpathTV.EncSliceUint16V(rv.Interface().([]uint16), fastpathCheckNilFalse, f.e)
|
|
|
+ if f.ti.mbs {
|
|
|
+ fastpathTV.EncAsMapSliceUint16V(rv.Interface().([]uint16), fastpathCheckNilFalse, f.e)
|
|
|
+ } else {
|
|
|
+ fastpathTV.EncSliceUint16V(rv.Interface().([]uint16), fastpathCheckNilFalse, f.e)
|
|
|
+ }
|
|
|
}
|
|
|
func (_ fastpathT) EncSliceUint16V(v []uint16, checkNil bool, e *Encoder) {
|
|
|
ee := e.e
|
|
|
@@ -3255,8 +3404,39 @@ func (_ fastpathT) EncSliceUint16V(v []uint16, checkNil bool, e *Encoder) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func (_ fastpathT) EncAsMapSliceUint16V(v []uint16, checkNil bool, e *Encoder) {
|
|
|
+ ee := e.e
|
|
|
+ cr := e.cr
|
|
|
+ if checkNil && v == nil {
|
|
|
+ ee.EncodeNil()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(v)%2 == 1 {
|
|
|
+ e.errorf("mapBySlice requires even slice length, but got %v", len(v))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ee.EncodeMapStart(len(v) / 2)
|
|
|
+ for j, v2 := range v {
|
|
|
+ if cr != nil {
|
|
|
+ if j%2 == 0 {
|
|
|
+ cr.sendContainerState(containerMapKey)
|
|
|
+ } else {
|
|
|
+ cr.sendContainerState(containerMapValue)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ee.EncodeUint(uint64(v2))
|
|
|
+ }
|
|
|
+ if cr != nil {
|
|
|
+ cr.sendContainerState(containerMapEnd)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func (f *encFnInfo) fastpathEncSliceUint32R(rv reflect.Value) {
|
|
|
- fastpathTV.EncSliceUint32V(rv.Interface().([]uint32), fastpathCheckNilFalse, f.e)
|
|
|
+ if f.ti.mbs {
|
|
|
+ fastpathTV.EncAsMapSliceUint32V(rv.Interface().([]uint32), fastpathCheckNilFalse, f.e)
|
|
|
+ } else {
|
|
|
+ fastpathTV.EncSliceUint32V(rv.Interface().([]uint32), fastpathCheckNilFalse, f.e)
|
|
|
+ }
|
|
|
}
|
|
|
func (_ fastpathT) EncSliceUint32V(v []uint32, checkNil bool, e *Encoder) {
|
|
|
ee := e.e
|
|
|
@@ -3277,8 +3457,39 @@ func (_ fastpathT) EncSliceUint32V(v []uint32, checkNil bool, e *Encoder) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func (_ fastpathT) EncAsMapSliceUint32V(v []uint32, checkNil bool, e *Encoder) {
|
|
|
+ ee := e.e
|
|
|
+ cr := e.cr
|
|
|
+ if checkNil && v == nil {
|
|
|
+ ee.EncodeNil()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(v)%2 == 1 {
|
|
|
+ e.errorf("mapBySlice requires even slice length, but got %v", len(v))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ee.EncodeMapStart(len(v) / 2)
|
|
|
+ for j, v2 := range v {
|
|
|
+ if cr != nil {
|
|
|
+ if j%2 == 0 {
|
|
|
+ cr.sendContainerState(containerMapKey)
|
|
|
+ } else {
|
|
|
+ cr.sendContainerState(containerMapValue)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ee.EncodeUint(uint64(v2))
|
|
|
+ }
|
|
|
+ if cr != nil {
|
|
|
+ cr.sendContainerState(containerMapEnd)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func (f *encFnInfo) fastpathEncSliceUint64R(rv reflect.Value) {
|
|
|
- fastpathTV.EncSliceUint64V(rv.Interface().([]uint64), fastpathCheckNilFalse, f.e)
|
|
|
+ if f.ti.mbs {
|
|
|
+ fastpathTV.EncAsMapSliceUint64V(rv.Interface().([]uint64), fastpathCheckNilFalse, f.e)
|
|
|
+ } else {
|
|
|
+ fastpathTV.EncSliceUint64V(rv.Interface().([]uint64), fastpathCheckNilFalse, f.e)
|
|
|
+ }
|
|
|
}
|
|
|
func (_ fastpathT) EncSliceUint64V(v []uint64, checkNil bool, e *Encoder) {
|
|
|
ee := e.e
|
|
|
@@ -3299,8 +3510,39 @@ func (_ fastpathT) EncSliceUint64V(v []uint64, checkNil bool, e *Encoder) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func (_ fastpathT) EncAsMapSliceUint64V(v []uint64, checkNil bool, e *Encoder) {
|
|
|
+ ee := e.e
|
|
|
+ cr := e.cr
|
|
|
+ if checkNil && v == nil {
|
|
|
+ ee.EncodeNil()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(v)%2 == 1 {
|
|
|
+ e.errorf("mapBySlice requires even slice length, but got %v", len(v))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ee.EncodeMapStart(len(v) / 2)
|
|
|
+ for j, v2 := range v {
|
|
|
+ if cr != nil {
|
|
|
+ if j%2 == 0 {
|
|
|
+ cr.sendContainerState(containerMapKey)
|
|
|
+ } else {
|
|
|
+ cr.sendContainerState(containerMapValue)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ee.EncodeUint(uint64(v2))
|
|
|
+ }
|
|
|
+ if cr != nil {
|
|
|
+ cr.sendContainerState(containerMapEnd)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func (f *encFnInfo) fastpathEncSliceUintptrR(rv reflect.Value) {
|
|
|
- fastpathTV.EncSliceUintptrV(rv.Interface().([]uintptr), fastpathCheckNilFalse, f.e)
|
|
|
+ if f.ti.mbs {
|
|
|
+ fastpathTV.EncAsMapSliceUintptrV(rv.Interface().([]uintptr), fastpathCheckNilFalse, f.e)
|
|
|
+ } else {
|
|
|
+ fastpathTV.EncSliceUintptrV(rv.Interface().([]uintptr), fastpathCheckNilFalse, f.e)
|
|
|
+ }
|
|
|
}
|
|
|
func (_ fastpathT) EncSliceUintptrV(v []uintptr, checkNil bool, e *Encoder) {
|
|
|
ee := e.e
|
|
|
@@ -3321,8 +3563,39 @@ func (_ fastpathT) EncSliceUintptrV(v []uintptr, checkNil bool, e *Encoder) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func (_ fastpathT) EncAsMapSliceUintptrV(v []uintptr, checkNil bool, e *Encoder) {
|
|
|
+ ee := e.e
|
|
|
+ cr := e.cr
|
|
|
+ if checkNil && v == nil {
|
|
|
+ ee.EncodeNil()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(v)%2 == 1 {
|
|
|
+ e.errorf("mapBySlice requires even slice length, but got %v", len(v))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ee.EncodeMapStart(len(v) / 2)
|
|
|
+ for j, v2 := range v {
|
|
|
+ if cr != nil {
|
|
|
+ if j%2 == 0 {
|
|
|
+ cr.sendContainerState(containerMapKey)
|
|
|
+ } else {
|
|
|
+ cr.sendContainerState(containerMapValue)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ e.encode(v2)
|
|
|
+ }
|
|
|
+ if cr != nil {
|
|
|
+ cr.sendContainerState(containerMapEnd)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func (f *encFnInfo) fastpathEncSliceIntR(rv reflect.Value) {
|
|
|
- fastpathTV.EncSliceIntV(rv.Interface().([]int), fastpathCheckNilFalse, f.e)
|
|
|
+ if f.ti.mbs {
|
|
|
+ fastpathTV.EncAsMapSliceIntV(rv.Interface().([]int), fastpathCheckNilFalse, f.e)
|
|
|
+ } else {
|
|
|
+ fastpathTV.EncSliceIntV(rv.Interface().([]int), fastpathCheckNilFalse, f.e)
|
|
|
+ }
|
|
|
}
|
|
|
func (_ fastpathT) EncSliceIntV(v []int, checkNil bool, e *Encoder) {
|
|
|
ee := e.e
|
|
|
@@ -3343,8 +3616,39 @@ func (_ fastpathT) EncSliceIntV(v []int, checkNil bool, e *Encoder) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func (_ fastpathT) EncAsMapSliceIntV(v []int, checkNil bool, e *Encoder) {
|
|
|
+ ee := e.e
|
|
|
+ cr := e.cr
|
|
|
+ if checkNil && v == nil {
|
|
|
+ ee.EncodeNil()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(v)%2 == 1 {
|
|
|
+ e.errorf("mapBySlice requires even slice length, but got %v", len(v))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ee.EncodeMapStart(len(v) / 2)
|
|
|
+ for j, v2 := range v {
|
|
|
+ if cr != nil {
|
|
|
+ if j%2 == 0 {
|
|
|
+ cr.sendContainerState(containerMapKey)
|
|
|
+ } else {
|
|
|
+ cr.sendContainerState(containerMapValue)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ee.EncodeInt(int64(v2))
|
|
|
+ }
|
|
|
+ if cr != nil {
|
|
|
+ cr.sendContainerState(containerMapEnd)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func (f *encFnInfo) fastpathEncSliceInt8R(rv reflect.Value) {
|
|
|
- fastpathTV.EncSliceInt8V(rv.Interface().([]int8), fastpathCheckNilFalse, f.e)
|
|
|
+ if f.ti.mbs {
|
|
|
+ fastpathTV.EncAsMapSliceInt8V(rv.Interface().([]int8), fastpathCheckNilFalse, f.e)
|
|
|
+ } else {
|
|
|
+ fastpathTV.EncSliceInt8V(rv.Interface().([]int8), fastpathCheckNilFalse, f.e)
|
|
|
+ }
|
|
|
}
|
|
|
func (_ fastpathT) EncSliceInt8V(v []int8, checkNil bool, e *Encoder) {
|
|
|
ee := e.e
|
|
|
@@ -3365,8 +3669,39 @@ func (_ fastpathT) EncSliceInt8V(v []int8, checkNil bool, e *Encoder) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func (_ fastpathT) EncAsMapSliceInt8V(v []int8, checkNil bool, e *Encoder) {
|
|
|
+ ee := e.e
|
|
|
+ cr := e.cr
|
|
|
+ if checkNil && v == nil {
|
|
|
+ ee.EncodeNil()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(v)%2 == 1 {
|
|
|
+ e.errorf("mapBySlice requires even slice length, but got %v", len(v))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ee.EncodeMapStart(len(v) / 2)
|
|
|
+ for j, v2 := range v {
|
|
|
+ if cr != nil {
|
|
|
+ if j%2 == 0 {
|
|
|
+ cr.sendContainerState(containerMapKey)
|
|
|
+ } else {
|
|
|
+ cr.sendContainerState(containerMapValue)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ee.EncodeInt(int64(v2))
|
|
|
+ }
|
|
|
+ if cr != nil {
|
|
|
+ cr.sendContainerState(containerMapEnd)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func (f *encFnInfo) fastpathEncSliceInt16R(rv reflect.Value) {
|
|
|
- fastpathTV.EncSliceInt16V(rv.Interface().([]int16), fastpathCheckNilFalse, f.e)
|
|
|
+ if f.ti.mbs {
|
|
|
+ fastpathTV.EncAsMapSliceInt16V(rv.Interface().([]int16), fastpathCheckNilFalse, f.e)
|
|
|
+ } else {
|
|
|
+ fastpathTV.EncSliceInt16V(rv.Interface().([]int16), fastpathCheckNilFalse, f.e)
|
|
|
+ }
|
|
|
}
|
|
|
func (_ fastpathT) EncSliceInt16V(v []int16, checkNil bool, e *Encoder) {
|
|
|
ee := e.e
|
|
|
@@ -3387,8 +3722,39 @@ func (_ fastpathT) EncSliceInt16V(v []int16, checkNil bool, e *Encoder) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func (_ fastpathT) EncAsMapSliceInt16V(v []int16, checkNil bool, e *Encoder) {
|
|
|
+ ee := e.e
|
|
|
+ cr := e.cr
|
|
|
+ if checkNil && v == nil {
|
|
|
+ ee.EncodeNil()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(v)%2 == 1 {
|
|
|
+ e.errorf("mapBySlice requires even slice length, but got %v", len(v))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ee.EncodeMapStart(len(v) / 2)
|
|
|
+ for j, v2 := range v {
|
|
|
+ if cr != nil {
|
|
|
+ if j%2 == 0 {
|
|
|
+ cr.sendContainerState(containerMapKey)
|
|
|
+ } else {
|
|
|
+ cr.sendContainerState(containerMapValue)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ee.EncodeInt(int64(v2))
|
|
|
+ }
|
|
|
+ if cr != nil {
|
|
|
+ cr.sendContainerState(containerMapEnd)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func (f *encFnInfo) fastpathEncSliceInt32R(rv reflect.Value) {
|
|
|
- fastpathTV.EncSliceInt32V(rv.Interface().([]int32), fastpathCheckNilFalse, f.e)
|
|
|
+ if f.ti.mbs {
|
|
|
+ fastpathTV.EncAsMapSliceInt32V(rv.Interface().([]int32), fastpathCheckNilFalse, f.e)
|
|
|
+ } else {
|
|
|
+ fastpathTV.EncSliceInt32V(rv.Interface().([]int32), fastpathCheckNilFalse, f.e)
|
|
|
+ }
|
|
|
}
|
|
|
func (_ fastpathT) EncSliceInt32V(v []int32, checkNil bool, e *Encoder) {
|
|
|
ee := e.e
|
|
|
@@ -3409,8 +3775,39 @@ func (_ fastpathT) EncSliceInt32V(v []int32, checkNil bool, e *Encoder) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func (_ fastpathT) EncAsMapSliceInt32V(v []int32, checkNil bool, e *Encoder) {
|
|
|
+ ee := e.e
|
|
|
+ cr := e.cr
|
|
|
+ if checkNil && v == nil {
|
|
|
+ ee.EncodeNil()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(v)%2 == 1 {
|
|
|
+ e.errorf("mapBySlice requires even slice length, but got %v", len(v))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ee.EncodeMapStart(len(v) / 2)
|
|
|
+ for j, v2 := range v {
|
|
|
+ if cr != nil {
|
|
|
+ if j%2 == 0 {
|
|
|
+ cr.sendContainerState(containerMapKey)
|
|
|
+ } else {
|
|
|
+ cr.sendContainerState(containerMapValue)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ee.EncodeInt(int64(v2))
|
|
|
+ }
|
|
|
+ if cr != nil {
|
|
|
+ cr.sendContainerState(containerMapEnd)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func (f *encFnInfo) fastpathEncSliceInt64R(rv reflect.Value) {
|
|
|
- fastpathTV.EncSliceInt64V(rv.Interface().([]int64), fastpathCheckNilFalse, f.e)
|
|
|
+ if f.ti.mbs {
|
|
|
+ fastpathTV.EncAsMapSliceInt64V(rv.Interface().([]int64), fastpathCheckNilFalse, f.e)
|
|
|
+ } else {
|
|
|
+ fastpathTV.EncSliceInt64V(rv.Interface().([]int64), fastpathCheckNilFalse, f.e)
|
|
|
+ }
|
|
|
}
|
|
|
func (_ fastpathT) EncSliceInt64V(v []int64, checkNil bool, e *Encoder) {
|
|
|
ee := e.e
|
|
|
@@ -3431,8 +3828,39 @@ func (_ fastpathT) EncSliceInt64V(v []int64, checkNil bool, e *Encoder) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func (_ fastpathT) EncAsMapSliceInt64V(v []int64, checkNil bool, e *Encoder) {
|
|
|
+ ee := e.e
|
|
|
+ cr := e.cr
|
|
|
+ if checkNil && v == nil {
|
|
|
+ ee.EncodeNil()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(v)%2 == 1 {
|
|
|
+ e.errorf("mapBySlice requires even slice length, but got %v", len(v))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ee.EncodeMapStart(len(v) / 2)
|
|
|
+ for j, v2 := range v {
|
|
|
+ if cr != nil {
|
|
|
+ if j%2 == 0 {
|
|
|
+ cr.sendContainerState(containerMapKey)
|
|
|
+ } else {
|
|
|
+ cr.sendContainerState(containerMapValue)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ee.EncodeInt(int64(v2))
|
|
|
+ }
|
|
|
+ if cr != nil {
|
|
|
+ cr.sendContainerState(containerMapEnd)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func (f *encFnInfo) fastpathEncSliceBoolR(rv reflect.Value) {
|
|
|
- fastpathTV.EncSliceBoolV(rv.Interface().([]bool), fastpathCheckNilFalse, f.e)
|
|
|
+ if f.ti.mbs {
|
|
|
+ fastpathTV.EncAsMapSliceBoolV(rv.Interface().([]bool), fastpathCheckNilFalse, f.e)
|
|
|
+ } else {
|
|
|
+ fastpathTV.EncSliceBoolV(rv.Interface().([]bool), fastpathCheckNilFalse, f.e)
|
|
|
+ }
|
|
|
}
|
|
|
func (_ fastpathT) EncSliceBoolV(v []bool, checkNil bool, e *Encoder) {
|
|
|
ee := e.e
|
|
|
@@ -3453,6 +3881,33 @@ func (_ fastpathT) EncSliceBoolV(v []bool, checkNil bool, e *Encoder) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func (_ fastpathT) EncAsMapSliceBoolV(v []bool, checkNil bool, e *Encoder) {
|
|
|
+ ee := e.e
|
|
|
+ cr := e.cr
|
|
|
+ if checkNil && v == nil {
|
|
|
+ ee.EncodeNil()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(v)%2 == 1 {
|
|
|
+ e.errorf("mapBySlice requires even slice length, but got %v", len(v))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ee.EncodeMapStart(len(v) / 2)
|
|
|
+ for j, v2 := range v {
|
|
|
+ if cr != nil {
|
|
|
+ if j%2 == 0 {
|
|
|
+ cr.sendContainerState(containerMapKey)
|
|
|
+ } else {
|
|
|
+ cr.sendContainerState(containerMapValue)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ee.EncodeBool(v2)
|
|
|
+ }
|
|
|
+ if cr != nil {
|
|
|
+ cr.sendContainerState(containerMapEnd)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func (f *encFnInfo) fastpathEncMapIntfIntfR(rv reflect.Value) {
|
|
|
fastpathTV.EncMapIntfIntfV(rv.Interface().(map[interface{}]interface{}), fastpathCheckNilFalse, f.e)
|
|
|
}
|
|
|
@@ -15489,9 +15944,6 @@ func (_ fastpathT) EncMapBoolBoolV(v map[bool]bool, checkNil bool, e *Encoder) {
|
|
|
|
|
|
// -- -- fast path type switch
|
|
|
func fastpathDecodeTypeSwitch(iv interface{}, d *Decoder) bool {
|
|
|
- if !fastpathEnabled {
|
|
|
- return false
|
|
|
- }
|
|
|
switch v := iv.(type) {
|
|
|
|
|
|
case []interface{}:
|
|
|
@@ -17712,7 +18164,7 @@ func (_ fastpathT) DecSliceIntfV(v []interface{}, checkNil bool, canChange bool,
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
|
|
|
if containerLenS > 0 {
|
|
|
@@ -17771,7 +18223,7 @@ func (_ fastpathT) DecSliceIntfV(v []interface{}, checkNil bool, canChange bool,
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
if cap(v) == 0 {
|
|
|
v = make([]interface{}, 1, 4)
|
|
|
@@ -17846,7 +18298,7 @@ func (_ fastpathT) DecSliceStringV(v []string, checkNil bool, canChange bool, d
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
|
|
|
if containerLenS > 0 {
|
|
|
@@ -17905,7 +18357,7 @@ func (_ fastpathT) DecSliceStringV(v []string, checkNil bool, canChange bool, d
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
if cap(v) == 0 {
|
|
|
v = make([]string, 1, 4)
|
|
|
@@ -17979,7 +18431,7 @@ func (_ fastpathT) DecSliceFloat32V(v []float32, checkNil bool, canChange bool,
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
|
|
|
if containerLenS > 0 {
|
|
|
@@ -18038,7 +18490,7 @@ func (_ fastpathT) DecSliceFloat32V(v []float32, checkNil bool, canChange bool,
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
if cap(v) == 0 {
|
|
|
v = make([]float32, 1, 4)
|
|
|
@@ -18112,7 +18564,7 @@ func (_ fastpathT) DecSliceFloat64V(v []float64, checkNil bool, canChange bool,
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
|
|
|
if containerLenS > 0 {
|
|
|
@@ -18171,7 +18623,7 @@ func (_ fastpathT) DecSliceFloat64V(v []float64, checkNil bool, canChange bool,
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
if cap(v) == 0 {
|
|
|
v = make([]float64, 1, 4)
|
|
|
@@ -18245,7 +18697,7 @@ func (_ fastpathT) DecSliceUintV(v []uint, checkNil bool, canChange bool, d *Dec
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
|
|
|
if containerLenS > 0 {
|
|
|
@@ -18304,7 +18756,7 @@ func (_ fastpathT) DecSliceUintV(v []uint, checkNil bool, canChange bool, d *Dec
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
if cap(v) == 0 {
|
|
|
v = make([]uint, 1, 4)
|
|
|
@@ -18378,7 +18830,7 @@ func (_ fastpathT) DecSliceUint16V(v []uint16, checkNil bool, canChange bool, d
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
|
|
|
if containerLenS > 0 {
|
|
|
@@ -18437,7 +18889,7 @@ func (_ fastpathT) DecSliceUint16V(v []uint16, checkNil bool, canChange bool, d
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
if cap(v) == 0 {
|
|
|
v = make([]uint16, 1, 4)
|
|
|
@@ -18511,7 +18963,7 @@ func (_ fastpathT) DecSliceUint32V(v []uint32, checkNil bool, canChange bool, d
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
|
|
|
if containerLenS > 0 {
|
|
|
@@ -18570,7 +19022,7 @@ func (_ fastpathT) DecSliceUint32V(v []uint32, checkNil bool, canChange bool, d
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
if cap(v) == 0 {
|
|
|
v = make([]uint32, 1, 4)
|
|
|
@@ -18644,7 +19096,7 @@ func (_ fastpathT) DecSliceUint64V(v []uint64, checkNil bool, canChange bool, d
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
|
|
|
if containerLenS > 0 {
|
|
|
@@ -18703,7 +19155,7 @@ func (_ fastpathT) DecSliceUint64V(v []uint64, checkNil bool, canChange bool, d
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
if cap(v) == 0 {
|
|
|
v = make([]uint64, 1, 4)
|
|
|
@@ -18777,7 +19229,7 @@ func (_ fastpathT) DecSliceUintptrV(v []uintptr, checkNil bool, canChange bool,
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
|
|
|
if containerLenS > 0 {
|
|
|
@@ -18836,7 +19288,7 @@ func (_ fastpathT) DecSliceUintptrV(v []uintptr, checkNil bool, canChange bool,
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
if cap(v) == 0 {
|
|
|
v = make([]uintptr, 1, 4)
|
|
|
@@ -18910,7 +19362,7 @@ func (_ fastpathT) DecSliceIntV(v []int, checkNil bool, canChange bool, d *Decod
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
|
|
|
if containerLenS > 0 {
|
|
|
@@ -18969,7 +19421,7 @@ func (_ fastpathT) DecSliceIntV(v []int, checkNil bool, canChange bool, d *Decod
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
if cap(v) == 0 {
|
|
|
v = make([]int, 1, 4)
|
|
|
@@ -19043,7 +19495,7 @@ func (_ fastpathT) DecSliceInt8V(v []int8, checkNil bool, canChange bool, d *Dec
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
|
|
|
if containerLenS > 0 {
|
|
|
@@ -19102,7 +19554,7 @@ func (_ fastpathT) DecSliceInt8V(v []int8, checkNil bool, canChange bool, d *Dec
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
if cap(v) == 0 {
|
|
|
v = make([]int8, 1, 4)
|
|
|
@@ -19176,7 +19628,7 @@ func (_ fastpathT) DecSliceInt16V(v []int16, checkNil bool, canChange bool, d *D
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
|
|
|
if containerLenS > 0 {
|
|
|
@@ -19235,7 +19687,7 @@ func (_ fastpathT) DecSliceInt16V(v []int16, checkNil bool, canChange bool, d *D
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
if cap(v) == 0 {
|
|
|
v = make([]int16, 1, 4)
|
|
|
@@ -19309,7 +19761,7 @@ func (_ fastpathT) DecSliceInt32V(v []int32, checkNil bool, canChange bool, d *D
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
|
|
|
if containerLenS > 0 {
|
|
|
@@ -19368,7 +19820,7 @@ func (_ fastpathT) DecSliceInt32V(v []int32, checkNil bool, canChange bool, d *D
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
if cap(v) == 0 {
|
|
|
v = make([]int32, 1, 4)
|
|
|
@@ -19442,7 +19894,7 @@ func (_ fastpathT) DecSliceInt64V(v []int64, checkNil bool, canChange bool, d *D
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
|
|
|
if containerLenS > 0 {
|
|
|
@@ -19501,7 +19953,7 @@ func (_ fastpathT) DecSliceInt64V(v []int64, checkNil bool, canChange bool, d *D
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
if cap(v) == 0 {
|
|
|
v = make([]int64, 1, 4)
|
|
|
@@ -19575,7 +20027,7 @@ func (_ fastpathT) DecSliceBoolV(v []bool, checkNil bool, canChange bool, d *Dec
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
|
|
|
if containerLenS > 0 {
|
|
|
@@ -19634,7 +20086,7 @@ func (_ fastpathT) DecSliceBoolV(v []bool, checkNil bool, canChange bool, d *Dec
|
|
|
changed = true
|
|
|
}
|
|
|
slh.End()
|
|
|
- return
|
|
|
+ return v, changed
|
|
|
}
|
|
|
if cap(v) == 0 {
|
|
|
v = make([]bool, 1, 4)
|