feature_reflect_native.go 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. func (encoder *stringCodec) encodeInterface(val interface{}, stream *Stream) {
  14. WriteToStream(val, stream, encoder)
  15. }
  16. func (codec *stringCodec) isEmpty(ptr unsafe.Pointer) bool {
  17. return *((*string)(ptr)) == ""
  18. }
  19. type intCodec struct {
  20. }
  21. func (codec *intCodec) decode(ptr unsafe.Pointer, iter *Iterator) {
  22. *((*int)(ptr)) = iter.ReadInt()
  23. }
  24. func (codec *intCodec) encode(ptr unsafe.Pointer, stream *Stream) {
  25. stream.WriteInt(*((*int)(ptr)))
  26. }
  27. func (encoder *intCodec) encodeInterface(val interface{}, stream *Stream) {
  28. WriteToStream(val, stream, encoder)
  29. }
  30. func (codec *intCodec) isEmpty(ptr unsafe.Pointer) bool {
  31. return *((*int)(ptr)) == 0
  32. }
  33. type int8Codec struct {
  34. }
  35. func (codec *int8Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
  36. *((*int8)(ptr)) = iter.ReadInt8()
  37. }
  38. func (codec *int8Codec) encode(ptr unsafe.Pointer, stream *Stream) {
  39. stream.WriteInt8(*((*int8)(ptr)))
  40. }
  41. func (encoder *int8Codec) encodeInterface(val interface{}, stream *Stream) {
  42. WriteToStream(val, stream, encoder)
  43. }
  44. func (codec *int8Codec) isEmpty(ptr unsafe.Pointer) bool {
  45. return *((*int8)(ptr)) == 0
  46. }
  47. type int16Codec struct {
  48. }
  49. func (codec *int16Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
  50. *((*int16)(ptr)) = iter.ReadInt16()
  51. }
  52. func (codec *int16Codec) encode(ptr unsafe.Pointer, stream *Stream) {
  53. stream.WriteInt16(*((*int16)(ptr)))
  54. }
  55. func (encoder *int16Codec) encodeInterface(val interface{}, stream *Stream) {
  56. WriteToStream(val, stream, encoder)
  57. }
  58. func (codec *int16Codec) isEmpty(ptr unsafe.Pointer) bool {
  59. return *((*int16)(ptr)) == 0
  60. }
  61. type int32Codec struct {
  62. }
  63. func (codec *int32Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
  64. *((*int32)(ptr)) = iter.ReadInt32()
  65. }
  66. func (codec *int32Codec) encode(ptr unsafe.Pointer, stream *Stream) {
  67. stream.WriteInt32(*((*int32)(ptr)))
  68. }
  69. func (encoder *int32Codec) encodeInterface(val interface{}, stream *Stream) {
  70. WriteToStream(val, stream, encoder)
  71. }
  72. func (codec *int32Codec) isEmpty(ptr unsafe.Pointer) bool {
  73. return *((*int32)(ptr)) == 0
  74. }
  75. type int64Codec struct {
  76. }
  77. func (codec *int64Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
  78. *((*int64)(ptr)) = iter.ReadInt64()
  79. }
  80. func (codec *int64Codec) encode(ptr unsafe.Pointer, stream *Stream) {
  81. stream.WriteInt64(*((*int64)(ptr)))
  82. }
  83. func (encoder *int64Codec) encodeInterface(val interface{}, stream *Stream) {
  84. WriteToStream(val, stream, encoder)
  85. }
  86. func (codec *int64Codec) isEmpty(ptr unsafe.Pointer) bool {
  87. return *((*int64)(ptr)) == 0
  88. }
  89. type uintCodec struct {
  90. }
  91. func (codec *uintCodec) decode(ptr unsafe.Pointer, iter *Iterator) {
  92. *((*uint)(ptr)) = iter.ReadUint()
  93. }
  94. func (codec *uintCodec) encode(ptr unsafe.Pointer, stream *Stream) {
  95. stream.WriteUint(*((*uint)(ptr)))
  96. }
  97. func (encoder *uintCodec) encodeInterface(val interface{}, stream *Stream) {
  98. WriteToStream(val, stream, encoder)
  99. }
  100. func (codec *uintCodec) isEmpty(ptr unsafe.Pointer) bool {
  101. return *((*uint)(ptr)) == 0
  102. }
  103. type uint8Codec struct {
  104. }
  105. func (codec *uint8Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
  106. *((*uint8)(ptr)) = iter.ReadUint8()
  107. }
  108. func (codec *uint8Codec) encode(ptr unsafe.Pointer, stream *Stream) {
  109. stream.WriteUint8(*((*uint8)(ptr)))
  110. }
  111. func (encoder *uint8Codec) encodeInterface(val interface{}, stream *Stream) {
  112. WriteToStream(val, stream, encoder)
  113. }
  114. func (codec *uint8Codec) isEmpty(ptr unsafe.Pointer) bool {
  115. return *((*uint8)(ptr)) == 0
  116. }
  117. type uint16Codec struct {
  118. }
  119. func (decoder *uint16Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
  120. *((*uint16)(ptr)) = iter.ReadUint16()
  121. }
  122. func (codec *uint16Codec) encode(ptr unsafe.Pointer, stream *Stream) {
  123. stream.WriteUint16(*((*uint16)(ptr)))
  124. }
  125. func (encoder *uint16Codec) encodeInterface(val interface{}, stream *Stream) {
  126. WriteToStream(val, stream, encoder)
  127. }
  128. func (codec *uint16Codec) isEmpty(ptr unsafe.Pointer) bool {
  129. return *((*uint16)(ptr)) == 0
  130. }
  131. type uint32Codec struct {
  132. }
  133. func (codec *uint32Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
  134. *((*uint32)(ptr)) = iter.ReadUint32()
  135. }
  136. func (codec *uint32Codec) encode(ptr unsafe.Pointer, stream *Stream) {
  137. stream.WriteUint32(*((*uint32)(ptr)))
  138. }
  139. func (encoder *uint32Codec) encodeInterface(val interface{}, stream *Stream) {
  140. WriteToStream(val, stream, encoder)
  141. }
  142. func (codec *uint32Codec) isEmpty(ptr unsafe.Pointer) bool {
  143. return *((*uint32)(ptr)) == 0
  144. }
  145. type uint64Codec struct {
  146. }
  147. func (codec *uint64Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
  148. *((*uint64)(ptr)) = iter.ReadUint64()
  149. }
  150. func (codec *uint64Codec) encode(ptr unsafe.Pointer, stream *Stream) {
  151. stream.WriteUint64(*((*uint64)(ptr)))
  152. }
  153. func (encoder *uint64Codec) encodeInterface(val interface{}, stream *Stream) {
  154. WriteToStream(val, stream, encoder)
  155. }
  156. func (codec *uint64Codec) isEmpty(ptr unsafe.Pointer) bool {
  157. return *((*uint64)(ptr)) == 0
  158. }
  159. type float32Codec struct {
  160. }
  161. func (codec *float32Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
  162. *((*float32)(ptr)) = iter.ReadFloat32()
  163. }
  164. func (codec *float32Codec) encode(ptr unsafe.Pointer, stream *Stream) {
  165. stream.WriteFloat32(*((*float32)(ptr)))
  166. }
  167. func (encoder *float32Codec) encodeInterface(val interface{}, stream *Stream) {
  168. WriteToStream(val, stream, encoder)
  169. }
  170. func (codec *float32Codec) isEmpty(ptr unsafe.Pointer) bool {
  171. return *((*float32)(ptr)) == 0
  172. }
  173. type float64Codec struct {
  174. }
  175. func (codec *float64Codec) decode(ptr unsafe.Pointer, iter *Iterator) {
  176. *((*float64)(ptr)) = iter.ReadFloat64()
  177. }
  178. func (codec *float64Codec) encode(ptr unsafe.Pointer, stream *Stream) {
  179. stream.WriteFloat64(*((*float64)(ptr)))
  180. }
  181. func (encoder *float64Codec) encodeInterface(val interface{}, stream *Stream) {
  182. WriteToStream(val, stream, encoder)
  183. }
  184. func (codec *float64Codec) isEmpty(ptr unsafe.Pointer) bool {
  185. return *((*float64)(ptr)) == 0
  186. }
  187. type boolCodec struct {
  188. }
  189. func (codec *boolCodec) decode(ptr unsafe.Pointer, iter *Iterator) {
  190. *((*bool)(ptr)) = iter.ReadBool()
  191. }
  192. func (codec *boolCodec) encode(ptr unsafe.Pointer, stream *Stream) {
  193. stream.WriteBool(*((*bool)(ptr)))
  194. }
  195. func (encoder *boolCodec) encodeInterface(val interface{}, stream *Stream) {
  196. WriteToStream(val, stream, encoder)
  197. }
  198. func (codec *boolCodec) isEmpty(ptr unsafe.Pointer) bool {
  199. return !(*((*bool)(ptr)))
  200. }
  201. type interfaceCodec struct {
  202. }
  203. func (codec *interfaceCodec) decode(ptr unsafe.Pointer, iter *Iterator) {
  204. *((*interface{})(ptr)) = iter.Read()
  205. }
  206. func (codec *interfaceCodec) encode(ptr unsafe.Pointer, stream *Stream) {
  207. stream.WriteVal(*((*interface{})(ptr)))
  208. }
  209. func (encoder *interfaceCodec) encodeInterface(val interface{}, stream *Stream) {
  210. stream.WriteVal(val)
  211. }
  212. func (codec *interfaceCodec) isEmpty(ptr unsafe.Pointer) bool {
  213. return ptr == nil
  214. }
  215. type anyCodec struct {
  216. }
  217. func (codec *anyCodec) decode(ptr unsafe.Pointer, iter *Iterator) {
  218. *((*Any)(ptr)) = iter.ReadAny()
  219. }
  220. func (codec *anyCodec) encode(ptr unsafe.Pointer, stream *Stream) {
  221. (*((*Any)(ptr))).WriteTo(stream)
  222. }
  223. func (encoder *anyCodec) encodeInterface(val interface{}, stream *Stream) {
  224. (val.(Any)).WriteTo(stream)
  225. }
  226. func (encoder *anyCodec) isEmpty(ptr unsafe.Pointer) bool {
  227. return (*((*Any)(ptr))).Size() == 0
  228. }
  229. type stringNumberDecoder struct {
  230. elemDecoder Decoder
  231. }
  232. func (decoder *stringNumberDecoder) decode(ptr unsafe.Pointer, iter *Iterator) {
  233. c := iter.nextToken()
  234. if c != '"' {
  235. iter.reportError("stringNumberDecoder", `expect "`)
  236. return
  237. }
  238. decoder.elemDecoder.decode(ptr, iter)
  239. if iter.Error != nil {
  240. return
  241. }
  242. c = iter.readByte()
  243. if c != '"' {
  244. iter.reportError("stringNumberDecoder", `expect "`)
  245. return
  246. }
  247. }