From 289b6f90b2afbc500f65e9e4c2319666e9af2998 Mon Sep 17 00:00:00 2001 From: jangko Date: Wed, 27 Dec 2023 16:03:08 +0700 Subject: [PATCH] Add useDefaultWriterIn, useDefaultReaderIn, useDefaultWriterFor, and useDefaultReaderFor --- serialization/formats.nim | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/serialization/formats.nim b/serialization/formats.nim index 5184f27..c3ed72d 100644 --- a/serialization/formats.nim +++ b/serialization/formats.nim @@ -52,8 +52,35 @@ template useDefaultSerializationIn*(T: untyped, Flavor: type) = mixin writeRecordValue writeRecordValue(w, value) +template useDefaultWriterIn*(T: untyped, Flavor: type) = + mixin Writer + + template writeValue*(w: var Writer(Flavor), value: T) = + mixin writeRecordValue + writeRecordValue(w, value) + +template useDefaultReaderIn*(T: untyped, Flavor: type) = + mixin Reader + + template readValue*(r: var Reader(Flavor), value: var T) = + mixin readRecordValue + readRecordValue(r, value) + macro useDefaultSerializationFor*(Flavor: type, types: varargs[untyped])= result = newStmtList() for T in types: result.add newCall(bindSym "useDefaultSerializationIn", T, Flavor) + +macro useDefaultWriterFor*(Flavor: type, types: varargs[untyped])= + result = newStmtList() + + for T in types: + result.add newCall(bindSym "useDefaultWriterIn", T, Flavor) + +macro useDefaultReaderFor*(Flavor: type, types: varargs[untyped])= + result = newStmtList() + + for T in types: + result.add newCall(bindSym "useDefaultReaderIn", T, Flavor) +