Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using protobuf to encode the message #104

Closed
MiaLinke opened this issue Oct 7, 2016 · 13 comments
Closed

using protobuf to encode the message #104

MiaLinke opened this issue Oct 7, 2016 · 13 comments
Labels

Comments

@MiaLinke
Copy link

MiaLinke commented Oct 7, 2016

Hello Kamil,
I am trying to encode the messages then publish it to client and again decode it in the PubSub Test Script in Test cases pane... to see correct message received pass the Test else Fail.
Please let me know if you need more information.
waiting for reply.

Thank you in Advance.. :)

@MiaLinke
Copy link
Author

when I am checking the messages
var Message = Java.type("com.google.protobuf.Message");
Message = mqttspy.getMessages("subscription");
value of Message shows like : [pl.baczkowicz.mqttspy.messages.FormattedMqttMessage@7d2c392d, pl.baczkowicz.mqttspy.messages.FormattedMqttMessage@37ba012a, pl.baczkowicz.mqttspy.messages.FormattedMqttMessage@71f4d85a, pl.baczkowicz.mqttspy.messages.FormattedMqttMessage@9369f67, pl.baczkowicz.mqttspy.messages.FormattedMqttMessage@15cf3a3d, pl.baczkowicz.mqttspy.messages.FormattedMqttMessage@721bcaff, pl.baczkowicz.mqttspy.messages.FormattedMqttMessage@25faeaee, pl.baczkowicz.mqttspy.messages.FormattedMqttMessage@180a8491, pl.baczkowicz.mqttspy.messages.FormattedMqttMessage@74f84b7f, pl.baczkowicz.mqttspy.messages.FormattedMqttMessage@58982b2d]
please clear this format ..
Waiting for reply

Thanks in Advance.. :)

@kamilfb
Copy link
Owner

kamilfb commented Oct 10, 2016

Hi @MiaLinke,

I don't think you are using Protobuf in the right way. You might need to do some more googling on that. I suspect you first need to get the binary payload from a FormattedMqttMessage, and then turn it into a Protobuf message.

Here are examples in mqtt-spy and Kura:

@MiaLinke
Copy link
Author

MiaLinke commented Oct 11, 2016

Thank you..
how can i get binary payload (in the form of 10010010010010101010 ) while from rawpayload i can get the byte data like B@34512d53
how to parse that data.
it gives me error Parser.parseFrom() is not a function but I had already imported in my script file.(var Parser = Java.type("com.google.protobuf.Parser"))
oder I also tried the KuraPayloadFormatter.format(Message.get(0).getRawPayload()) output for this is Message or its encoding is invalid..

waiting for reply.. :)

@kamilfb
Copy link
Owner

kamilfb commented Oct 17, 2016

@MiaLinke, the getRawPayload() method returns an array of bytes (byte[]). What type does your parseFrom() expect?

@MiaLinke
Copy link
Author

MiaLinke commented Oct 18, 2016

Thank you
Yes that I understand... I am trying to write code for protobuf in pubsub Script without modifying the mqtt-spy-0.5.4-jar-with-dependencies.jar file.
I tried : Clone the code and after build jar and when I run that jar shows me error for javafx.fxml.LoadException.
I am trying for return type for parser function String or JSON.

Waiting for reply :)

@kamilfb
Copy link
Owner

kamilfb commented Oct 18, 2016

sorry, i dont understand...

@MiaLinke
Copy link
Author

Sorry.. i am new to these concepts
but i decided to use my protobuf compiled files jar as dependency and then use same while i want to use my own proto files.
will you please tell me for the javafx.fxml.LoadException that comes at the time of opening the sample local broker..Thank you.. :)
und i think after that it will be better to close this issue.

@kamilfb
Copy link
Owner

kamilfb commented Oct 19, 2016

I think there is an easier way - rather than recompiling the whole project, put your JAR on the classpath as explained in https://github.com/kamilfb/mqtt-spy/wiki/GettingStarted. Look for the "Running with additional JARs on the classpath" heading.

@MiaLinke
Copy link
Author

All working perfectly and mainly with protobuf formatting.. :)
Thank you once agin ..

@kamilfb
Copy link
Owner

kamilfb commented Oct 25, 2016

hi @MiaLinke - cool - well done! any chance you could share your final solution so that other people can benefit from this as well?

@MiaLinke
Copy link
Author

Yes. I will do it definitely to help others.
will you please tell me the working of this:
var Payload = message.size() > 0 ? message.get(0).getRawPayload() : " ";

I published my protobuf encoded bytearray object in Pubsub script (newBuilder and then toByteArray).

when I doing protobuf parsefrom then i get the string value correct but Id is false. My proto file had message with int32 Id and String data value. parsefrom return getData value correct but int32 getId not ex: published Id=1234 returned parsed getId value is 19881967.
but for Id=121 or 122 or 101 kind of Id received correct decoded value received.

Please tell me where I am going wrong.

@MiaLinke
Copy link
Author

@kamilfb
I found out the reason (reference :protobufjs/protobuf.js#192): It happen because
there is some sort of string conversion in between (which is a common cause of such issues) that corrupts non-ASCII values . But I am not getting that with pubsub script ..(send bytearray and received bytearray are different)
Please reply..
Thanks in advance.

@kamilfb
Copy link
Owner

kamilfb commented Nov 1, 2016

@MiaLinke , I'm not sure why it doesn't work - looks like a protobuf thing... :(

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

No branches or pull requests

2 participants