Basic support for serialization flavours without default object serialization
This commit is contained in:
parent
7cb0c31cb2
commit
68722b14fc
|
@ -1,5 +1,8 @@
|
||||||
import
|
import
|
||||||
std/typetraits
|
std/[typetraits, macros]
|
||||||
|
|
||||||
|
type
|
||||||
|
DefaultFlavor* = object
|
||||||
|
|
||||||
template serializationFormatImpl(Name: untyped,
|
template serializationFormatImpl(Name: untyped,
|
||||||
mimeTypeName: static string = "") {.dirty.} =
|
mimeTypeName: static string = "") {.dirty.} =
|
||||||
|
@ -38,3 +41,19 @@ template createFlavor*(ModifiedFormat, FlavorName: untyped) =
|
||||||
template PreferredOutputType*(T: type FlavorName): type = PreferredOutputType(ModifiedFormat)
|
template PreferredOutputType*(T: type FlavorName): type = PreferredOutputType(ModifiedFormat)
|
||||||
template mimeType*(T: type FlavorName): string = mimeType(ModifiedFormat)
|
template mimeType*(T: type FlavorName): string = mimeType(ModifiedFormat)
|
||||||
|
|
||||||
|
template useDefaultSerializationIn*(T: untyped, Flavor: type) =
|
||||||
|
mixin Reader, Writer
|
||||||
|
|
||||||
|
template readValue*(r: var Reader(Flavor), value: var T) =
|
||||||
|
mixin readRecordValue
|
||||||
|
readRecordValue(r, value)
|
||||||
|
|
||||||
|
template writeValue*(w: var Writer(Flavor), value: T) =
|
||||||
|
mixin writeRecordValue
|
||||||
|
writeRecordValue(w, value)
|
||||||
|
|
||||||
|
macro useDefaultSerializationFor*(Flavor: type, types: varargs[untyped])=
|
||||||
|
result = newStmtList()
|
||||||
|
|
||||||
|
for T in types:
|
||||||
|
result.add newCall(bindSym "useDefaultSerializationIn", T, Flavor)
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
import
|
import
|
||||||
std/typetraits,
|
std/typetraits,
|
||||||
stew/shims/macros, stew/objects,
|
stew/shims/macros, stew/objects,
|
||||||
./errors
|
./errors, ./formats
|
||||||
|
|
||||||
type
|
type
|
||||||
DefaultFlavor* = object
|
|
||||||
FieldTag*[RecordType: object; fieldName: static string] = distinct void
|
FieldTag*[RecordType: object; fieldName: static string] = distinct void
|
||||||
|
|
||||||
|
export
|
||||||
|
DefaultFlavor
|
||||||
|
|
||||||
let
|
let
|
||||||
# Identifiers affecting the public interface of the library:
|
# Identifiers affecting the public interface of the library:
|
||||||
valueSym {.compileTime.} = ident "value"
|
valueSym {.compileTime.} = ident "value"
|
||||||
|
|
Loading…
Reference in New Issue