Commit Graph

63 Commits

Author SHA1 Message Date
andri lim 8a4ed98bbd
Add compile time switch to alter encoder enum representation (#95)
* Add compile time switch to alter encoder enum representation

* Fix test

* Add enum section in README.md

Add more tests and encoder features of enums

* Add enums section to README.md
2024-07-27 07:27:11 +07:00
Etan Kissling 6ff807654f
Update `nimbus-eth2` reference (#94)
`nim-beacon-chain` was renamed to `nimbus-eth2`, update references.
2024-07-24 13:34:36 +00:00
andri lim 1ac1d69f95
Add JsonValueRef compare operation (#89) 2024-03-20 21:32:43 +07:00
jangko 7516a92eb8
Fix JsonValueRef.Object comparison 2024-02-29 13:58:51 +07:00
jangko c9705eee64
Add test for nim compiler regression 23233 2024-01-23 09:15:31 +07:00
andri lim d9394dc728
Resilience against null fields (#78)
* Resilience against fields with null value

* writeField helper also handle optional fields correctly

* Use uint4 for test_parser's parseValue

* Add parseObjectWithoutSkip and parseObjectSkipNullFields
2024-01-17 13:39:29 +07:00
andri lim b14f5b58e9
Deconvolute optional fields writer (#77) 2024-01-17 07:48:42 +07:00
tersec 42253591b9
add lexer test cases (#76) 2024-01-15 07:02:08 +00:00
jangko 0db6307eb3
Add flavor feature: reader will skip null fields 2024-01-15 10:31:19 +07:00
jangko 9c74b885ea
Writer produce correct top-level or in-array optional elem when custom flavor omit optional fields 2024-01-11 16:51:00 +07:00
jangko 547604004d
Fix JsonValueRef nil comparison 2023-12-29 12:33:58 +07:00
jangko ce214b000d
Improve nested structure depth limit check 2023-12-29 12:31:56 +07:00
jangko 61a03e20d3
Add JsonVoid, JsonNumber, and JsonValueRef to JsonWriter 2023-12-27 11:58:02 +07:00
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