First time here? Check out the FAQ!
THIS IS A TEST INSTANCE. Feel free to ask and answer questions, but take care to avoid triggering too many notifications.
0

Comparing 2 UInt64s in Lua for Null Value

I am trying to print "No Value" on certain 64bit nullable sentinel values for SBE protocols. Here is a code example:

-- Size: Cross Id
size_of.cross_id = 8

-- Display: Cross Id
display.cross_id = function(value)
  -- Check if field has value
  if value == 18446744073709551615 then
    return "Cross Id: No Value ("..value..")"
  end

  return "Cross Id: "..value
end

-- Dissect: Cross Id
dissect.cross_id = function(buffer, offset, packet, parent)
  local length = size_of.cross_id
  local range = buffer(offset, length)
  local value = range:le_uint64()
  local display = display.cross_id(value, buffer, offset, packet, parent)

  parent:add(cme_futures_ilink3_sbe_v8_7.fields.cross_id, range, value, display)

  return offset + length, value
end

This script prints 18446744073709551615 for the null values. I know the 64 bit types have special handling. What is the cleanest method to handle this type?

Omi's avatar
3
Omi
asked 2021-04-04 01:38:40 +0000, updated 2021-04-05 15:33:43 +0000
edit flag offensive 0 remove flag close merge delete

Comments

What do you mean, "it prints 18446744073709551615 for the null values"? What do you expect it to print?

cmaynard's avatar cmaynard (2021-04-05 14:41:45 +0000) edit
add a comment see more comments

1 Answer

0

If your question is how to compare 2 UInt64's in Lua, then I believe this is answered in the Wireshark Developer Guide in section 11.13. Handling 64-bit Integers.

cmaynard's avatar
11.1k
cmaynard
answered 2021-04-05 14:43:28 +0000
edit flag offensive 0 remove flag delete link

Comments

From reading the guide I believe the code is correct. This branch should be taken:

  if value == 18446744073709551615 then
    return "Cross Id: No Value ("..value..")"

And No Value should be printed. However, Wireshark dissection prints 18446744073709551615. I have tried a few iterations of comparing UInt64s but none of my guesses worked. Any ideas on exactly what changes need to be made to make Wireshark recognize 64bit null values? Note this code work fine for 32 bit integers.

Omi's avatar Omi (2021-04-05 15:31:12 +0000) edit

I still don't understand what you mean by a null value. null implies there is no value at all, but that's not the case. Here you're comparing against a specific value, except that you're not performing the comparison correctly. You need to compare a UInt64 against another UInt64, but you're not doing that. You need something like this:

-- Display: Cross Id
display.cross_id = function(value)
    local maxvalue = UInt64(0xffffffff, 0xffffffff)

    -- Check if field has value
    if value == maxvalue then
        return "Cross Id: No Value ("..value..")"
    end

    return "Cross Id: "..value
end

But for some reason you're still displaying value even if it is "null", so maybe you just want this?

return "Cross Id: No Value"
cmaynard's avatar cmaynard (2021-04-05 16:02:40 +0000) edit

This works:

-- Display: Cross Id
display.cross_id = function(value)
   -- Check if field has value
   if value == UInt64(0xFFFFFFFF, 0xFFFFFFFF) then
    return "Cross Id: No Value ("..value..")"
  end

  return "Cross Id: "..value
end

Thanks.

For these binary fields that are always on the wire, CME uses a sentinel value to mark null/optional fields. I have generally included the value in parenthesis in the dissectors, however I am changing my mind as

No Value (18446744073709551615)

is not exactly the most elegant display.

Omi's avatar Omi (2021-04-05 17:27:17 +0000) edit
add a comment see more comments

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss.

Add Answer