feature_reflect_native.go 4.1 KB

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