pmalhaire / xk6-mqtt

k6 mqtt extension
Apache License 2.0
47 stars 37 forks source link

Binary data types not supported for Publish message contents #2

Closed mjkapkan closed 2 years ago

mjkapkan commented 3 years ago

This is because the Message argument on Publish function is declared as string.

pmalhaire commented 3 years ago

This is caused by the underlying lib which is using string as argument. github.com/eclipse/paho.mqtt.golang

The clean way to fix this would be to fix it in there.

pmalhaire commented 3 years ago

can you give me a js sample file sending binary in js so I can test : I made a fix in https://github.com/pmalhaire/xk6-mqtt/tree/byte_array_support

mjkapkan commented 3 years ago

Thanks. Just try encoding any string with CBOR. For example this one https://github.com/paroga/cbor-js

Basically I encode before sending and decode after receiving.

pmalhaire commented 3 years ago

The thing needed for this is the way to convert js array to golang []byte and back.

pmalhaire commented 3 years ago

note you can do the binary to hex and hex to binary in the js code instead of injecting it in golang.

mjkapkan commented 3 years ago

Yeah. I actually do that. But the thing that was missing was to be able to send bytes in the mqtt message. As before my modification it was converting everything to string. Will try out the new version and let you know how it works. Thanks again!

pmalhaire commented 3 years ago

The issues is that the js arraybuffer does not have a corresponding golang type (or at least I did not find how to do it) so I am kindof stucked on this for now.