-
Notifications
You must be signed in to change notification settings - Fork 3
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
How to transmit binary data? #65
Comments
BenediktBurger
added
question
Further information is requested
messages
Concerns the message format
labels
Feb 15, 2024
More elaborate discussion of the different methods. 1. Binary data as the only payloadImplementationThe payload of the LECO message is the binary data, without any (pre-defined) other information. ProFrom the LECO side quite simple: put the binary data in one or several payload frames (several for several binary objects). Cons
2. JSON message and additional payloadImplementation
example mehod (based on PyLECO): current_message: Message # contains the LECO message
additional_response: bytes # will later contain the additional, binary, response
def method_with_binary(json_parameter):
binary_data = current_message.payload[1]
result = do_something(json_parameter, binary_data)
additional_response = result
return None
# afterwards the additional_response has to be added to the response message before sending Pros
Cons
Open questions
3. Encode binary data to string and send it via JSONImplementationEncode your binary data to a string and use that as a parameter for JSON-RPC. Pros
Cons
Comments
|
3 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sometime you have to transmit binary data, like an image.
JSON (our main encoding scheme) does not support binary data.
What do we recommend?
Several options, which are all compatible with current LECO definitions:
This requires, however, that the code looks at the whole message and makes the additional frames available to the json-rpc interpreter somehow.
Here it might be good to define its own message type as well.
(I implemented this for PyMoDAQ)
The most common encoding seems to be base64.
All three approaches have their advantages and disadvantages.
I guess the choice depends on the circumstances.
Here I want to present them, maybe we can recommend one or the other, or even all three as
The text was updated successfully, but these errors were encountered: