Enabling compression on socket send/receive.

2024-08-22 Thread void09
Thank you Clonk, but like I said, I wanted to avoid the "ifs", and case is just an alternative if. Already know to implement it like this. My question was how I can implement it with storing the procs instead, like I said 3 times already :)

Enabling compression on socket send/receive.

2024-08-22 Thread Clonk
> And all socket sends are handled by client.sendProc(data: string) type Compression = enum uncompressed, gzip, deflate NNTPContext = object c: NNTP comp: Compression AsyncNNTPContext = object c: AsyncNNTP comp: C

Enabling compression on socket send/receive.

2024-08-21 Thread void09
not sure what you mean there Araq. That is what I want to accomplish here, write 3 procs, sendUncompressed, sendGzip, sendDeflate, and when compression is enabled, just do client.sendProc = sendGzip or whatever. And all socket sends are handled by client.sendProc(data: string). I am stuck at thi

Enabling compression on socket send/receive.

2024-08-21 Thread Araq
The `if` is only everywhere when you fail at using wrapper procs for send/recv consistently.

Enabling compression on socket send/receive.

2024-08-21 Thread void09
I am trying to write a NNTP client for nim, for some reason this basic ancient protocol is not implemented in any lib I could find. NNTP protocol allows for gzip or deflate compression. I know an if boolean for every send is not a big deal, but if it can be done better, by swapping assigned proc

Enabling compression on socket send/receive.

2024-08-18 Thread treeform
Here is the corrected version with improved spelling and grammar: I’m not sure what you’re trying to do. Do you have an HTTP server and want to add compression to it? Mummy () already does this and is super performant in other ways. Do you have some sort of TCP p

Enabling compression on socket send/receive.

2024-08-18 Thread void09
Thank you, I guess that is an acceptable workaround while keeping the same syntax of nntp.sendProc(), but the reason I wanted to store the procedure as a field in the object, is to avoid the if compress: sendCompressed else: sendUncompressed. Would avoid extra code and runtime overhead for all t

Enabling compression on socket send/receive.

2024-08-18 Thread Clonk
> Any idea what I am doing wrong and how to fix it ? Instead of storing the proc as a field, why not use the type for static dispatch ? proc sendProc(s: AsyncNNTP, ...) = discard proc sendProc(s: NNTP, ...) = discard proc new(T: typedesc[NNTP | AsyncNNTP], host: string,

Enabling compression on socket send/receive.

2024-08-17 Thread void09
bump. still no solution found yet

Enabling compression on socket send/receive.

2024-08-15 Thread void09
I tried to get a proc as field in my client object, so i can swap it at runtime without having if else everywhere. I have these definitions: proc sendProcU(nntp: NNTP | AsyncNNTP, data: string) {.multisync.} = await nntp.sock.send(data) NNTPClientBase*[SocketType]

Enabling compression on socket send/receive.

2024-08-12 Thread void09
already saw that example that is not relevant to the topic. if compression then send compress(string) else send string. I was looking for a more generic socket-centric solution.

Enabling compression on socket send/receive.

2024-08-12 Thread Clonk
> that is not relevant to the topic You can use the exact same logic shown in the example with `std/socksts`, who had send / recv proc on string See :

Enabling compression on socket send/receive.

2024-08-12 Thread Clonk
You have explicit example of that in `zippy` :

Enabling compression on socket send/receive.

2024-08-11 Thread void09
What would be the most simple/elegant way to have (de)compression enabled on all data sent/received over a socket ? In go it appears that it's as simple as: .. code-block:: go > conn, err := net.Dial("tcp", "localhost:8080") > > `if err != nil ...` > > gzipWriter := gzip.NewWriter(conn) messag