Wireshark-dev: Re: [Wireshark-dev] How to retrieve/modify a tree string
From: Guy Harris <guy@xxxxxxxxxxxx>
Date: Wed, 15 Nov 2006 09:41:25 -0800
Bill Florac wrote:
Is there an easy way to amend the display text for an item inserted in a
tree with proto_tree_add_item(). Like proto_item_append_text() but I
need to insert text into or in front of the existing text.  For example,
if I want to display an array of items that all use the same hfindex.
In the following example, the "user" comes from hf[] and the following
name is the value.
User: Bob
User: Tom
User: Fred

I want to insert an index to the view so it would look like
User[0]: Bob
User[1]: Tom
User[2]: Fred

Unfortunately, there's currently no way to do that - and there's no proto_tree_add_item_format() for that; you could use the other proto_tree_add_XXX_format() routines.

This sort of thing is - "arrays" or sequences of entries of the same type - is, I suspect, common enough that we might want to have a mechanism to add an item and have a "subscript" added to it.

That might be a variant of the proto_tree_add_XXX routines that takes a subscript value, and adds the subscript value after the field name - for example, proto_tree_add_XXX_array_element() or proto_tree_add_XXX_sequence_element().

If we did that, would we want the format of the subscript to be wired in (e.g., "Field[n]" or "Field n"), would we want it to be a property of the field (in the hf[] entry), or would we want it to be an additional argument to the proto_tree_add_XXX_... routine?

I thought that if I put sprintf context into the hf[] data like
"User[%d]",

No, that's just a field name.