Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

WIP: Decoding function parameters from JSON string #7

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

willemolding
Copy link
Collaborator

@willemolding willemolding commented Sep 27, 2018

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

Copy link
Collaborator

@Connoropolous Connoropolous left a 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);
Copy link
Collaborator

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") {
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

@Connoropolous Connoropolous left a 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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants