Terminal output / Candid / dcli

Hello!
I wasn’t sure how to name the topic.
I was playing with the random module; I’m using this function.

public func play () : async Blob {
       let y = await Random.blob();
       return (y);
    };

When I use dfx canister to call this function the output in the terminal is something like that
: (blob “1\93\eb\d4+U\deH\92\9b9\149d}\fc.\a7RU\cf\feM!\9f\ca\12\e0\e9F\fc\dc”).

However I’ve tried to output the raw data and then using the candid tool didc to decode the raw data and in this case I do get my 32 bytes printed correctly:

(I’ve counted they are 32!)

What is happening here? Why does dfx is not able to decode the raw data correctly?

I suspect because Candid is only one data format, and dfx doesn’t impose any restrictions around that.

In theory you could use protobuf or your own format and dfx doesn’t know about those either.

1 Like

Yes but I thought that the default format for data read by dfx was precisely Candid, so it should be able to read the blob correctly.

You might be using an old didc binary. blob "1\93\eb\d4+U..." is a shorthand for vec nat8. See candid/Candid.md at master · dfinity/candid · GitHub.

The first ascii character 1 corresponds to 49, which is the ascii code for 1. The second character \93 corresponds to 93 in hex, which is 147 in decimal, so blob "1\93" is the same as vec {49; 147}

1 Like