Wireshark-dev: Re: [Wireshark-dev] BASE_CUSTOM and 64-bit values

From: Jeff Morriss <jeff.morriss.ws@xxxxxxxxx>
Date: Mon, 25 Mar 2013 17:23:58 -0400
On 03/17/13 11:58, David Arnold wrote:
On 14/03/2013, at 10:36 PM, Guy Harris wrote:

You could use proto_tree_add_uint64_format_value().

I ended up writing a

     static void
     foo_tree_add_timestamp(
         proto_tree *tree,
         const int hf,
         tvbuff_t *tvb,
         gint offset);

which extracts the value using tvb_get_ntoh64(), splits it into hours, minutes, seconds and nanoseconds, writes it to a wmem_packet_scope() buffer using g_snprintf(), and calls proto_tree_add_string() to populate the FT_STRING, BASE_NONE element from my header_field_info array.  It's only a few more lines of code than the BASE_CUSTOM formatting function would have been.

My question then becomes one of consistency: should I do this for all my BASE_CUSTOM cases?   Or is there some advantage in using BASE_CUSTOM that I've missed (beyond saving a couple of lines of code)?

The advantage of BASE_CUSTOM is that the presentation is built only if/when it is needed (whereas the code you've done there obviously builds the presentation--and stores it--well before it is used).