Bugfix: Handling of struct fields
This commit is contained in:
parent
0f098d731c
commit
5e0ae8c260
12
marshal.go
12
marshal.go
|
@ -168,7 +168,6 @@ func init() {
|
|||
}
|
||||
|
||||
func encRegister(e interface{}) (err error) {
|
||||
v := reflect.ValueOf(e)
|
||||
t := reflect.TypeOf(e)
|
||||
switch t.Kind() {
|
||||
case reflect.Invalid:
|
||||
|
@ -257,6 +256,7 @@ func encRegister(e interface{}) (err error) {
|
|||
}
|
||||
|
||||
f := func(e interface{}) (ret []byte, err error) {
|
||||
v := reflect.ValueOf(e)
|
||||
bs := make([][]byte, n)
|
||||
blen := 0
|
||||
for _, i := range mfields {
|
||||
|
@ -276,51 +276,61 @@ func encRegister(e interface{}) (err error) {
|
|||
encoderCache[t.Name()] = f
|
||||
case reflect.Bool:
|
||||
f := func(e interface{}) (ret []byte, err error) {
|
||||
v := reflect.ValueOf(e)
|
||||
return marshalBaseType(bool(v.Bool()))
|
||||
}
|
||||
encoderCache[t.Name()] = f
|
||||
case reflect.Uint8:
|
||||
f := func(e interface{}) (ret []byte, err error) {
|
||||
v := reflect.ValueOf(e)
|
||||
return marshalBaseType(uint8(v.Uint()))
|
||||
}
|
||||
encoderCache[t.Name()] = f
|
||||
case reflect.Uint16:
|
||||
f := func(e interface{}) (ret []byte, err error) {
|
||||
v := reflect.ValueOf(e)
|
||||
return marshalBaseType(uint16(v.Uint()))
|
||||
}
|
||||
encoderCache[t.Name()] = f
|
||||
case reflect.Uint32:
|
||||
f := func(e interface{}) (ret []byte, err error) {
|
||||
v := reflect.ValueOf(e)
|
||||
return marshalBaseType(uint32(v.Uint()))
|
||||
}
|
||||
encoderCache[t.Name()] = f
|
||||
case reflect.Uint64:
|
||||
f := func(e interface{}) (ret []byte, err error) {
|
||||
v := reflect.ValueOf(e)
|
||||
return marshalBaseType(uint64(v.Uint()))
|
||||
}
|
||||
encoderCache[t.Name()] = f
|
||||
case reflect.Int8:
|
||||
f := func(e interface{}) (ret []byte, err error) {
|
||||
v := reflect.ValueOf(e)
|
||||
return marshalBaseType(int8(v.Uint()))
|
||||
}
|
||||
encoderCache[t.Name()] = f
|
||||
case reflect.Int16:
|
||||
f := func(e interface{}) (ret []byte, err error) {
|
||||
v := reflect.ValueOf(e)
|
||||
return marshalBaseType(int16(v.Uint()))
|
||||
}
|
||||
encoderCache[t.Name()] = f
|
||||
case reflect.Int32:
|
||||
f := func(e interface{}) (ret []byte, err error) {
|
||||
v := reflect.ValueOf(e)
|
||||
return marshalBaseType(int32(v.Uint()))
|
||||
}
|
||||
encoderCache[t.Name()] = f
|
||||
case reflect.Int64:
|
||||
f := func(e interface{}) (ret []byte, err error) {
|
||||
v := reflect.ValueOf(e)
|
||||
return marshalBaseType(int64(v.Uint()))
|
||||
}
|
||||
encoderCache[t.Name()] = f
|
||||
case reflect.String:
|
||||
f := func(e interface{}) (ret []byte, err error) {
|
||||
v := reflect.ValueOf(e)
|
||||
return marshalBaseType(string(v.String()))
|
||||
}
|
||||
encoderCache[t.Name()] = f
|
||||
|
|
|
@ -278,7 +278,6 @@ func init() {
|
|||
}
|
||||
|
||||
func encRegisterUnsafe(e interface{}) (err error) {
|
||||
v := reflect.ValueOf(e)
|
||||
t := reflect.TypeOf(e)
|
||||
switch t.Kind() {
|
||||
case reflect.Invalid:
|
||||
|
@ -367,6 +366,7 @@ func encRegisterUnsafe(e interface{}) (err error) {
|
|||
}
|
||||
|
||||
f := func(e interface{}) (ret []byte, err error) {
|
||||
v := reflect.ValueOf(e)
|
||||
bs := make([][]byte, n)
|
||||
blen := 0
|
||||
for _, i := range mfields {
|
||||
|
@ -386,51 +386,61 @@ func encRegisterUnsafe(e interface{}) (err error) {
|
|||
unsafeEncoderCache[t.Name()] = f
|
||||
case reflect.Bool:
|
||||
f := func(e interface{}) (ret []byte, err error) {
|
||||
v := reflect.ValueOf(e)
|
||||
return unsafeMarshalBaseType(bool(v.Bool()))
|
||||
}
|
||||
unsafeEncoderCache[t.Name()] = f
|
||||
case reflect.Uint8:
|
||||
f := func(e interface{}) (ret []byte, err error) {
|
||||
v := reflect.ValueOf(e)
|
||||
return unsafeMarshalBaseType(string(v.String()))
|
||||
}
|
||||
unsafeEncoderCache[t.Name()] = f
|
||||
case reflect.Uint16:
|
||||
f := func(e interface{}) (ret []byte, err error) {
|
||||
v := reflect.ValueOf(e)
|
||||
return unsafeMarshalBaseType(string(v.String()))
|
||||
}
|
||||
unsafeEncoderCache[t.Name()] = f
|
||||
case reflect.Uint32:
|
||||
f := func(e interface{}) (ret []byte, err error) {
|
||||
v := reflect.ValueOf(e)
|
||||
return unsafeMarshalBaseType(string(v.String()))
|
||||
}
|
||||
unsafeEncoderCache[t.Name()] = f
|
||||
case reflect.Uint64:
|
||||
f := func(e interface{}) (ret []byte, err error) {
|
||||
v := reflect.ValueOf(e)
|
||||
return unsafeMarshalBaseType(string(v.String()))
|
||||
}
|
||||
unsafeEncoderCache[t.Name()] = f
|
||||
case reflect.Int8:
|
||||
f := func(e interface{}) (ret []byte, err error) {
|
||||
v := reflect.ValueOf(e)
|
||||
return unsafeMarshalBaseType(string(v.String()))
|
||||
}
|
||||
unsafeEncoderCache[t.Name()] = f
|
||||
case reflect.Int16:
|
||||
f := func(e interface{}) (ret []byte, err error) {
|
||||
v := reflect.ValueOf(e)
|
||||
return unsafeMarshalBaseType(string(v.String()))
|
||||
}
|
||||
unsafeEncoderCache[t.Name()] = f
|
||||
case reflect.Int32:
|
||||
f := func(e interface{}) (ret []byte, err error) {
|
||||
v := reflect.ValueOf(e)
|
||||
return unsafeMarshalBaseType(string(v.String()))
|
||||
}
|
||||
unsafeEncoderCache[t.Name()] = f
|
||||
case reflect.Int64:
|
||||
f := func(e interface{}) (ret []byte, err error) {
|
||||
v := reflect.ValueOf(e)
|
||||
return unsafeMarshalBaseType(string(v.String()))
|
||||
}
|
||||
unsafeEncoderCache[t.Name()] = f
|
||||
case reflect.String:
|
||||
f := func(e interface{}) (ret []byte, err error) {
|
||||
v := reflect.ValueOf(e)
|
||||
return unsafeMarshalBaseType(string(v.String()))
|
||||
}
|
||||
unsafeEncoderCache[t.Name()] = f
|
||||
|
|
Loading…
Reference in New Issue