Commit Graph

50 Commits

Author SHA1 Message Date
jangko 61bae43e01
Improve lexer flexibility 2023-12-26 16:03:46 +07:00
jangko d57a9d86c5
Add test vectors 2023-12-25 22:55:11 +07:00
jangko 34dc825066
Add copyright year to source file 2023-12-25 22:55:07 +07:00
zah f42567c00c
Basic support for Json flavours without default object serialization (#66)
Other changes:

* Migrate many procs accepting JsonReader to JsonLexer in order to
  reduce the number of generic instantiations and the resulting code
  bloat
2023-12-19 12:00:24 +02:00
gabrielmer 230e226da0
fix: amend incorrect int bound check (#65) 2023-11-24 17:18:23 +01:00
Etan Kissling 85b7ea093c
add `{.raises.}` annotation to `writeValue` (#64)
Tag `writeValue` overrides with `{.raises: [IOError].}`.

The override in `writer.nim` also needs `gcsafe` to support recursion
in Nim 2.0.
2023-08-19 13:47:32 +02:00
Etan Kissling d93fc19d4a
add `readValue` implementations for case objects (#63)
Case objects require custom `readValue` implementations to prevent
problems when keys are in an unexpected order. Define them for tests.
2023-08-19 12:28:06 +02:00
tersec b068e1440d
make nimble file consistent with CI setup (#58) 2023-06-10 05:15:58 +00:00
jangko aa44ee61dd
works with nim devel 2023-06-05 15:23:36 +07:00
Etan Kissling ed4440d881
use string value when encoding enums (#55)
Currently, we encode enum values always as the numeric value `ord(val)`.
unless explicitly overridden using `serializesAsTextInJson` or with a
custom `writeValue` implementation. Reduce verbosity by automatically
doing that.
2023-05-27 12:42:08 +03:00
Tanguy e5b18fb710
bugfix: a leading field with a 'none' value was producing an incorrect encoding (#50)
The field was omitted, but not the comma following it, resulting in an
encoding such as '{, otherFields: ...}'
2022-07-15 10:23:35 +00:00
Zahary Karadjov aca66fbd8e
bugfix: even the Option fields were mandatory under requireAllFields 2022-07-14 15:14:10 +03:00
Zahary Karadjov 95399caff3
Use latest nim-serialization; Add tests for useCustomSerialization 2022-06-18 13:34:04 +03:00
zah b9af0be99d
Don't write empty optional fields (#47) 2022-06-16 17:14:00 +03:00
Jordan Hrycaj 3509706517
Lazy JSON parser (#42)
* Proper error handling when parsed number exceeds uint64

details:
  Returns an "errNonPortableInt" error

* need legacy flag for unit tests

* lazy numeric token parser

why:
  Numeric data may have a custom format. In particular,numeric data may be
  Uint256 which is not a JSON standard and might lead to an overflow.

details:
  Numeric values are assigned a preliminary token type tkNumeric without
  being fully parsed. This can be used to insert a custom parser.
  Otherwise the value is parsed implicitly when querying/fetching the
  token type.

  + tok:     replaced by getter tok() resolving lazy stuff (if necessary)
  + tokKind: current type without auto-resolving

  This lazy scheme could be extended to other custom types as long as
  the first token letter determines the custom type.

* activate lazy parsing in reader

howto:
  + no code change if a custom reader refers to an existing reader
    type FancyInt = distinct int
    proc readValue(reader: var JsonReader, value: var FancyInt) =
      value = reader.readValue(int).FancyInt

  + bespoke reader for cusom parsing
    type FancyUint = distinct uint
    proc readValue(reader: var JsonReader, value: var FancyUint) =
      if reader.lexer.lazyTok == tkNumeric:
        var accu: FancyUint
        reader.lexer.customIntValueIt:
          accu = accu * 10 + it.u256
        value = accu
      elif reader.lexer.tok == tkString:
        value = reader.lexer.strVal.parseUint.FancyUint
        ...
      reader.lexer.next

  + full code explanation at json_serialisation/reader.readValue()

* Add lazy parsing for customised string objects

why:
  This allows parsing large or specialised strings without storing it
  in the lexer state descriptor.

details:
  Similar logic applies as for the cusomised number parser. For mostly
  all practical cases, a DSL template is available serving as wrapper
  around the character/byte item processor code.

* fix typo in unit test
2022-05-05 17:33:40 +01:00
Tanguy 010aa238cf Enable styleCheck:usages 2021-12-15 13:17:38 +02:00
Zahary Karadjov 297496d703 NULL cstrings are encoded to JS null 2021-11-01 18:59:12 +02:00
Zahary Karadjov 4f3775ddf4 Add JsonReader.init(..., requireAllFields: bool) 2021-08-11 20:01:47 +03:00
Zahary Karadjov 706eb5740e
Add support for serialization flavors 2021-03-18 13:01:06 +02:00
jangko 5d36ea5900
fixes test 2020-12-24 16:32:59 +07:00
jangko dd2a6d8ac3
add github action 2020-12-24 16:04:58 +07:00
Zahary Karadjov 3b0c9eafa4
Bugfix: incorrect logic in the parsing of comments fails to detect EOF properly 2020-10-09 19:32:25 +03:00
Zahary Karadjov d5eb9427b8
Serialization of JsonNode fields 2020-07-24 23:16:35 +03:00
Zahary Karadjov 25adda6f3f
Alternative implementation that doesn't require rewind points 2020-07-21 22:09:38 +03:00
Zahary Karadjov 4d8145c67b
WIP Deserialization of the JsonString literal fields 2020-07-17 23:58:02 +03:00
Zahary Karadjov 1cf51931f1
Implement forward-compatible deserialization 2020-06-30 22:11:56 +03:00
Zahary Karadjov aa51f6fed1
Test case for the serializedFieldName pragma
The pragma was added in https://github.com/status-im/nim-serialization/pull/25
2020-05-20 13:53:21 +03:00
Zahary Karadjov 2f5e71b25f
Use the latest FastStreams API 2020-05-13 11:43:52 +03:00
Jacek Sieka cb695d175f reader support for stringlikes 2020-04-29 19:37:34 +03:00
Jacek Sieka e485b74a10 treat array-of-char as string 2020-04-29 19:37:34 +03:00
Zahary Karadjov 16931f4fa3
Use the improved InputStream API 2020-04-10 16:46:12 +03:00
Zahary Karadjov f52683b2ee
Close #12 2020-04-09 20:46:48 +03:00
Zahary Karadjov c108ba90e6
Update the lexer test and add it to nimble test 2020-03-25 18:43:56 +02:00
Zahary Karadjov 88b79e2300
Remove warnings in Nim 1.0.2 2019-11-04 18:42:34 +00:00
andri lim a0607c6375 fix 32 bit problem 2019-08-14 15:44:59 +02:00
Alexander Ivanov e49b8bdb43 Implement support for normal and ordered tables 2019-08-02 13:33:44 +03:00
Zahary Karadjov 342a272281
Some of the test cases were moved to the generic suite in nim-serialization 2019-08-02 11:54:47 +03:00
Zahary Karadjov 997ae368a5
Add a test case for case objects 2019-08-01 17:12:31 +03:00
Zahary Karadjov 73d9e0d458
Handle changes in the serialization APIs 2019-07-18 21:20:17 +03:00
Zahary Karadjov 7922a83c4d
Serialization for sets 2019-07-16 13:20:05 +03:00
Zahary Karadjov 9d909d352a Add support and tests for Option and reference types 2019-06-24 17:38:37 +03:00
Mamy André-Ratsimbazafy f3d8f822bd
Handle reserved keyword `type` as field name 2019-05-28 17:42:18 +02:00
Zahary Karadjov 4ffd0b3af3 Add a test for handling missing fields 2019-04-08 15:29:21 +03:00
Zahary Karadjov c2daa5a23c Improved error handling and pretty-printing for arrays 2019-03-20 01:54:16 +02:00
Ștefan Talpalaru 002c6bbb38
assert() -> doAssert()
and an explicit "test" task for the sake of nimble.sh
2019-03-14 00:39:10 +01:00
Zahary Karadjov a9d565f8e0 Tests with distinct types 2019-03-13 23:20:58 +02:00
Zahary Karadjov edda2577a3 Handle large unsigned values and add Portable JsonMode in the Lexer 2019-01-21 19:40:14 +02:00
Ștefan Talpalaru d61f2e01fb add "--threads:on" to tests
and be explicit about relative path imports in them
2019-01-11 15:33:32 +02:00
Zahary Karadjov 6d3fae7df2 Json deserialisation; Tests 2018-12-19 12:47:53 +02:00
Zahary Karadjov e5da7654d5 Use the proper field enumeration logic; Add some high-level helpers and tests 2018-11-11 13:46:19 +02:00