Variants in Candid - Size

When a Variant is seariled to candid for shipping over the wire to another canister in a XCanister call, how many bytes is the tag for the variant?

For example, If I have type = {#myVar : Nat32;}, how big would that be? 4 Bytes for the 32 bit Nat and then how much for the myvar tag?

Use case: Xcannister calls are limited to around 2MB and if I have a big array of my type I need to know when I need to chunk it up.

As long as your variant type has no more than 128 different tags a variant value costs one byte plus the contained value. If the contained value is of type null (as it is in the enum case), that does not take any space.

Source: candid/Candid.md at master · dfinity/candid · GitHub

2 Likes