1
0
mirror of https://github.com/json-iterator/go.git synced 2024-11-27 08:30:57 +02:00
json-iterator/feature_reflect_native.go

192 lines
4.2 KiB
Go
Raw Normal View History

2017-01-06 14:17:47 +02:00
package jsoniter
import "unsafe"
2017-01-09 11:47:21 +02:00
type stringCodec struct {
2017-01-06 14:17:47 +02:00
}
2017-01-09 11:47:21 +02:00
func (codec *stringCodec) decode(ptr unsafe.Pointer, iter *Iterator) {
2017-01-06 14:17:47 +02:00
*((*string)(ptr)) = iter.ReadString()
}
2017-01-09 11:47:21 +02:00
func (codec *stringCodec) encode(ptr unsafe.Pointer, stream *Stream) {
stream.WriteString(*((*string)(ptr)))
2017-01-06 14:17:47 +02:00
}
2017-01-09 11:47:21 +02:00
type intCodec struct {
}
func (codec *intCodec) decode(ptr unsafe.Pointer, iter *Iterator) {
2017-01-06 14:17:47 +02:00
*((*int)(ptr)) = iter.ReadInt()
}
2017-01-09 11:47:21 +02:00
func (codec *intCodec) encode(ptr unsafe.Pointer, stream *Stream) {
stream.WriteInt(*((*int)(ptr)))
}
2017-01-09 13:19:48 +02:00
type int8Codec struct {
2017-01-06 14:17:47 +02:00
}
2017-01-09 13:19:48 +02:00
func (codec *int8Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
2017-01-06 14:17:47 +02:00
*((*int8)(ptr)) = iter.ReadInt8()
}
2017-01-09 13:19:48 +02:00
func (codec *int8Codec) encode(ptr unsafe.Pointer, stream *Stream) {
stream.WriteInt8(*((*int8)(ptr)))
2017-01-06 14:17:47 +02:00
}
2017-01-09 13:19:48 +02:00
type int16Codec struct {
}
func (codec *int16Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
2017-01-06 14:17:47 +02:00
*((*int16)(ptr)) = iter.ReadInt16()
}
2017-01-09 13:19:48 +02:00
func (codec *int16Codec) encode(ptr unsafe.Pointer, stream *Stream) {
stream.WriteInt16(*((*int16)(ptr)))
}
type int32Codec struct {
2017-01-06 14:17:47 +02:00
}
2017-01-09 13:19:48 +02:00
func (codec *int32Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
2017-01-06 14:17:47 +02:00
*((*int32)(ptr)) = iter.ReadInt32()
}
2017-01-09 13:19:48 +02:00
func (codec *int32Codec) encode(ptr unsafe.Pointer, stream *Stream) {
stream.WriteInt32(*((*int32)(ptr)))
}
type int64Codec struct {
2017-01-06 14:17:47 +02:00
}
2017-01-09 13:19:48 +02:00
func (codec *int64Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
2017-01-06 14:17:47 +02:00
*((*int64)(ptr)) = iter.ReadInt64()
}
2017-01-09 13:19:48 +02:00
func (codec *int64Codec) encode(ptr unsafe.Pointer, stream *Stream) {
stream.WriteInt64(*((*int64)(ptr)))
2017-01-06 14:17:47 +02:00
}
2017-01-09 13:19:48 +02:00
type uintCodec struct {
}
func (codec *uintCodec) decode(ptr unsafe.Pointer, iter *Iterator) {
2017-01-06 14:17:47 +02:00
*((*uint)(ptr)) = iter.ReadUint()
}
2017-01-09 13:19:48 +02:00
func (codec *uintCodec) encode(ptr unsafe.Pointer, stream *Stream) {
stream.WriteUint(*((*uint)(ptr)))
}
type uint8Codec struct {
2017-01-06 14:17:47 +02:00
}
2017-01-09 13:19:48 +02:00
func (codec *uint8Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
2017-01-06 14:17:47 +02:00
*((*uint8)(ptr)) = iter.ReadUint8()
}
2017-01-09 13:19:48 +02:00
func (codec *uint8Codec) encode(ptr unsafe.Pointer, stream *Stream) {
stream.WriteUint8(*((*uint8)(ptr)))
}
type uint16Codec struct {
2017-01-06 14:17:47 +02:00
}
2017-01-09 13:19:48 +02:00
func (decoder *uint16Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
2017-01-06 14:17:47 +02:00
*((*uint16)(ptr)) = iter.ReadUint16()
}
2017-01-09 13:19:48 +02:00
func (decoder *uint16Codec) encode(ptr unsafe.Pointer, stream *Stream) {
stream.WriteUint16(*((*uint16)(ptr)))
2017-01-06 14:17:47 +02:00
}
2017-01-09 13:19:48 +02:00
type uint32Codec struct {
}
func (codec *uint32Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
2017-01-06 14:17:47 +02:00
*((*uint32)(ptr)) = iter.ReadUint32()
}
2017-01-09 13:19:48 +02:00
func (codec *uint32Codec) encode(ptr unsafe.Pointer, stream *Stream) {
stream.WriteUint32(*((*uint32)(ptr)))
}
type uint64Codec struct {
2017-01-06 14:17:47 +02:00
}
2017-01-09 13:19:48 +02:00
func (codec *uint64Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
2017-01-06 14:17:47 +02:00
*((*uint64)(ptr)) = iter.ReadUint64()
}
2017-01-09 13:19:48 +02:00
func (codec *uint64Codec) encode(ptr unsafe.Pointer, stream *Stream) {
stream.WriteUint64(*((*uint64)(ptr)))
}
type float32Codec struct {
2017-01-06 14:17:47 +02:00
}
2017-01-09 13:19:48 +02:00
func (codec *float32Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
2017-01-06 14:17:47 +02:00
*((*float32)(ptr)) = iter.ReadFloat32()
}
2017-01-09 13:19:48 +02:00
func (codec *float32Codec) encode(ptr unsafe.Pointer, stream *Stream) {
stream.WriteFloat32(*((*float32)(ptr)))
2017-01-06 14:17:47 +02:00
}
2017-01-09 13:19:48 +02:00
type float64Codec struct {
}
func (codec *float64Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
2017-01-06 14:17:47 +02:00
*((*float64)(ptr)) = iter.ReadFloat64()
}
2017-01-09 13:19:48 +02:00
func (codec *float64Codec) encode(ptr unsafe.Pointer, stream *Stream) {
stream.WriteFloat64(*((*float64)(ptr)))
}
type boolCodec struct {
2017-01-06 14:17:47 +02:00
}
2017-01-09 13:19:48 +02:00
func (codec *boolCodec) decode(ptr unsafe.Pointer, iter *Iterator) {
2017-01-06 14:17:47 +02:00
*((*bool)(ptr)) = iter.ReadBool()
}
2017-01-09 13:19:48 +02:00
func (codec *boolCodec) encode(ptr unsafe.Pointer, stream *Stream) {
stream.WriteBool(*((*bool)(ptr)))
}
2017-01-06 14:17:47 +02:00
type interfaceDecoder struct {
}
func (decoder *interfaceDecoder) decode(ptr unsafe.Pointer, iter *Iterator) {
*((*interface{})(ptr)) = iter.ReadAny().Get()
}
type anyDecoder struct {
}
func (decoder *anyDecoder) decode(ptr unsafe.Pointer, iter *Iterator) {
*((*Any)(ptr)) = *iter.ReadAny()
}
type stringNumberDecoder struct {
elemDecoder Decoder
}
func (decoder *stringNumberDecoder) decode(ptr unsafe.Pointer, iter *Iterator) {
c := iter.nextToken()
if c != '"' {
iter.reportError("stringNumberDecoder", `expect "`)
return
}
decoder.elemDecoder.decode(ptr, iter)
if iter.Error != nil {
return
}
c = iter.readByte()
if c != '"' {
iter.reportError("stringNumberDecoder", `expect "`)
return
}
}