Binary Representation for from_candid - motoko

What is the binary representation used to deserialize?

Use case: I want to push in binary from outside a canister and then use from_candid to decode it. Ideally, I’d be able to use something in the agent(agent-s) to encode a structure into a Blob and call a canister with that blob.

Reason: Perhaps I want to encrypt something that my canister can decrypt using ECDSA and then load into one of my known structures.

@claudio @chenyan


I’m not sure decrypt with ECDSA is a good use case :wink:

+1 on @skilesare question.

For my part, I’d like to encode a Buffer<ComplexType> into a Blob, send it to another canister, and have that canister decode the Blob back into a Buffer<ComplexType>. If there is a way to do this so that the data fits into an existing binary representation then that would be great.

Otherwise, I was thinking of building a class for each data type I care about. The class would maintain a Buffer of said type and would provide methods for encoding/decoding that buffer into a TLV structure similar to how ASN.1 structures are encoded.

Use case: I am building a constellation of canisters that all need to send their logged events back to a single log aggregator. It would be nice if I could send these events in a single update call.

Edit: Edited to clarify that I was referring to complex types.

@matthewhammer implemented from_candid in:

It appears to defer to the existing deserialize_from_blob:


Thank you Paul!

I also just finished reading this thread which was very insightful: