Skip to content
Permalink
Browse files
优化为switch方式
  • Loading branch information
Changeden committed Oct 12, 2021
1 parent 0214778 commit 9c70e1fe2ed866b732d227b1e80e51a3b72811ee
Showing 1 changed file with 15 additions and 0 deletions.
@@ -167,6 +167,21 @@ func (e *Encoder) Encode(v interface{}) error {
if reflect.Ptr == vVal.Kind() && !vVal.IsNil() {
return e.Encode(vVal.Elem().Interface())
}
switch t.Kind() {
case reflect.Bool:
vv := v.(*bool)
if vv != nil {
e.buffer = encBool(e.buffer, *vv)
} else {
e.buffer = encBool(e.buffer, false)
}
case reflect.Int32:
var err error
e.buffer, err = e.encTypeInt32(e.buffer, v)
if err != nil {
return err
}
}
case reflect.Struct:
vv := reflect.ValueOf(v)
vv = UnpackPtr(vv)

0 comments on commit 9c70e1f

Please sign in to comment.