holochain / hdk-assemblyscript

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

Is hc_debug require utf8? In this case you can do simpler routine #1

Closed MaxGraey closed 5 years ago

MaxGraey commented 5 years ago

You can simplify this: https://github.com/holochain/hdk-assemblyscript/blob/6ea42fd6766b5be95551d1f22d96369c1fe69217/main.ts#L18

if your host require UTF8 string of course. But according to debug api it seems and this it seems this exactly that case.

You could convert AssemblyScript's String to null terminated utf8 pointer. Such of similar stuff already done for EOS.io smart contracts and you can simply use String#toUTF8() method for that.

export function debug(message: string): void {
   hc_debug(<i32>message.toUTF8());
}
Connoropolous commented 5 years ago

It'd be nice if we could, however, the point of writing the hdk is to simplify memory management, given how holochain implements it... check out https://holochain.github.io/holochain-rust/writing_development_kit.html#the-development-kit-wasm-solution

MaxGraey commented 5 years ago

Unfortunately I didn't find any mentions about memory layout for string representation. But according to this: https://github.com/holochain/holochain-rust/blob/8a69dc60020646342cccbb245d91ac9572f6f1e2/core/src/nucleus/ribosome/api/mod.rs#L157 Bytes should be encoded in utf8 (not sure about null terminating)

Connoropolous commented 5 years ago

@MaxGraey just curious, how did you come upon this? Obviously you have a keen interest in holochain and holochain-rust. :)

MaxGraey commented 5 years ago

Ahaha, not really. I'm just one of the AssemblyScript contributors.

Connoropolous commented 5 years ago

Ah, gotcha. Coming at it from the other side. Well that's cool. I've been getting familiar with assemblyscript the last days, it's good to meet you!