2017-01-06 14:17:47 +02:00
|
|
|
package jsoniter
|
|
|
|
|
2017-01-25 16:43:57 +02:00
|
|
|
import (
|
2017-06-06 03:44:56 +02:00
|
|
|
"encoding/base64"
|
2017-06-06 17:27:00 +02:00
|
|
|
"encoding/json"
|
|
|
|
"unsafe"
|
2017-01-25 16:43:57 +02:00
|
|
|
)
|
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-06-20 09:11:01 +02:00
|
|
|
func (codec *stringCodec) Decode(ptr unsafe.Pointer, iter *Iterator) {
|
2017-01-06 14:17:47 +02:00
|
|
|
*((*string)(ptr)) = iter.ReadString()
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *stringCodec) Encode(ptr unsafe.Pointer, stream *Stream) {
|
2017-05-23 11:44:50 +02:00
|
|
|
str := *((*string)(ptr))
|
|
|
|
stream.WriteString(str)
|
2017-01-06 14:17:47 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *stringCodec) EncodeInterface(val interface{}, stream *Stream) {
|
2017-06-20 01:46:13 +02:00
|
|
|
writeToStream(val, stream, codec)
|
2017-01-25 18:25:17 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *stringCodec) IsEmpty(ptr unsafe.Pointer) bool {
|
2017-03-08 17:38:25 +02:00
|
|
|
return *((*string)(ptr)) == ""
|
|
|
|
}
|
|
|
|
|
2017-01-09 11:47:21 +02:00
|
|
|
type intCodec struct {
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *intCodec) Decode(ptr unsafe.Pointer, iter *Iterator) {
|
2017-01-06 14:17:47 +02:00
|
|
|
*((*int)(ptr)) = iter.ReadInt()
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *intCodec) Encode(ptr unsafe.Pointer, stream *Stream) {
|
2017-01-09 11:47:21 +02:00
|
|
|
stream.WriteInt(*((*int)(ptr)))
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *intCodec) EncodeInterface(val interface{}, stream *Stream) {
|
2017-05-23 11:44:50 +02:00
|
|
|
writeToStream(val, stream, encoder)
|
2017-01-25 18:25:17 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *intCodec) IsEmpty(ptr unsafe.Pointer) bool {
|
2017-03-08 17:38:25 +02:00
|
|
|
return *((*int)(ptr)) == 0
|
|
|
|
}
|
|
|
|
|
2017-01-09 13:19:48 +02:00
|
|
|
type int8Codec struct {
|
2017-01-06 14:17:47 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *int8Codec) Decode(ptr unsafe.Pointer, iter *Iterator) {
|
2017-01-06 14:17:47 +02:00
|
|
|
*((*int8)(ptr)) = iter.ReadInt8()
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *int8Codec) Encode(ptr unsafe.Pointer, stream *Stream) {
|
2017-01-09 13:19:48 +02:00
|
|
|
stream.WriteInt8(*((*int8)(ptr)))
|
2017-01-06 14:17:47 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *int8Codec) EncodeInterface(val interface{}, stream *Stream) {
|
2017-05-23 11:44:50 +02:00
|
|
|
writeToStream(val, stream, encoder)
|
2017-01-25 18:25:17 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *int8Codec) IsEmpty(ptr unsafe.Pointer) bool {
|
2017-03-08 17:38:25 +02:00
|
|
|
return *((*int8)(ptr)) == 0
|
|
|
|
}
|
|
|
|
|
2017-01-09 13:19:48 +02:00
|
|
|
type int16Codec struct {
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *int16Codec) Decode(ptr unsafe.Pointer, iter *Iterator) {
|
2017-01-06 14:17:47 +02:00
|
|
|
*((*int16)(ptr)) = iter.ReadInt16()
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *int16Codec) Encode(ptr unsafe.Pointer, stream *Stream) {
|
2017-01-09 13:19:48 +02:00
|
|
|
stream.WriteInt16(*((*int16)(ptr)))
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *int16Codec) EncodeInterface(val interface{}, stream *Stream) {
|
2017-05-23 11:44:50 +02:00
|
|
|
writeToStream(val, stream, encoder)
|
2017-01-25 18:25:17 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *int16Codec) IsEmpty(ptr unsafe.Pointer) bool {
|
2017-03-08 17:38:25 +02:00
|
|
|
return *((*int16)(ptr)) == 0
|
|
|
|
}
|
|
|
|
|
2017-01-09 13:19:48 +02:00
|
|
|
type int32Codec struct {
|
2017-01-06 14:17:47 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *int32Codec) Decode(ptr unsafe.Pointer, iter *Iterator) {
|
2017-01-06 14:17:47 +02:00
|
|
|
*((*int32)(ptr)) = iter.ReadInt32()
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *int32Codec) Encode(ptr unsafe.Pointer, stream *Stream) {
|
2017-01-09 13:19:48 +02:00
|
|
|
stream.WriteInt32(*((*int32)(ptr)))
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *int32Codec) EncodeInterface(val interface{}, stream *Stream) {
|
2017-05-23 11:44:50 +02:00
|
|
|
writeToStream(val, stream, encoder)
|
2017-01-25 18:25:17 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *int32Codec) IsEmpty(ptr unsafe.Pointer) bool {
|
2017-03-08 17:38:25 +02:00
|
|
|
return *((*int32)(ptr)) == 0
|
|
|
|
}
|
|
|
|
|
2017-01-09 13:19:48 +02:00
|
|
|
type int64Codec struct {
|
2017-01-06 14:17:47 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *int64Codec) Decode(ptr unsafe.Pointer, iter *Iterator) {
|
2017-01-06 14:17:47 +02:00
|
|
|
*((*int64)(ptr)) = iter.ReadInt64()
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *int64Codec) Encode(ptr unsafe.Pointer, stream *Stream) {
|
2017-01-09 13:19:48 +02:00
|
|
|
stream.WriteInt64(*((*int64)(ptr)))
|
2017-01-06 14:17:47 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *int64Codec) EncodeInterface(val interface{}, stream *Stream) {
|
2017-05-23 11:44:50 +02:00
|
|
|
writeToStream(val, stream, encoder)
|
2017-01-25 18:25:17 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *int64Codec) IsEmpty(ptr unsafe.Pointer) bool {
|
2017-03-08 17:38:25 +02:00
|
|
|
return *((*int64)(ptr)) == 0
|
|
|
|
}
|
|
|
|
|
2017-01-09 13:19:48 +02:00
|
|
|
type uintCodec struct {
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *uintCodec) Decode(ptr unsafe.Pointer, iter *Iterator) {
|
2017-01-06 14:17:47 +02:00
|
|
|
*((*uint)(ptr)) = iter.ReadUint()
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *uintCodec) Encode(ptr unsafe.Pointer, stream *Stream) {
|
2017-01-09 13:19:48 +02:00
|
|
|
stream.WriteUint(*((*uint)(ptr)))
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *uintCodec) EncodeInterface(val interface{}, stream *Stream) {
|
2017-05-23 11:44:50 +02:00
|
|
|
writeToStream(val, stream, encoder)
|
2017-01-25 18:25:17 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *uintCodec) IsEmpty(ptr unsafe.Pointer) bool {
|
2017-03-08 17:38:25 +02:00
|
|
|
return *((*uint)(ptr)) == 0
|
|
|
|
}
|
|
|
|
|
2017-01-09 13:19:48 +02:00
|
|
|
type uint8Codec struct {
|
2017-01-06 14:17:47 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *uint8Codec) Decode(ptr unsafe.Pointer, iter *Iterator) {
|
2017-01-06 14:17:47 +02:00
|
|
|
*((*uint8)(ptr)) = iter.ReadUint8()
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *uint8Codec) Encode(ptr unsafe.Pointer, stream *Stream) {
|
2017-01-09 13:19:48 +02:00
|
|
|
stream.WriteUint8(*((*uint8)(ptr)))
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *uint8Codec) EncodeInterface(val interface{}, stream *Stream) {
|
2017-05-23 11:44:50 +02:00
|
|
|
writeToStream(val, stream, encoder)
|
2017-01-25 18:25:17 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *uint8Codec) IsEmpty(ptr unsafe.Pointer) bool {
|
2017-03-08 17:38:25 +02:00
|
|
|
return *((*uint8)(ptr)) == 0
|
|
|
|
}
|
|
|
|
|
2017-01-09 13:19:48 +02:00
|
|
|
type uint16Codec struct {
|
2017-01-06 14:17:47 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (decoder *uint16Codec) Decode(ptr unsafe.Pointer, iter *Iterator) {
|
2017-01-06 14:17:47 +02:00
|
|
|
*((*uint16)(ptr)) = iter.ReadUint16()
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +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-06-20 09:11:01 +02:00
|
|
|
func (encoder *uint16Codec) EncodeInterface(val interface{}, stream *Stream) {
|
2017-05-23 11:44:50 +02:00
|
|
|
writeToStream(val, stream, encoder)
|
2017-01-25 18:25:17 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *uint16Codec) IsEmpty(ptr unsafe.Pointer) bool {
|
2017-03-08 17:38:25 +02:00
|
|
|
return *((*uint16)(ptr)) == 0
|
|
|
|
}
|
|
|
|
|
2017-01-09 13:19:48 +02:00
|
|
|
type uint32Codec struct {
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *uint32Codec) Decode(ptr unsafe.Pointer, iter *Iterator) {
|
2017-01-06 14:17:47 +02:00
|
|
|
*((*uint32)(ptr)) = iter.ReadUint32()
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *uint32Codec) Encode(ptr unsafe.Pointer, stream *Stream) {
|
2017-01-09 13:19:48 +02:00
|
|
|
stream.WriteUint32(*((*uint32)(ptr)))
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *uint32Codec) EncodeInterface(val interface{}, stream *Stream) {
|
2017-05-23 11:44:50 +02:00
|
|
|
writeToStream(val, stream, encoder)
|
2017-01-25 18:25:17 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *uint32Codec) IsEmpty(ptr unsafe.Pointer) bool {
|
2017-03-08 17:38:25 +02:00
|
|
|
return *((*uint32)(ptr)) == 0
|
|
|
|
}
|
|
|
|
|
2017-01-09 13:19:48 +02:00
|
|
|
type uint64Codec struct {
|
2017-01-06 14:17:47 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *uint64Codec) Decode(ptr unsafe.Pointer, iter *Iterator) {
|
2017-01-06 14:17:47 +02:00
|
|
|
*((*uint64)(ptr)) = iter.ReadUint64()
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *uint64Codec) Encode(ptr unsafe.Pointer, stream *Stream) {
|
2017-01-09 13:19:48 +02:00
|
|
|
stream.WriteUint64(*((*uint64)(ptr)))
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *uint64Codec) EncodeInterface(val interface{}, stream *Stream) {
|
2017-05-23 11:44:50 +02:00
|
|
|
writeToStream(val, stream, encoder)
|
2017-01-25 18:25:17 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *uint64Codec) IsEmpty(ptr unsafe.Pointer) bool {
|
2017-03-08 17:38:25 +02:00
|
|
|
return *((*uint64)(ptr)) == 0
|
|
|
|
}
|
|
|
|
|
2017-01-09 13:19:48 +02:00
|
|
|
type float32Codec struct {
|
2017-01-06 14:17:47 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *float32Codec) Decode(ptr unsafe.Pointer, iter *Iterator) {
|
2017-01-06 14:17:47 +02:00
|
|
|
*((*float32)(ptr)) = iter.ReadFloat32()
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *float32Codec) Encode(ptr unsafe.Pointer, stream *Stream) {
|
2017-01-09 13:19:48 +02:00
|
|
|
stream.WriteFloat32(*((*float32)(ptr)))
|
2017-01-06 14:17:47 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *float32Codec) EncodeInterface(val interface{}, stream *Stream) {
|
2017-05-23 11:44:50 +02:00
|
|
|
writeToStream(val, stream, encoder)
|
2017-01-25 18:25:17 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *float32Codec) IsEmpty(ptr unsafe.Pointer) bool {
|
2017-03-08 17:38:25 +02:00
|
|
|
return *((*float32)(ptr)) == 0
|
|
|
|
}
|
|
|
|
|
2017-01-09 13:19:48 +02:00
|
|
|
type float64Codec struct {
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *float64Codec) Decode(ptr unsafe.Pointer, iter *Iterator) {
|
2017-01-06 14:17:47 +02:00
|
|
|
*((*float64)(ptr)) = iter.ReadFloat64()
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *float64Codec) Encode(ptr unsafe.Pointer, stream *Stream) {
|
2017-01-09 13:19:48 +02:00
|
|
|
stream.WriteFloat64(*((*float64)(ptr)))
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *float64Codec) EncodeInterface(val interface{}, stream *Stream) {
|
2017-05-23 11:44:50 +02:00
|
|
|
writeToStream(val, stream, encoder)
|
2017-01-25 18:25:17 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *float64Codec) IsEmpty(ptr unsafe.Pointer) bool {
|
2017-03-08 17:38:25 +02:00
|
|
|
return *((*float64)(ptr)) == 0
|
|
|
|
}
|
|
|
|
|
2017-01-09 13:19:48 +02:00
|
|
|
type boolCodec struct {
|
2017-01-06 14:17:47 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *boolCodec) Decode(ptr unsafe.Pointer, iter *Iterator) {
|
2017-01-06 14:17:47 +02:00
|
|
|
*((*bool)(ptr)) = iter.ReadBool()
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *boolCodec) Encode(ptr unsafe.Pointer, stream *Stream) {
|
2017-01-09 13:19:48 +02:00
|
|
|
stream.WriteBool(*((*bool)(ptr)))
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *boolCodec) EncodeInterface(val interface{}, stream *Stream) {
|
2017-05-23 11:44:50 +02:00
|
|
|
writeToStream(val, stream, encoder)
|
2017-01-25 18:25:17 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *boolCodec) IsEmpty(ptr unsafe.Pointer) bool {
|
2017-03-08 17:38:25 +02:00
|
|
|
return !(*((*bool)(ptr)))
|
|
|
|
}
|
|
|
|
|
2017-05-26 18:36:21 +02:00
|
|
|
type emptyInterfaceCodec struct {
|
2017-01-06 14:17:47 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *emptyInterfaceCodec) 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-06-20 09:11:01 +02:00
|
|
|
func (codec *emptyInterfaceCodec) Encode(ptr unsafe.Pointer, stream *Stream) {
|
2017-01-09 15:00:01 +02:00
|
|
|
stream.WriteVal(*((*interface{})(ptr)))
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *emptyInterfaceCodec) EncodeInterface(val interface{}, stream *Stream) {
|
2017-02-03 12:44:54 +02:00
|
|
|
stream.WriteVal(val)
|
2017-01-25 18:25:17 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *emptyInterfaceCodec) IsEmpty(ptr unsafe.Pointer) bool {
|
2017-03-08 17:38:25 +02:00
|
|
|
return ptr == nil
|
|
|
|
}
|
|
|
|
|
2017-05-26 18:36:21 +02:00
|
|
|
type nonEmptyInterfaceCodec struct {
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *nonEmptyInterfaceCodec) Decode(ptr unsafe.Pointer, iter *Iterator) {
|
2017-05-26 18:36:21 +02:00
|
|
|
nonEmptyInterface := (*nonEmptyInterface)(ptr)
|
2017-06-09 11:06:27 +02:00
|
|
|
if nonEmptyInterface.itab == nil {
|
2017-06-20 09:11:01 +02:00
|
|
|
iter.ReportError("read non-empty interface", "do not know which concrete type to decode to")
|
2017-06-09 11:06:27 +02:00
|
|
|
return
|
|
|
|
}
|
2017-05-26 18:36:21 +02:00
|
|
|
var i interface{}
|
|
|
|
e := (*emptyInterface)(unsafe.Pointer(&i))
|
|
|
|
e.typ = nonEmptyInterface.itab.typ
|
|
|
|
e.word = nonEmptyInterface.word
|
|
|
|
iter.ReadVal(&i)
|
|
|
|
nonEmptyInterface.word = e.word
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *nonEmptyInterfaceCodec) Encode(ptr unsafe.Pointer, stream *Stream) {
|
2017-05-26 18:36:21 +02:00
|
|
|
nonEmptyInterface := (*nonEmptyInterface)(ptr)
|
|
|
|
var i interface{}
|
|
|
|
e := (*emptyInterface)(unsafe.Pointer(&i))
|
|
|
|
e.typ = nonEmptyInterface.itab.typ
|
|
|
|
e.word = nonEmptyInterface.word
|
|
|
|
stream.WriteVal(i)
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *nonEmptyInterfaceCodec) EncodeInterface(val interface{}, stream *Stream) {
|
2017-05-26 18:36:21 +02:00
|
|
|
stream.WriteVal(val)
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *nonEmptyInterfaceCodec) IsEmpty(ptr unsafe.Pointer) bool {
|
2017-05-26 18:36:21 +02:00
|
|
|
nonEmptyInterface := (*nonEmptyInterface)(ptr)
|
|
|
|
return nonEmptyInterface.word == nil
|
|
|
|
}
|
|
|
|
|
2017-01-25 18:25:17 +02:00
|
|
|
type anyCodec struct {
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *anyCodec) Decode(ptr unsafe.Pointer, iter *Iterator) {
|
2017-01-25 18:25:17 +02:00
|
|
|
*((*Any)(ptr)) = iter.ReadAny()
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *anyCodec) Encode(ptr unsafe.Pointer, stream *Stream) {
|
2017-01-25 18:25:17 +02:00
|
|
|
(*((*Any)(ptr))).WriteTo(stream)
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *anyCodec) EncodeInterface(val interface{}, stream *Stream) {
|
2017-01-25 18:25:17 +02:00
|
|
|
(val.(Any)).WriteTo(stream)
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *anyCodec) IsEmpty(ptr unsafe.Pointer) bool {
|
2017-03-08 17:38:25 +02:00
|
|
|
return (*((*Any)(ptr))).Size() == 0
|
|
|
|
}
|
|
|
|
|
2017-06-02 04:21:43 +02:00
|
|
|
type jsonNumberCodec struct {
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *jsonNumberCodec) Decode(ptr unsafe.Pointer, iter *Iterator) {
|
2017-06-02 04:21:43 +02:00
|
|
|
*((*json.Number)(ptr)) = json.Number([]byte(iter.readNumberAsString()))
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *jsonNumberCodec) Encode(ptr unsafe.Pointer, stream *Stream) {
|
2017-06-02 04:21:43 +02:00
|
|
|
stream.WriteRaw(string(*((*json.Number)(ptr))))
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *jsonNumberCodec) EncodeInterface(val interface{}, stream *Stream) {
|
2017-06-02 04:21:43 +02:00
|
|
|
stream.WriteRaw(string(val.(json.Number)))
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *jsonNumberCodec) IsEmpty(ptr unsafe.Pointer) bool {
|
2017-06-02 04:21:43 +02:00
|
|
|
return len(*((*json.Number)(ptr))) == 0
|
|
|
|
}
|
|
|
|
|
2017-06-02 04:50:23 +02:00
|
|
|
type jsonRawMessageCodec struct {
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *jsonRawMessageCodec) Decode(ptr unsafe.Pointer, iter *Iterator) {
|
2017-06-02 04:50:23 +02:00
|
|
|
*((*json.RawMessage)(ptr)) = json.RawMessage(iter.SkipAndReturnBytes())
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *jsonRawMessageCodec) Encode(ptr unsafe.Pointer, stream *Stream) {
|
2017-06-02 04:50:23 +02:00
|
|
|
stream.WriteRaw(string(*((*json.RawMessage)(ptr))))
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *jsonRawMessageCodec) EncodeInterface(val interface{}, stream *Stream) {
|
2017-06-02 04:50:23 +02:00
|
|
|
stream.WriteRaw(string(val.(json.RawMessage)))
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *jsonRawMessageCodec) IsEmpty(ptr unsafe.Pointer) bool {
|
2017-06-02 04:50:23 +02:00
|
|
|
return len(*((*json.RawMessage)(ptr))) == 0
|
|
|
|
}
|
|
|
|
|
2017-06-19 17:10:20 +02:00
|
|
|
type jsoniterRawMessageCodec struct {
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *jsoniterRawMessageCodec) Decode(ptr unsafe.Pointer, iter *Iterator) {
|
2017-06-19 17:10:20 +02:00
|
|
|
*((*RawMessage)(ptr)) = RawMessage(iter.SkipAndReturnBytes())
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *jsoniterRawMessageCodec) Encode(ptr unsafe.Pointer, stream *Stream) {
|
2017-06-19 17:10:20 +02:00
|
|
|
stream.WriteRaw(string(*((*RawMessage)(ptr))))
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *jsoniterRawMessageCodec) EncodeInterface(val interface{}, stream *Stream) {
|
2017-06-19 17:10:20 +02:00
|
|
|
stream.WriteRaw(string(val.(RawMessage)))
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *jsoniterRawMessageCodec) IsEmpty(ptr unsafe.Pointer) bool {
|
2017-06-19 17:10:20 +02:00
|
|
|
return len(*((*RawMessage)(ptr))) == 0
|
|
|
|
}
|
|
|
|
|
2017-06-06 03:44:56 +02:00
|
|
|
type base64Codec struct {
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *base64Codec) Decode(ptr unsafe.Pointer, iter *Iterator) {
|
2017-06-06 03:44:56 +02:00
|
|
|
encoding := base64.StdEncoding
|
|
|
|
src := iter.SkipAndReturnBytes()
|
2017-06-06 17:27:00 +02:00
|
|
|
src = src[1 : len(src)-1]
|
2017-06-06 03:44:56 +02:00
|
|
|
decodedLen := encoding.DecodedLen(len(src))
|
|
|
|
dst := make([]byte, decodedLen)
|
|
|
|
_, err := encoding.Decode(dst, src)
|
|
|
|
if err != nil {
|
2017-06-20 09:11:01 +02:00
|
|
|
iter.ReportError("decode base64", err.Error())
|
2017-06-06 03:44:56 +02:00
|
|
|
} else {
|
|
|
|
*((*[]byte)(ptr)) = dst
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (codec *base64Codec) Encode(ptr unsafe.Pointer, stream *Stream) {
|
2017-06-06 03:44:56 +02:00
|
|
|
encoding := base64.StdEncoding
|
|
|
|
stream.writeByte('"')
|
|
|
|
src := *((*[]byte)(ptr))
|
|
|
|
toGrow := encoding.EncodedLen(len(src))
|
|
|
|
stream.ensure(toGrow)
|
|
|
|
encoding.Encode(stream.buf[stream.n:], src)
|
|
|
|
stream.n += toGrow
|
|
|
|
stream.writeByte('"')
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *base64Codec) EncodeInterface(val interface{}, stream *Stream) {
|
2017-06-06 03:44:56 +02:00
|
|
|
encoding := base64.StdEncoding
|
|
|
|
stream.writeByte('"')
|
|
|
|
src := val.([]byte)
|
|
|
|
toGrow := encoding.EncodedLen(len(src))
|
|
|
|
stream.ensure(toGrow)
|
|
|
|
encoding.Encode(stream.buf[stream.n:], src)
|
|
|
|
stream.n += toGrow
|
|
|
|
stream.writeByte('"')
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *base64Codec) IsEmpty(ptr unsafe.Pointer) bool {
|
2017-06-06 03:44:56 +02:00
|
|
|
return len(*((*[]byte)(ptr))) == 0
|
|
|
|
}
|
|
|
|
|
2017-06-17 05:38:09 +02:00
|
|
|
type stringModeDecoder struct {
|
2017-06-20 01:59:45 +02:00
|
|
|
elemDecoder ValDecoder
|
2017-01-06 14:17:47 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (decoder *stringModeDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
|
2017-01-06 14:17:47 +02:00
|
|
|
c := iter.nextToken()
|
|
|
|
if c != '"' {
|
2017-06-20 09:11:01 +02:00
|
|
|
iter.ReportError("stringModeDecoder", `expect "`)
|
2017-01-06 14:17:47 +02:00
|
|
|
return
|
|
|
|
}
|
2017-06-20 09:11:01 +02:00
|
|
|
decoder.elemDecoder.Decode(ptr, iter)
|
2017-01-06 14:17:47 +02:00
|
|
|
if iter.Error != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
c = iter.readByte()
|
|
|
|
if c != '"' {
|
2017-06-20 09:11:01 +02:00
|
|
|
iter.ReportError("stringModeDecoder", `expect "`)
|
2017-01-06 14:17:47 +02:00
|
|
|
return
|
|
|
|
}
|
2017-05-24 08:34:00 +02:00
|
|
|
}
|
|
|
|
|
2017-06-17 05:38:09 +02:00
|
|
|
type stringModeEncoder struct {
|
2017-06-20 01:59:45 +02:00
|
|
|
elemEncoder ValEncoder
|
2017-06-17 05:38:09 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *stringModeEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
|
2017-06-17 05:38:09 +02:00
|
|
|
stream.writeByte('"')
|
2017-06-20 09:11:01 +02:00
|
|
|
encoder.elemEncoder.Encode(ptr, stream)
|
2017-06-17 05:38:09 +02:00
|
|
|
stream.writeByte('"')
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *stringModeEncoder) EncodeInterface(val interface{}, stream *Stream) {
|
2017-06-17 05:38:09 +02:00
|
|
|
writeToStream(val, stream, encoder)
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *stringModeEncoder) IsEmpty(ptr unsafe.Pointer) bool {
|
|
|
|
return encoder.elemEncoder.IsEmpty(ptr)
|
2017-06-17 05:38:09 +02:00
|
|
|
}
|
|
|
|
|
2017-05-24 08:34:00 +02:00
|
|
|
type marshalerEncoder struct {
|
|
|
|
templateInterface emptyInterface
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *marshalerEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
|
2017-05-24 08:34:00 +02:00
|
|
|
templateInterface := encoder.templateInterface
|
|
|
|
templateInterface.word = ptr
|
|
|
|
realInterface := (*interface{})(unsafe.Pointer(&templateInterface))
|
|
|
|
marshaler := (*realInterface).(json.Marshaler)
|
|
|
|
bytes, err := marshaler.MarshalJSON()
|
|
|
|
if err != nil {
|
|
|
|
stream.Error = err
|
|
|
|
} else {
|
|
|
|
stream.Write(bytes)
|
|
|
|
}
|
|
|
|
}
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *marshalerEncoder) EncodeInterface(val interface{}, stream *Stream) {
|
2017-05-24 08:34:00 +02:00
|
|
|
writeToStream(val, stream, encoder)
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (encoder *marshalerEncoder) IsEmpty(ptr unsafe.Pointer) bool {
|
2017-05-24 08:34:00 +02:00
|
|
|
templateInterface := encoder.templateInterface
|
|
|
|
templateInterface.word = ptr
|
|
|
|
realInterface := (*interface{})(unsafe.Pointer(&templateInterface))
|
|
|
|
marshaler := (*realInterface).(json.Marshaler)
|
|
|
|
bytes, err := marshaler.MarshalJSON()
|
|
|
|
if err != nil {
|
|
|
|
return true
|
|
|
|
} else {
|
|
|
|
return len(bytes) > 0
|
|
|
|
}
|
2017-05-24 10:04:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type unmarshalerDecoder struct {
|
|
|
|
templateInterface emptyInterface
|
|
|
|
}
|
|
|
|
|
2017-06-20 09:11:01 +02:00
|
|
|
func (decoder *unmarshalerDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
|
2017-05-24 10:04:11 +02:00
|
|
|
templateInterface := decoder.templateInterface
|
|
|
|
templateInterface.word = ptr
|
|
|
|
realInterface := (*interface{})(unsafe.Pointer(&templateInterface))
|
|
|
|
unmarshaler := (*realInterface).(json.Unmarshaler)
|
|
|
|
bytes := iter.SkipAndReturnBytes()
|
|
|
|
err := unmarshaler.UnmarshalJSON(bytes)
|
|
|
|
if err != nil {
|
2017-06-20 09:11:01 +02:00
|
|
|
iter.ReportError("unmarshaler", err.Error())
|
2017-05-24 10:04:11 +02:00
|
|
|
}
|
2017-06-06 03:44:56 +02:00
|
|
|
}
|