Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need Prim.principalToWord8Array. #21

Closed
enzoh opened this issue May 13, 2020 · 7 comments
Closed

Need Prim.principalToWord8Array. #21

enzoh opened this issue May 13, 2020 · 7 comments

Comments

@enzoh
Copy link
Contributor

enzoh commented May 13, 2020

No description provided.

@chenyan-dfinity
Copy link
Contributor

You can use Prim.blobOfPrincipal x

@enzoh
Copy link
Contributor Author

enzoh commented May 13, 2020

Is Blob just an alias for [Word8]?

@enzoh enzoh changed the title Need Prim.principalToWord8Array or some other comparable primative. Need Prim.principalToWord8Array. May 13, 2020
@enzoh
Copy link
Contributor Author

enzoh commented May 13, 2020

Or can I convert type Blob to [Word8]? I don't see much in the Blob API. Sorry if the original title for this issue was ambiguous.

@chenyan-dfinity
Copy link
Contributor

We are still trying to understand what is Blob: dfinity/motoko#966
For now, you can iterate the Blob via for (x in blob.bytes())

@crusso
Copy link
Contributor

crusso commented May 13, 2020

Yup, that's the way to go. Blob is actually more compact than [Word8] (in the current implementation) since we don't specialize array representations (Joachim wants to eventually).

@crusso
Copy link
Contributor

crusso commented May 13, 2020

For a hash, there is actually a Word32 hash on Principals in base library Principal.mo, defined as ... Blob.hash (Prim.blobOfPrincipal p) ...

@enzoh
Copy link
Contributor Author

enzoh commented May 17, 2020

Cool thanks! Looks like what I wanted was func (x) { Iter.toArray<Word8>(Prim.blobOfPrincipal(x).bytes())) }.

@enzoh enzoh closed this as completed May 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants