holochain / hdk-assemblyscript

The Holochain Developer Kit for Assemblyscript
41 stars 2 forks source link

Build a way to easily parse JSON strings into separate params #4

Open Connoropolous opened 5 years ago

willemolding commented 5 years ago

To address this issue I have started a new repo (https://github.com/willemolding/asm-json-parser)

MaxGraey commented 5 years ago

I could start implementing JSON.parse and JSON.stringify based on RapidJSON implementation after merged this PR.

btw AssemblyScript joined to Open Collective so anyone who want speedup developing AS сan this help now

Connoropolous commented 5 years ago

Both of those are great news @MaxGraey!

willemolding commented 5 years ago

I could start implementing JSON.parse and JSON.stringify based on RapidJSON implementation after merged this PR

What is your plan for implementing JSON.parse? I figure since AS can't have an any type you would need a way to parse to populate a predefined class like serde_json::from_str in rust.

Or I guess you could parse the JSON directly in to a hash map

MaxGraey commented 5 years ago

It could be parse to Map<string, AnyValue> where AnyValue is wrapper class which could store one of other values like null, numbers, string and other Map. This approach is fully dynamic and not performant. Other option is add @serializable/@deserializable class decorators (similar to #[derive(Serialize, Deserialize)] in Rust) which pre-generate serialize-deserialize methods for each class field statically. That approach more complicated and require extra changes from compiler side as well but should be much faster and handy.

Connoropolous commented 5 years ago

hey @MaxGraey looks like you got that PR merged! We are getting serious now about moving forward on this... we are going to explore a couple different options, but we'd actually like whatever we do, or collaborate with you on, to become a contribution to Assemblyscript. What do you think?

Connoropolous commented 5 years ago

also ping @maackle get in on this thread

willemolding commented 5 years ago

Since this relates to AS I opened an issue on the repo

https://github.com/AssemblyScript/assemblyscript/issues/292

MaxGraey commented 5 years ago

Yeah, I saw. So as I understand you required JSON.parse at first and JSON.stringify is not important for you right now?

willemolding commented 5 years ago

We require both actually. I guess I expect parse to be a much more challenging problem

MaxGraey commented 5 years ago

As I understand you require json parsing only for your internal stuffs like passing variable set of arguments from host to wasm method, right? Could you use protobuffer/flatbuffer for that? Which implement much simpler and don't require parsing at all

EDIT also more simpler way is implement PSON/BSON. PSON decoding even already implemented on AS: https://github.com/AssemblyScript/assemblyscript/tree/master/examples/pson

vgrichina commented 5 years ago

BTW, if anyone is interested in BSON decoding/encoding in WebAssembly – check out https://github.com/nearprotocol/assemblyscript-bson

vgrichina commented 5 years ago

I have also created encoder / decoder for JSON: https://github.com/nearprotocol/assemblyscript-json/

It doesn't support floats yet (though not hard to add) + can still be improved performance-wise and probably needs some edge case testing. Generally it implements grammar from http://json.org, so any unhandled cases would be only by mistake.

Let me know if there is anything missing.

P.S. You also will be able to generate bindings automatically, however current implementation only does BSON (see https://github.com/nearprotocol/assemblyscript/tree/master/tests/near-bindgen for example).

vgrichina commented 5 years ago

Bindings generation for JSON is also ready now: https://github.com/nearprotocol/assemblyscript/pull/12

However note that it's specific to our use case.

nickredmark commented 5 years ago

@vgrichina could your implementation be used here or does it need to be integrated into assemblyscript for the project to proceed?

vgrichina commented 5 years ago

@nmaro if you are talking about binding generation – it has to be integrated into compiler for now, but assemblyscript-json package is usable as is.

nickredmark commented 5 years ago

Thanks. Perhaps the greater question is what would be needed for the development here to continue. Are you blocked by the assemblyscript project or are you prioritizing something else or do you need help?

MaxGraey commented 5 years ago

@vgrichina actually working on another project called NEAR Protocol. @nmaro you should addressed your question to Holochain team

vgrichina commented 5 years ago

@nmaro the real answer is that you should just be using NEAR Protocol where we already handled serialization :-P

It's easy to get started – just go to http://studio.nearprotocol.com/, create project from one of the templates and press Run. You'll have an app running on our chain in like less than a minute.