News for hackers. Stuff that matters.
Re:Mongrel2 v1.6 Released by FooBarWidget on Thursday May 12, 2011 @03:07PM (#2541904)
I'm wondering why TNetstring types come after the data. This means you have to buffer the entire data before you can parse it. Is this intentional?
Re:Mongrel2 v1.6 Released by amattn on Thursday May 12, 2011 @03:27PM (#2541976)
It's for backwards compatibility with regular old netstrings. It works very well in practice. Implementations are dead-simple and super fast in just about every language.
Re:Mongrel2 v1.6 Released by zedshaw on Thursday May 12, 2011 @03:31PM (#2541990)
Yep, you have to anyway. It's to prevent buffer overflows so that you can't "cheat" and try to stream it. You have to read it, allocate, then save it. It also means you can abort after just reading the size and ':' if it's too big. Rather than designing your protocol to allow insane buffer sizes to "stream", just have things send reasonable easily buffered chunks. That's more reliable and easier to manage.

The other reason was so it was backward compatible with netstrings. The : was already used by netstrings, but the ',' wasn't so overloading that was easiest.