Change TreeItem value Lua

asked Aug 26 '25

We are researching how to add composite values to the protocol tree. It would be ideal to parse the child fields first and update the parent "composite". One thing that is missing is a set_value(). Is there a method to update the "show" value in the protocol tree.

Here is an example of an output in PDML:

    <field name="cme.futures.ilink3.sbe.v8.5.timetoexpiration" showname="Time To Expiration: " size="5" pos="247" show="" value="ffffff7f7f">
      <field name="cme.futures.ilink3.sbe.v8.5.mantissa32" showname="Mantissa 32: No Value" size="4" pos="247" show="2147483647" value="ffffff7f"/>
      <field name="cme.futures.ilink3.sbe.v8.5.exponent" showname="Exponent: No Value" size="1" pos="251" show="127" value="7f"/>
    </field>

Is there a way to update the show="" attribute of the parent? We could generate 2 separate reader functions as an alternate.

Thanks in advance

Comments

(Related to Update parent tree node)

WSDG: 12.7.1. TreeItem
Would 12.7.1.4. treeitem:set_text(text) or 12.7.1.15. treeitem.text work?

User 2763 ( Aug 26 '25 )

When I tried:

time_to_expiration:set_text("O'Doyle Rules")

I got:

<field name="cme.futures.ilink3.sbe.v8.5.timetoexpiration" showname="O'Doyle Rules" size="5" pos="247" show="" value="ffffff7f7f">
User 76285 ( Aug 26 '25 )

Sorry. Work to be done in the documentation and terms used.
treeitem:set_text(text) - "Sets the text of the label."
treeitem.text - "Set/get the TreeItem's display string (string)."
These update the "Description" string as mentioned below.

WSUG: Table 6.3. The menu items of the “Packet Details” pop-up menu
Copy → Description - "Copy the displayed text of the selected field to the system clipboard."
Copy → Fieldname - "Copy the name of the selected field to the system clipboard."
Copy → Value - "Copy the value of the selected field to the system clipboard."

You would like to update the value of the field in the tree?

User 2763 ( Aug 27 '25 )

Yes, the value of the group/struct copies as (null). I would like to change that value post dissection of the child fields. There does not seem to be a set_value()

User 76285 ( Aug 27 '25 )

The composite type should resolve to an 8 byte unsigned integer. Here is the generated code:

-- Display: Block Timestamp
siac_opra_recipient_obi_v6_2_display.block_timestamp = function(packet, parent, value, length)
  if value == nil then
    return "No Value"
  end
  -- Parse unix timestamp
  local seconds = math.floor(value:tonumber()/1000000000)
  local nanoseconds = value:tonumber()%1000000000

  return os.date("%x %H:%M:%S.", seconds)..string.format("%09d", nanoseconds)
end

-- Dissect Fields: Block Timestamp
siac_opra_recipient_obi_v6_2_dissect.block_timestamp_fields = function(buffer, offset, packet, parent)
  local index = offset

  -- Seconds: 4 Byte Unsigned Fixed Width Integer
  index, seconds = siac_opra_recipient_obi_v6_2_dissect.seconds(buffer, index, packet, parent)

  -- Nanoseconds: 4 Byte Unsigned Fixed Width Integer
  index, nanoseconds = siac_opra_recipient_obi_v6_2_dissect.nanoseconds(buffer, index, packet, parent)

  -- Composite value
  local block_timestamp = UInt64.new(seconds * 1000000000 + nanoseconds)

  return index, block_timestamp
end

-- Dissect: Block Timestamp
siac_opra_recipient_obi_v6_2_dissect.block_timestamp = function(buffer, offset, packet, parent)
  if show.block_timestamp then
    -- Optionally add element to protocol tree
    parent = parent:add(siac_opra_recipient_obi_v6_2.fields.block_timestamp, buffer(offset, 0))
    local index, value = siac_opra_recipient_obi_v6_2_dissect.block_timestamp_fields(buffer, offset, packet, parent)
    local length = index - offset
    parent:set_len(length)
    local display = siac_opra_recipient_obi_v6_2_display.block_timestamp(packet, parent, value, length)
    parent:append_text(display)

    return index, parent
  else
    -- Skip element, add fields directly
    return siac_opra_recipient_obi_v6_2_dissect.block_timestamp_fields(buffer, offset, packet, parent)
  end
end

Here is the output xml:

<field name="siac.opra.recipient.obi.v6.2.blocktimestamp" showname="Block Timestamp: 11/29/2023 14:56:44.799651328" size="8" pos="53" show="" value="6567a58c2fa9b600">

How can I set the tree item to the returned "value" without having to read the fields multiple times? (We can generate this, but it would be less elegant)

User 76285 ( Aug 30 '25 )

You could send this to the Wireshark-dev email list.
Not everyone follows the Ask questions so you might get a better solution or maybe an explanation of why there is no "set_value" function.

User 2763 ( Sep 02 '25 )