-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Streaming API #6
Comments
For our use case we don't need this feature so I am hesitant to add and maintain it. From an API perspective it would involve duplicating From an internal code perspective it would need to avoid regressing the current performance without duplicating too much code.
Can you read from the Are your messages too large that they would consume too much memory? I kind of doubt this because serialized bitcode typically consumes less memory than the deserialized type does. |
Yes but that vector could include multiple structs. Postcard has a method take_from_bytes which returns the slice of unused bytes.
I was worried that streaming wasn't possible because bitcode relied on knowing where the serialized data ends. In hindsight I realize that doesn't make sense. |
We work exclusively with WebSockets which provide their own framing of messages. The easiest way to use |
Yes, that's a good solution thanks. But first I might take a crack at modifying the bitcode codebase to allow for reading a slice partially or reading from a stream. |
I think having a way to pack multiple types into one big packet is quite an essential feature, when encoding I guess we can just In my usecase (sending game data in UDP packets) I currently use a Cursor and decode messages (using bincode) in a loop until it consumed the entire packet, but even something as simple as getting |
This would still result in redundant information since each message would be padded to the nearest byte. |
Well that's a bummer |
It's necessary for TCP streams which don't support transmitting fractional bytes, unless the end of each message waited until the start of the next message.
To be clear, a streaming API in the sense of We're considering an API that allows you to:
This would slightly reduce the overhead of using Edit: Closing this issue may have been premature. I've reopened it until there is an issue more focused on what we can actually implement. |
❤️ |
New version of bitcode #19 has the potential to add streaming without high overhead. |
Looks like the code actually would work great with streaming APIs, if only the I'd have a loop with roughly this:
Note that this way |
You could achieve the same effect by length prefixing your messages. If your messages are long, this shouldn't add much overhead. If your messages are short and you encode them one at a time, bitcode won't provide any benefit over bincode. Note: If your use-case is packing multiple small messages into a UDP packet see bitcode_packet_packer. It's able to encode multiple messages at once, but produces discrete packets that don't exceed a limit. Included is a benchmark of various techniques including encoding messages one at a time. |
This is, obviously, a workaround that is universal and well know, and it what I'm using currently. I'm interested in specifically Thanks for sharing the bitcode_packet_packer. My use case is passing data over WebTransport streams - and currently it is for an example app. It is, basically, sending a packet and waiting for a reply, very old fashioned state machine on both ends without the need to pack multiple messages at once. I'm currently using the tokio_util::codec::length_delimited::LengthDelimitedCodec - but just that, without the rest of |
Are there any plans for a streaming API? The ability to serialize/deserialize
impl Read
andimpl Write
.I want to be able to deserialize from a TCPStream.
bincode and postcard both support this.
The text was updated successfully, but these errors were encountered: