jsoniter: Fix errors during reading integers from chunked io.Reader (#477)

This commit fixes bug in Iterator.assertInteger method if the next
conditions are met:
- Iterator reads data from `io.Reader`,
- expected value is `0` (zero)
- `Iterator.tail == Iterator.head + 1`
- `Iterator.tail < len(Iterator.buf)`
- value in the buffer after `Iterator.tail` is presented from the previous read and has '.' character.

Typical error which user cal see is:
- assertInteger: can not decode float as int, error found in #X byte of ...

Regression test added for checking the correct behaviour.

Fixes #476
2 files changed
tree: 0e9a7b9fd46dce402387202ad9148fa745127a24
  1. any_tests/
  2. api_tests/
  3. benchmarks/
  4. extension_tests/
  5. extra/
  6. misc_tests/
  7. skip_tests/
  8. type_tests/
  9. value_tests/
  10. .codecov.yml
  11. .gitignore
  12. .travis.yml
  13. adapter.go
  14. any.go
  15. any_array.go
  16. any_bool.go
  17. any_float.go
  18. any_int32.go
  19. any_int64.go
  20. any_invalid.go
  21. any_nil.go
  22. any_number.go
  23. any_object.go
  24. any_str.go
  25. any_uint32.go
  26. any_uint64.go
  27. build.sh
  28. config.go
  29. example_test.go
  30. fuzzy_mode_convert_table.md
  31. go.mod
  32. go.sum
  33. Gopkg.lock
  34. Gopkg.toml
  35. iter.go
  36. iter_array.go
  37. iter_float.go
  38. iter_int.go
  39. iter_object.go
  40. iter_skip.go
  41. iter_skip_sloppy.go
  42. iter_skip_sloppy_test.go
  43. iter_skip_strict.go
  44. iter_str.go
  45. jsoniter.go
  46. LICENSE
  47. pool.go
  48. README.md
  49. reflect.go
  50. reflect_array.go
  51. reflect_dynamic.go
  52. reflect_extension.go
  53. reflect_json_number.go
  54. reflect_json_raw_message.go
  55. reflect_map.go
  56. reflect_marshaler.go
  57. reflect_native.go
  58. reflect_optional.go
  59. reflect_slice.go
  60. reflect_struct_decoder.go
  61. reflect_struct_encoder.go
  62. stream.go
  63. stream_float.go
  64. stream_int.go
  65. stream_str.go
  66. stream_test.go
  67. test.sh
README.md

Sourcegraph GoDoc Build Status codecov rcard License Gitter chat

A high-performance 100% compatible drop-in replacement of “encoding/json”

You can also use thrift like JSON using thrift-iterator

Benchmark

benchmark

Source code: https://github.com/json-iterator/go-benchmark/blob/master/src/github.com/json-iterator/go-benchmark/benchmark_medium_payload_test.go

Raw Result (easyjson requires static code generation)

ns/opallocation bytesallocation times
std decode35510 ns/op1960 B/op99 allocs/op
easyjson decode8499 ns/op160 B/op4 allocs/op
jsoniter decode5623 ns/op160 B/op3 allocs/op
std encode2213 ns/op712 B/op5 allocs/op
easyjson encode883 ns/op576 B/op3 allocs/op
jsoniter encode837 ns/op384 B/op4 allocs/op

Always benchmark with your own workload. The result depends heavily on the data input.

Usage

100% compatibility with standard lib

Replace

import "encoding/json"
json.Marshal(&data)

with

import jsoniter "github.com/json-iterator/go"

var json = jsoniter.ConfigCompatibleWithStandardLibrary
json.Marshal(&data)

Replace

import "encoding/json"
json.Unmarshal(input, &data)

with

import jsoniter "github.com/json-iterator/go"

var json = jsoniter.ConfigCompatibleWithStandardLibrary
json.Unmarshal(input, &data)

More documentation

How to get

go get github.com/json-iterator/go

Contribution Welcomed !

Contributors

Report issue or pull request, or email taowen@gmail.com, or Gitter chat