Convert bytes to object

How to pass array of bytes to canister and convert those bytes to object in Motoko?
Is there any example of this?

1 Like

I’d like to help, but I’m not sure I fully understand the question.

Is that passing an array of bytes from Javascript to Motoko or between canisters?

And what exactly do you have in mind when converting those bytes to an object? What sort of object?

1 Like

I want to transfer an array of bytes to a canister using the command “canister call mycanistr …” and then in the canister convert those bytes to a structure or object. For example, as in the Golang language “json.Unmarshal”

As long as you are happy with the Candid serialization format, Motoko already does the marshalling and unmarshalling of structured data to bytes for you.

If you don’t want to use Candid, but want to have your own serialization format or implement another one, then we don’t have any examples of that, as far as I am aware, and you will need to roll your own marshalling and unmarshalling mechanism. Something along the line of Andrew Kennedy’s pickler combinators should translate nicely to Motoko,

but perhaps you’ve got something else in mind.