-
Notifications
You must be signed in to change notification settings - Fork 2
WIP: Decoding function parameters from JSON string #7
base: master
Are you sure you want to change the base?
Conversation
…unction we need to use the global scope for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this is awesome. It gets us what we want/need even if the constraints of assemblyscript still make it a little awkward. I'd be happy to merge something like this, and keep us moving forward
} | ||
|
||
export function test_decode_multiple_params(encoded_allocation: u32): u32 { | ||
let jsonString: string = deserialize(encoded_allocation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got the impression from Max's PR we could/should just leave out the type defs on variable declarations that aren't in the function signature
|
||
class MultiParameterHandler extends Handler { | ||
onString(value: string): void { | ||
if(this.currentKey == "firstString") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could currentKey be passed in as a param to the function itself, rather than being an implicit property on the class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I like your idea better. I think I will combine currentKey and keyStack to a single parameter that is passed to each of the value callbacks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah! I love how you hide all this in the hdk. Brilliant.
Here is a proposed solution to parsing the parameters to a function passed as a JSON string.
This current implementation only supports primitives and string arguments but extending it to also accept objects and arrays should not be too difficult.
It uses asm-json-parser which is a module I write for event driven JSON parsing in assemblyscript. Using this to define a parser for a custom class is pretty straightforward and most of this boilerplate will be generated by the transform stage.
Inviting feedback and comments before going further
Closes #4