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

266 lines
6.2 KiB
Go
Raw Normal View History

2017-01-06 14:17:47 +02:00
package jsoniter
2017-01-25 16:43:57 +02:00
import (
"unsafe"
)
2017-01-06 14:17:47 +02:00
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-25 18:25:17 +02:00
func (encoder *stringCodec) encodeInterface(val interface{}, stream *Stream) {
WriteToStream(val, stream, encoder)
}
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-25 18:25:17 +02:00
func (encoder *intCodec) encodeInterface(val interface{}, stream *Stream) {
WriteToStream(val, stream, encoder)
}
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-25 18:25:17 +02:00
func (encoder *int8Codec) encodeInterface(val interface{}, stream *Stream) {
WriteToStream(val, stream, encoder)
}
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)))
}
2017-01-25 18:25:17 +02:00
func (encoder *int16Codec) encodeInterface(val interface{}, stream *Stream) {
WriteToStream(val, stream, encoder)
}
2017-01-09 13:19:48 +02:00
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)))
}
2017-01-25 18:25:17 +02:00
func (encoder *int32Codec) encodeInterface(val interface{}, stream *Stream) {
WriteToStream(val, stream, encoder)
}
2017-01-09 13:19:48 +02:00
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-25 18:25:17 +02:00
func (encoder *int64Codec) encodeInterface(val interface{}, stream *Stream) {
WriteToStream(val, stream, encoder)
}
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)))
}
2017-01-25 18:25:17 +02:00
func (encoder *uintCodec) encodeInterface(val interface{}, stream *Stream) {
WriteToStream(val, stream, encoder)
}
2017-01-09 13:19:48 +02:00
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)))
}
2017-01-25 18:25:17 +02:00
func (encoder *uint8Codec) encodeInterface(val interface{}, stream *Stream) {
WriteToStream(val, stream, encoder)
}
2017-01-09 13:19:48 +02:00
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-25 18:25:17 +02:00
func (codec *uint16Codec) encode(ptr unsafe.Pointer, stream *Stream) {
2017-01-09 13:19:48 +02:00
stream.WriteUint16(*((*uint16)(ptr)))
2017-01-06 14:17:47 +02:00
}
2017-01-25 18:25:17 +02:00
func (encoder *uint16Codec) encodeInterface(val interface{}, stream *Stream) {
WriteToStream(val, stream, encoder)
}
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)))
}
2017-01-25 18:25:17 +02:00
func (encoder *uint32Codec) encodeInterface(val interface{}, stream *Stream) {
WriteToStream(val, stream, encoder)
}
2017-01-09 13:19:48 +02:00
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)))
}
2017-01-25 18:25:17 +02:00
func (encoder *uint64Codec) encodeInterface(val interface{}, stream *Stream) {
WriteToStream(val, stream, encoder)
}
2017-01-09 13:19:48 +02:00
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-25 18:25:17 +02:00
func (encoder *float32Codec) encodeInterface(val interface{}, stream *Stream) {
WriteToStream(val, stream, encoder)
}
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)))
}
2017-01-25 18:25:17 +02:00
func (encoder *float64Codec) encodeInterface(val interface{}, stream *Stream) {
WriteToStream(val, stream, encoder)
}
2017-01-09 13:19:48 +02:00
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-25 18:25:17 +02:00
func (encoder *boolCodec) encodeInterface(val interface{}, stream *Stream) {
WriteToStream(val, stream, encoder)
}
2017-01-09 15:00:01 +02:00
type interfaceCodec struct {
2017-01-06 14:17:47 +02:00
}
2017-01-09 15:00:01 +02:00
func (codec *interfaceCodec) decode(ptr unsafe.Pointer, iter *Iterator) {
2017-01-22 13:36:19 +02:00
*((*interface{})(ptr)) = iter.Read()
2017-01-06 14:17:47 +02:00
}
2017-01-09 15:00:01 +02:00
func (codec *interfaceCodec) encode(ptr unsafe.Pointer, stream *Stream) {
stream.WriteVal(*((*interface{})(ptr)))
}
2017-01-25 18:25:17 +02:00
func (encoder *interfaceCodec) encodeInterface(val interface{}, stream *Stream) {
WriteToStream(val, stream, encoder)
}
type anyCodec struct {
}
func (codec *anyCodec) decode(ptr unsafe.Pointer, iter *Iterator) {
*((*Any)(ptr)) = iter.ReadAny()
}
func (codec *anyCodec) encode(ptr unsafe.Pointer, stream *Stream) {
(*((*Any)(ptr))).WriteTo(stream)
}
func (encoder *anyCodec) encodeInterface(val interface{}, stream *Stream) {
(val.(Any)).WriteTo(stream)
}
2017-01-06 14:17:47 +02:00
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
}
}