Motoko Serialization

As a closer to this subject … the from_candid method returns an optional type or () (?Type) … this was a new thing for me, as it will not compile if you take that value and try to use it … so we need a switch to check whether it worked … even though it will assert if the “from_candid” fails … here is a quick code example that may prove useful to the next Explorer walking this path:

var tempBlobReturned : ?ArchiveType = from_candid(tempBlob); 

switch tempBlobReturned {
  case (?val) {
    Debug.print("RESTORE SUCCESS - have a value" ) ;
    tempArchiveRestored:=val ;
  };
  case null {
    Debug.print("RESTORE FAILED - have no value " ) ;
  };
};// end switch

Happy to respond if anything does not make sense here … extrapolated this solution from the following post:

needless to say, but very obtuse … thanks @rossberg
please rock on …

1 Like