feature_reflect_native.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. package jsoniter
  2. import "unsafe"
  3. type stringCodec struct {
  4. }
  5. func (codec *stringCodec) decode(ptr unsafe.Pointer, iter *Iterator) {
  6. *((*string)(ptr)) = iter.ReadString()
  7. }
  8. func (codec *stringCodec) encode(ptr unsafe.Pointer, stream *Stream) {
  9. stream.WriteString(*((*string)(ptr)))
  10. }
  11. type intCodec struct {
  12. }
  13. func (codec *intCodec) decode(ptr unsafe.Pointer, iter *Iterator) {
  14. *((*int)(ptr)) = iter.ReadInt()
  15. }
  16. func (codec *intCodec) encode(ptr unsafe.Pointer, stream *Stream) {
  17. stream.WriteInt(*((*int)(ptr)))
  18. }
  19. type int8Codec struct {
  20. }
  21. func (codec *int8Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
  22. *((*int8)(ptr)) = iter.ReadInt8()
  23. }
  24. func (codec *int8Codec) encode(ptr unsafe.Pointer, stream *Stream) {
  25. stream.WriteInt8(*((*int8)(ptr)))
  26. }
  27. type int16Codec struct {
  28. }
  29. func (codec *int16Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
  30. *((*int16)(ptr)) = iter.ReadInt16()
  31. }
  32. func (codec *int16Codec) encode(ptr unsafe.Pointer, stream *Stream) {
  33. stream.WriteInt16(*((*int16)(ptr)))
  34. }
  35. type int32Codec struct {
  36. }
  37. func (codec *int32Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
  38. *((*int32)(ptr)) = iter.ReadInt32()
  39. }
  40. func (codec *int32Codec) encode(ptr unsafe.Pointer, stream *Stream) {
  41. stream.WriteInt32(*((*int32)(ptr)))
  42. }
  43. type int64Codec struct {
  44. }
  45. func (codec *int64Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
  46. *((*int64)(ptr)) = iter.ReadInt64()
  47. }
  48. func (codec *int64Codec) encode(ptr unsafe.Pointer, stream *Stream) {
  49. stream.WriteInt64(*((*int64)(ptr)))
  50. }
  51. type uintCodec struct {
  52. }
  53. func (codec *uintCodec) decode(ptr unsafe.Pointer, iter *Iterator) {
  54. *((*uint)(ptr)) = iter.ReadUint()
  55. }
  56. func (codec *uintCodec) encode(ptr unsafe.Pointer, stream *Stream) {
  57. stream.WriteUint(*((*uint)(ptr)))
  58. }
  59. type uint8Codec struct {
  60. }
  61. func (codec *uint8Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
  62. *((*uint8)(ptr)) = iter.ReadUint8()
  63. }
  64. func (codec *uint8Codec) encode(ptr unsafe.Pointer, stream *Stream) {
  65. stream.WriteUint8(*((*uint8)(ptr)))
  66. }
  67. type uint16Codec struct {
  68. }
  69. func (decoder *uint16Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
  70. *((*uint16)(ptr)) = iter.ReadUint16()
  71. }
  72. func (decoder *uint16Codec) encode(ptr unsafe.Pointer, stream *Stream) {
  73. stream.WriteUint16(*((*uint16)(ptr)))
  74. }
  75. type uint32Codec struct {
  76. }
  77. func (codec *uint32Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
  78. *((*uint32)(ptr)) = iter.ReadUint32()
  79. }
  80. func (codec *uint32Codec) encode(ptr unsafe.Pointer, stream *Stream) {
  81. stream.WriteUint32(*((*uint32)(ptr)))
  82. }
  83. type uint64Codec struct {
  84. }
  85. func (codec *uint64Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
  86. *((*uint64)(ptr)) = iter.ReadUint64()
  87. }
  88. func (codec *uint64Codec) encode(ptr unsafe.Pointer, stream *Stream) {
  89. stream.WriteUint64(*((*uint64)(ptr)))
  90. }
  91. type float32Codec struct {
  92. }
  93. func (codec *float32Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
  94. *((*float32)(ptr)) = iter.ReadFloat32()
  95. }
  96. func (codec *float32Codec) encode(ptr unsafe.Pointer, stream *Stream) {
  97. stream.WriteFloat32(*((*float32)(ptr)))
  98. }
  99. type float64Codec struct {
  100. }
  101. func (codec *float64Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
  102. *((*float64)(ptr)) = iter.ReadFloat64()
  103. }
  104. func (codec *float64Codec) encode(ptr unsafe.Pointer, stream *Stream) {
  105. stream.WriteFloat64(*((*float64)(ptr)))
  106. }
  107. type boolCodec struct {
  108. }
  109. func (codec *boolCodec) decode(ptr unsafe.Pointer, iter *Iterator) {
  110. *((*bool)(ptr)) = iter.ReadBool()
  111. }
  112. func (codec *boolCodec) encode(ptr unsafe.Pointer, stream *Stream) {
  113. stream.WriteBool(*((*bool)(ptr)))
  114. }
  115. type interfaceCodec struct {
  116. }
  117. func (codec *interfaceCodec) decode(ptr unsafe.Pointer, iter *Iterator) {
  118. *((*interface{})(ptr)) = iter.Read()
  119. }
  120. func (codec *interfaceCodec) encode(ptr unsafe.Pointer, stream *Stream) {
  121. stream.WriteVal(*((*interface{})(ptr)))
  122. }
  123. type stringNumberDecoder struct {
  124. elemDecoder Decoder
  125. }
  126. func (decoder *stringNumberDecoder) decode(ptr unsafe.Pointer, iter *Iterator) {
  127. c := iter.nextToken()
  128. if c != '"' {
  129. iter.reportError("stringNumberDecoder", `expect "`)
  130. return
  131. }
  132. decoder.elemDecoder.decode(ptr, iter)
  133. if iter.Error != nil {
  134. return
  135. }
  136. c = iter.readByte()
  137. if c != '"' {
  138. iter.reportError("stringNumberDecoder", `expect "`)
  139. return
  140. }
  141. }