Varint?

783 views
Skip to first unread message

ju...@benet.ai

unread,
Mar 31, 2014, 1:07:38 PM3/31/14
to capn...@googlegroups.com
Hey guys,

How does one do varints in capnp? I only see fixed-size ints in the spec.

Thanks!
Juan

Kenton Varda

unread,
Mar 31, 2014, 1:38:40 PM3/31/14
to Juan Batiz-Benet, capnproto
Hi Juan,

Cap'n Proto does not directly support varints because their variable width makes it impossible to access anything later in the message without parsing the varint.  Thus, Cap'n Proto would no longer be random-access, and would no longer be appropriate as an in-memory representation, defeating the purpose.  Also, the varint format was actually a huge mistake in protobufs -- it's surprisingly slow both to parse and to encode, because of all the branching required.

As an alternative, Cap'n Proto provides "packing".  When you write a message out, you can choose to write it in "packed" format, which does a pass over the data that compresses out zero bytes.  This of course takes non-zero time and so counts as a decoding step, but it is still faster in practice than using protobufs (varints), and produces similarly-sized messages.

-Kenton


--
You received this message because you are subscribed to the Google Groups "Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+...@googlegroups.com.
Visit this group at http://groups.google.com/group/capnproto.

Juan Batiz-Benet

unread,
Mar 31, 2014, 2:16:16 PM3/31/14
to Kenton Varda, capnproto
SGTM. Thanks Kenton! 
Reply all
Reply to author
Forward
0 new messages