msoucy / dproto

D Protocol Buffer mixins to create structures at compile time
Boost Software License 1.0
37 stars 16 forks source link

fix and optimize toVarint #34

Closed MartinNowak closed 9 years ago

MartinNowak commented 9 years ago
msoucy commented 9 years ago

According to the encoding page, it's POSSIBLE to encode a signed long or signed int with varint directly, just not recommended...

MartinNowak commented 9 years ago

Sure, but you have to cast it to an unsigned value so that the bit shifting works. Previously negative values would lead to an infinite loop because the sign bit isn't shifted.

MartinNowak commented 9 years ago

Ping, I added a test for (-1).toVarint just to emphasize, that it works with negative numbers. Previously this test would hang.

msoucy commented 9 years ago

Alright, I'll have a chance to look at it in a day or so... Basically whenever I get power back. Yay snowstorms.