diff options
author | bptato <nincsnevem662@gmail.com> | 2022-11-27 00:30:53 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-11-27 00:31:56 +0100 |
commit | e7f157c792f53cb084e8694ee608f00727432a3d (patch) | |
tree | f4b640619327b5e15578cc156028102955437e36 /src/ips | |
parent | a58d2eff7f68bf98ee3b1ba1b59de6d80743f97e (diff) | |
download | chawan-e7f157c792f53cb084e8694ee608f00727432a3d.tar.gz |
Also, implement proper async
Well, not really proper, but better than nothing? Maybe not.
Diffstat (limited to 'src/ips')
-rw-r--r-- | src/ips/serialize.nim | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/ips/serialize.nim b/src/ips/serialize.nim index 9de0e374..2647db2f 100644 --- a/src/ips/serialize.nim +++ b/src/ips/serialize.nim @@ -14,7 +14,7 @@ import types/url proc slen*[T](o: T): int = when T is string: - return sizeof(o.len) + o.len + return slen(o.len) + o.len elif T is bool: return sizeof(char) elif T is URL: @@ -83,6 +83,9 @@ proc slen*[T](o: T): int = of LOAD_PIPE: result += slen(o.fd) result += slen(o.location) result += slen(o.contenttype) + elif T is tuple: + for f in o.fields: + result += slen(f) else: result += sizeof(o) @@ -182,6 +185,14 @@ proc swrite*(stream: Stream, source: BufferSource) = proc swrite*(stream: Stream, bconfig: BufferConfig) = stream.swrite(bconfig.userstyle) +proc swrite*(stream: Stream, tup: tuple) = + for f in tup.fields: + stream.swrite(f) + +proc swrite*(stream: Stream, obj: object) = + for f in obj.fields: + stream.swrite(f) + template sread*[T](stream: Stream, o: T) = stream.read(o) @@ -314,3 +325,11 @@ proc sread*(stream: Stream, source: var BufferSource) = proc sread*(stream: Stream, bconfig: var BufferConfig) = stream.sread(bconfig.userstyle) + +proc sread*(stream: Stream, obj: var object) = + for f in obj.fields: + stream.sread(f) + +proc sread*(stream: Stream, tup: var tuple) = + for f in tup.fields: + stream.sread(f) |