Add Lua codegen to deserialize

Open
#314 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
24/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
lua, python
Domain
backend, devtools

Research direction

Start by reading the code-generation entry points and templates in this repository, then trace how an existing language backend generates deserialization code and fields. The issue gives Wireshark Lua examples and proposed function interfaces, but no target files or tests; done means generated Lua modules can deserialize DSDL messages for the linked Wireshark plugins and expose the expected ProtoFields and dispatch functions.

Written by the indexing model from the issue text.

Description

feature

Generate Lua functions to deserialize (serialization is not needed yet) for the Wireshark plugins in https://github.com/OpenCyphal-Garage/wireshark_plugins.

These would need to be "importable" modules which would take in the buffer, pfino, tree so that they could directly modify the Wireshark tree view.

The generated code would need to:
1.) emit a list of those expected ProtoFields which would have to somehow be added into their own Proto or incorporated into the Cyphal/CAN or Cyphal/UDP Protos. (TDB)
2.) emit a 'dissector' function which takes the buffer, pinfo, tree and populates the Wireshark tree using those fields
3.) emit function which has a very long switch/if/else condition per message type would also have to be created and then called from both Cyphal/CAN and Cyphal/UDP Protocol Dissectors.

Here's similar code which breaks down the Heartbeat:

payload_tree:add_le(cyphal_heartbeat_uptime, payload(0, 4))
payload_tree:add(cyphal_heartbeat_health, payload(4, 1))
payload_tree:add(cyphal_heartbeat_mode, payload(5, 1))
payload_tree:add(cyphal_heartbeat_vssc, payload(6, 1))

And the GetInfo

local offset = 0
payload_tree:add(cyphal_getinfo_protocol_version_major, payload(offset, 1))
offset = offset + 1
payload_tree:add(cyphal_getinfo_protocol_version_minor, payload(offset, 1))
offset = offset + 1
payload_tree:add(cyphal_getinfo_hardware_version_major, payload(offset, 1))
offset = offset + 1
payload_tree:add(cyphal_getinfo_hardware_version_minor, payload(offset, 1))
offset = offset + 1
payload_tree:add(cyphal_getinfo_software_version_major, payload(offset, 1))
offset = offset + 1
payload_tree:add(cyphal_getinfo_software_version_minor, payload(offset, 1))
offset = offset + 1
payload_tree:add(cyphal_getinfo_software_vcs_revision_id, payload(offset, 8))
offset = offset + 8
payload_tree:add(cyphal_getinfo_unique_id, payload(offset, 16))
offset = offset + 16
local len = payload(offset, 1):uint()
offset = offset + 1
payload_tree:add(cyphal_getinfo_name, payload(offset, len))
offset = offset + len
len = payload(offset, 1):uint()
offset = offset + 1
if len > 0 then
    payload_tree:add(cyphal_getinfo_software_image_crc, payload(offset, len))
end
offset = offset + len
len = payload(offset, 1):uint()
offset = offset + 1
if len > 0 then
    payload_tree:add(cyphal_getinfo_certificate_of_authority, payload(offset, len))
end

In both of these cases the payload is a Tvb object which can be subscripted to form ranges, integers, floats, etc. The payload_tree is the Wireshark 'tree' object which will hold the decoded values and the various cyphal_getinfo_* are the various ProtoField declarations which inform Wireshark what fields could be expected.

The calling function:

function decode_message(payload, pinfo, payload_tree. subject_id)
  if subject_id == 7509 then -- Heartbeat
    decode_cyphal_heartbeat(payload, pinfo, payload_tree)
  ... etc
  end
end

function decode_service(payload, pinfo, payload_tree, service_id, request_not_response) 
  if service_id == 430 then 
    if request_not_response then
      decode_request_getinfo(payload, pinfo, payload_tree)
   else
     decode_response_getinfo(payload, pinfo, payload_tree)
   end
 end
end

These are just ideas and are not hard requirements.

Dominant language
Python
Stars
48
Forks
26
Avg merge
1d 18h
Merged PRs (30d)
9

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from OpenCyphal/nunavut

All issues in OpenCyphal/nunavut

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.