Add a helper simplifying writing a single value to a stream

This commit is contained in:
Zahary Karadjov 2019-06-24 05:07:13 +03:00
parent 6804ea2537
commit 060c8fd9bf
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
2 changed files with 6 additions and 1 deletions

View File

@ -121,3 +121,8 @@ template borrowSerialization*(Alias: distinct type,
mixin readValue mixin readValue
value = Alias reader.readValue(OriginalType) value = Alias reader.readValue(OriginalType)
template appendValue*(stream: OutputStreamVar, Format: type, value: auto) =
mixin WriterType, init, writeValue
var writer = init(WriterType(Format), stream)
writeValue writer, value

View File

@ -2,6 +2,6 @@ type
SerializationError* = object of CatchableError SerializationError* = object of CatchableError
UnexpectedEofError* = object of SerializationError UnexpectedEofError* = object of SerializationError
method formatMsg*(err: ref SerializationError, filename: string): string {.base.} = method formatMsg*(err: ref SerializationError, filename: string): string {.gcsafe, base.} =
"Serialisation error while processing " & filename "Serialisation error while processing " & filename