Commit Graph

17 Commits

Author SHA1 Message Date
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
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
jangko aa44ee61dd
works with nim devel 2023-06-05 15:23:36 +07: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 bedbe6595a
Avoid overloading the separate classes of writeField ops 2022-06-19 12:38:44 +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
Zahary Karadjov ec374f26ca
Break reader.readObject into smaller reusable pieces 2020-08-02 13:22:24 +03:00
Zahary Karadjov c478b7bbba
Proper JSON serialization for IP addresses 2020-06-05 17:06:48 +03:00
Alexander Ivanov 193d103934 Read keys of table as string as this is only valid json, but convert them if needed 2020-05-08 17:01:15 +03:00
Zahary Karadjov f4bd22e054 Support for tuples 2019-08-14 16:18:42 +02:00
Zahary Karadjov 9a8d593598
Fix compilation issues with Nim 0.19.6 2019-08-02 15:07:06 +03:00
Alexander Ivanov e49b8bdb43 Implement support for normal and ordered tables 2019-08-02 13:33:44 +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
Zahary Karadjov a1baedeb1b Opt-in helper module for serializing the stdlib Port type 2019-06-20 15:35:17 +03:00