Techern-archived / Varint-rs

Variable-length integer implementation in Rust
Apache License 2.0
7 stars 2 forks source link

design questions #1

Open BurntSushi opened 9 years ago

BurntSushi commented 9 years ago

I just came across your library, and I'm curious about the rationale for the current implementation. In particular, it looks like encoding a varint requires an allocation (specifically, a VecDeque). This seems very heavyweight.

The README mentions that this doesn't implement methods for writing to a stream/buffer, but it seems to me that methods for writing to a stream/buffer are actually much more fundamental than requiring an allocation.

For inspiration, I'd suggest looking at Go's standard library encoding/binary package. Half of it is for writing fixed size numbers, but the other half is for variable integer decoding. I'd expect a Rust API to look pretty similar: http://golang.org/pkg/encoding/binary/

The key is that a "buffer" can actually be stack allocated, so it allows the caller a lot more freedom.

CruzBishop commented 9 years ago

Yeah, the initial version was just quickly whipped up without much thought. I've been wanting to rewrite it for a little while now that I have a bit of experience with the Read and Write traits.

Thanks for the link, I'll have a look at it after work :) I start at 4 am, so I probably won't have anything up today, but tomorrow looks promising

BurntSushi commented 9 years ago

@CruzBishop Awesome! No rush. :-)