Unsigned integer types

80 views
Skip to first unread message

Zhong Wang

unread,
Mar 29, 2019, 8:18:18 PM3/29/19
to ScalaPB
It seems ScalaPB treats unsigned integer types (e.g. uint32) as signed scala types (e.g. ScalaType.Int). This makes the value overflow if they are larger than Int.MaxValue. How can we handle this gracefully?

Thanks!
Zhong

Nadav Samet

unread,
Mar 29, 2019, 8:55:54 PM3/29/19
to Zhong Wang, ScalaPB
Hi Zhong,

Unfortunately, there are no primitive unsigned integers on JVM, so ScalaPB took the same approach as the official Java protocol buffers and uses the corresponding signed types and letting the user deal with the potential overflows. One thing you can do is to use a custom type such as BigDecimal and create your custom type mapper that would correctly convert from an Int/Long and correct overflows. This would come with some performance penalty since longs and ints are primitives and BigDecimal is an object.

-Nadav


--
You received this message because you are subscribed to the Google Groups "ScalaPB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalapb+u...@googlegroups.com.
To post to this group, send email to sca...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalapb/acea824f-7d99-46f1-be33-d5165e0ecb5d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
-Nadav
Reply all
Reply to author
Forward
0 new messages