holo_json/read_basic

Search:
Group by:
Source   Edit  

implements reading behavior for basic types

Types

HasNormalizer = concept
    proc normalizeField(_: typedesc[Self]; format: type JsonReadFormat;
                        name: string): string
implement to normalize field names when reading in json, i.e. for style insensitivity Source   Edit  

Procs

proc finishObjectRead[T](format: JsonReadFormat; reader: JsonReaderArg; v: var T) {.
    inline.}

hook called into when an object or named tuple has finished reading all fields

does not work for ref objects, define it for their deref types, see derefType in test_objects for an easy way to do this

Source   Edit  
proc fromJson[T](s: string; x: typedesc[T]; format = JsonReadFormat()): T {.
    inline.}
Takes json and outputs the object it represents.
  • Extra json fields are ignored.
  • Missing json fields keep their default values.
  • proc startObjectRead(format: JsonReadFormat, reader: JsonReaderArg, foo: var ...) Can be used to populate default values.
Source   Edit  
proc read(format: JsonReadFormat; reader: JsonReaderArg; v: var bool) {.inline,
    ...raises: [Exception, JsonParseError, JsonValueError], tags: [RootEffect],
    forbids: [].}
Will parse boolean true or false. Source   Edit  
proc read(format: JsonReadFormat; reader: JsonReaderArg; v: var char) {.inline,
    ...raises: [Exception, JsonParseError, JsonValueError], tags: [RootEffect],
    forbids: [].}
Source   Edit  
proc read(format: JsonReadFormat; reader: JsonReaderArg; v: var cstring) {.
    inline, ...raises: [Exception, JsonParseError, JsonValueError],
    tags: [RootEffect], forbids: [].}

Parse cstring.

on native backends, deallocating it is the user's responsibility

Source   Edit  
proc read(format: JsonReadFormat; reader: JsonReaderArg; v: var float) {....raises: [
    Exception, JsonParseError, JsonValueError, Exception, JsonParseError,
    JsonValueError], tags: [RootEffect], forbids: [].}
Will parse floats. Source   Edit  
proc read(format: JsonReadFormat; reader: JsonReaderArg; v: var float32) {.
    inline, ...raises: [Exception, JsonParseError, JsonValueError],
    tags: [RootEffect], forbids: [].}
Will parse floats. Source   Edit  
proc read(format: JsonReadFormat; reader: JsonReaderArg; v: var int) {.inline,
    ...raises: [Exception, JsonParseError, JsonValueError], tags: [RootEffect],
    forbids: [].}
Will parse signed integers. Source   Edit  
proc read(format: JsonReadFormat; reader: JsonReaderArg; v: var int8) {.inline,
    ...raises: [Exception, JsonParseError, JsonValueError], tags: [RootEffect],
    forbids: [].}
Will parse signed integers. Source   Edit  
proc read(format: JsonReadFormat; reader: JsonReaderArg; v: var int16) {.inline,
    ...raises: [Exception, JsonParseError, JsonValueError], tags: [RootEffect],
    forbids: [].}
Will parse signed integers. Source   Edit  
proc read(format: JsonReadFormat; reader: JsonReaderArg; v: var int32) {.inline,
    ...raises: [Exception, JsonParseError, JsonValueError], tags: [RootEffect],
    forbids: [].}
Will parse signed integers. Source   Edit  
proc read(format: JsonReadFormat; reader: JsonReaderArg; v: var int64) {.inline,
    ...raises: [Exception, JsonParseError, JsonValueError], tags: [RootEffect],
    forbids: [].}
Will parse signed integers. Source   Edit  
proc read(format: JsonReadFormat; reader: JsonReaderArg; v: var RawJson) {.
    inline, ...raises: [Exception, JsonParseError], tags: [RootEffect], forbids: [].}
Source   Edit  
proc read(format: JsonReadFormat; reader: JsonReaderArg; v: var RawJsonValue) {.
    inline, ...raises: [Exception, JsonParseError], tags: [RootEffect], forbids: [].}
Source   Edit  
proc read(format: JsonReadFormat; reader: JsonReaderArg; v: var string) {.
    inline, ...raises: [Exception, JsonParseError, JsonValueError],
    tags: [RootEffect], forbids: [].}
Source   Edit  
proc read(format: JsonReadFormat; reader: JsonReaderArg; v: var uint) {.inline,
    ...raises: [Exception, JsonParseError, JsonValueError], tags: [RootEffect],
    forbids: [].}
Will parse unsigned integers. Source   Edit  
proc read(format: JsonReadFormat; reader: JsonReaderArg; v: var uint8) {.inline,
    ...raises: [Exception, JsonParseError, JsonValueError], tags: [RootEffect],
    forbids: [].}
Will parse unsigned integers. Source   Edit  
proc read(format: JsonReadFormat; reader: JsonReaderArg; v: var uint16) {.
    inline, ...raises: [Exception, JsonParseError, JsonValueError],
    tags: [RootEffect], forbids: [].}
Will parse unsigned integers. Source   Edit  
proc read(format: JsonReadFormat; reader: JsonReaderArg; v: var uint32) {.
    inline, ...raises: [Exception, JsonParseError, JsonValueError],
    tags: [RootEffect], forbids: [].}
Will parse unsigned integers. Source   Edit  
proc read(format: JsonReadFormat; reader: JsonReaderArg; v: var uint64) {.
    inline, ...raises: [Exception, JsonParseError, JsonValueError],
    tags: [RootEffect], forbids: [].}
Will parse unsigned integers. Source   Edit  
proc read[T: array](format: JsonReadFormat; reader: JsonReaderArg; v: var T)
Source   Edit  
proc read[T: distinct](format: JsonReadFormat; reader: JsonReaderArg; v: var T) {.
    inline.}
Source   Edit  
proc read[T: enum](format: JsonReadFormat; reader: JsonReaderArg; v: var T) {.
    inline.}
Source   Edit  
proc read[T: object](format: JsonReadFormat; reader: JsonReaderArg; v: var T)
Source   Edit  
proc read[T: tuple](format: JsonReadFormat; reader: JsonReaderArg; v: var T)
Source   Edit  
proc read[T](format: JsonReadFormat; reader: JsonReaderArg; _: typedesc[T]): T
Source   Edit  
proc read[T](format: JsonReadFormat; reader: JsonReaderArg; v: var ref T) {.
    inline.}
Source   Edit  
proc read[T](format: JsonReadFormat; reader: JsonReaderArg; v: var seq[T]) {.
    inline.}
Source   Edit  
proc readEnumString[T: enum](format: JsonReadFormat; reader: JsonReaderArg;
                             _: typedesc[T]): T
Source   Edit  
proc readJson[T](reader: JsonReaderArg; _: typedesc[T]): T {.inline.}
Source   Edit  
proc readJson[T](reader: JsonReaderArg; v: var T) {.inline.}
Source   Edit  
proc readSeq[T](format: JsonReadFormat; reader: JsonReaderArg): seq[T]
reads a JSON array as a seq of T Source   Edit  
proc readUnsignedInt[T](format: JsonReadFormat; reader: JsonReaderArg;
                        _: typedesc[T]): UintImpl[T]
Source   Edit  
proc startObjectRead[T](format: JsonReadFormat; reader: JsonReaderArg; v: var T) {.
    inline.}

hook called into when an object or named tuple are about to read their fields

does not work for ref objects, define it for their deref types, see derefType in test_objects for an easy way to do this

Source   Edit