Some needed support for custom field serialization in Json
This commit is contained in:
parent
56ad4b18de
commit
b42502b512
|
@ -2,7 +2,7 @@ import
|
|||
stew/shims/macros, stew/objects
|
||||
|
||||
type
|
||||
FieldTag[RecordType; fieldName: static string; FieldType] = distinct void
|
||||
FieldTag*[RecordType; fieldName: static string; FieldType] = distinct void
|
||||
|
||||
let
|
||||
# Identifiers affecting the public interface of the library:
|
||||
|
@ -138,6 +138,13 @@ template readFieldIMPL[Reader](field: type FieldTag,
|
|||
mixin readValue
|
||||
reader.readValue(field.FieldType)
|
||||
|
||||
template writeFieldIMPL*[Writer](writer: var Writer,
|
||||
fieldTag: type FieldTag,
|
||||
fieldVal: auto,
|
||||
holderObj: auto) =
|
||||
mixin writeValue
|
||||
writer.writeValue(fieldVal)
|
||||
|
||||
proc makeFieldReadersTable(RecordType, Reader: distinct type):
|
||||
seq[FieldReader[RecordType, Reader]] =
|
||||
mixin enumAllSerializedFields, readFieldIMPL
|
||||
|
@ -281,8 +288,10 @@ proc genCustomSerializationForField(Format, field,
|
|||
if writeBody != nil:
|
||||
result.add quote do:
|
||||
type Writer = WriterType(`Format`)
|
||||
proc writeFieldIMPL*(F: type FieldTag[`RecordType`, `fieldName`, auto],
|
||||
`writerVar`: var Writer) =
|
||||
proc writeFieldIMPL*(`writerVar`: var Writer,
|
||||
F: type FieldTag[`RecordType`, `fieldName`, auto],
|
||||
`valueVar`: auto,
|
||||
`holderVar`: `RecordType`) =
|
||||
`writeBody`
|
||||
|
||||
proc genCustomSerializationForType(Format, typ: NimNode,
|
||||
|
|
Loading…
Reference in New Issue