Ask Your Question
0

Comparing 2 UInt64s in Lua for Null Value

asked 2021-04-04 01:38:40 +0000

wwtegel gravatar image

updated 2021-04-05 15:33:43 +0000

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?

edit retag flag offensive close merge delete

Comments

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

cmaynard gravatar imagecmaynard ( 2021-04-05 14:41:45 +0000 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-04-05 14:43:28 +0000

cmaynard gravatar image

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.

edit flag offensive delete link more

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.

wwtegel gravatar imagewwtegel ( 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 gravatar imagecmaynard ( 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.

wwtegel gravatar imagewwtegel ( 2021-04-05 17:27:17 +0000 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-04-04 01:38:40 +0000

Seen: 54 times

Last updated: Apr 05