Comments (8)
We could write a Candid serialization/deserialization implementation in Motoko, that converts from Blob into Candid AST and back. This route seems even better (more useful) but also seemed like more work, in the short term, than insisting that the user do the parsing into and from an AST.
This is actually the "shortcut", see https://github.com/dfinity/motoko/blob/master/test/run/idl.mo. The real solution is generics in Candid :)
from candid-spaces.
One may wonder:
Why does Candid Spaces convert Candid data into an AST for the
put
andgetImage
APIs?
If we want to transfer arbitrary data, we can just send blob over the wire, and let the canister decode to its proper type?
These are valid and natural questions.
We could write a Candid serialization/deserialization implementation in Motoko, that converts from Blob into Candid AST and back. This route seems even better (more useful) but also seemed like more work, in the short term, than insisting that the user do the parsing into and from an AST.
Then, I thought, perhaps the local Candid tools could do that extra step, since the canister may want to accept and store the AST directly (like in my case, here).
from candid-spaces.
- Thanks for that link for the shortcut! Yes, using those utilities would be helpful, but they aren't the same as what a want, which is what Andreas has been calling "type
dynamic
" in our meetings, AFAIK. In particular, for candid spaces to accept any candid value stream but also see its structure (for queries, etc.), I want to inspect eachBlob
-based value without knowing its type, a priori, like in a dynamically-typed language. I think that idl primitive stuff is not exposing enough type information, and perhaps there just isn't enough in Candid, since we only include the hashes of fields. - Generics in Candid would be helpful for some projects, but this one (candid spaces) is trying to accept any valid Candid, so having generics isn't quite as useful as it would be for a key-value store with specific key and value types.
from candid-spaces.
for candid spaces to accept any candid value stream but also see its structure (for queries, etc.), I want to inspect each Blob-based value without knowing its type
I don't know if that's possible in a strongly typed language like Motoko. As you mentioned, we need the type information as an input to deserialization. The deserialization expects two types: the wire type (comes from the message) and the expected type. With only the wire type, it's like using the candid value untyped.
from candid-spaces.
Actually, when you receive the message, the sender should know the candid type. You can ask the sender to get the type by calling the candid_tmp_hack
. I think your use case is similar to Paul's qr scanner: https://github.com/ninegua/ic-qr-scanner
from candid-spaces.
I think for now, the easiest thing is to finish the tool that I am creating to send the AST over the wire, with full field names.
See #10 for a draft PR.
I realize that the wire format is inefficient, but that's not the main issue right now. Later, Candid Spaces can offer a more efficient put
operation that accepts the (ordinary candid) Blob
format whose decoding we are debating now. Somehow, we need to send the type with the Blob
, or get it from somewhere. I don't think it's generally the case that every candid value has a service or a type to go along with it, but I see that in many cases, they might. In the short term, #10 plans to reuse the functionality of parsing and type-checking from the candid crate, and then add a minimal layer to send the parsed AST over the wire. Almost there now.
from candid-spaces.
I finished and merged #10
It creates a simple tool caniput
using the existing candid crate. Its chief purpose is to put data into candid spaces, and provide the text/binary parsing that I don't want to implement in Motoko, at least not yet. For now, the tool permits me to reuse that functionality of the candid
crate, and do it "client side" rather than "server side" (for now).
Now, with a bit more polish, caniput
can transmit files and binary data too. (Not yet in #10)
from candid-spaces.
Related: dfinity/candid#245
I still don't quite see the exact requirement here. Does one of the ideas listed above fits your need? Feel free to add more ideas there.
from candid-spaces.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from candid-spaces.