top | item 37583093

(no title)

Ginden | 2 years ago

> length prefixing is annoying when streaming

This can be avoided by magic number. If length is 0, then message length isn't known.

discuss

order

jchw|2 years ago

That does leave one problem: you still need a way to segment your stream. Most length-prefixed framing schemes do not have any way to segment the stream other than the length prefix. What you wind up wanting is something like chunked encoding.

(Also, using zero as a sentinel is not necessarily a good idea, since it makes zero length messages more difficult. I'd go with -1 or ~0 instead.)

saghm|2 years ago

Using `-1` would require using a singed integer for the length, which I guess could be done if you're fine with having the maximum length be half as long, but that also raises the question of what to do with the remaining negative values; what does a length of -10 mean?

I thought -0 is only something in floating point numbers, not integers, and using floats for the length of a message sounds like a nightmare to me.

Cthulhu_|2 years ago

Or it doesn't have a length. For messaging protocols - or in general - magic should be avoided at all times.