Add some info about extended value string to section 1.7.1
[obnox/wireshark/wip.git] / doc / README.developer
index ba94c68b5ff02cd54aba78f8fa3e9b36ab952be5..21eb9f532932491aab22dcf20dacce44ff4e2404 100644 (file)
@@ -100,15 +100,16 @@ Don't declare variables in the middle of executable code; not all C
 compilers support that.  Variables should be declared outside a
 function, or at the beginning of a function or compound statement.
 
-Don't use anonymous unions; not all compilers support it.
+Don't use anonymous unions; not all compilers support them.
 Example:
-typedef struct foo {
-  guint32 foo;
-  union {
-    guint32 foo_l;
-    guint16 foo_s;
-  } u;  /* have a name here */
-} foo_t;
+
+       typedef struct foo {
+         guint32 foo;
+         union {
+           guint32 foo_l;
+           guint16 foo_s;
+         } u;  /* have a name here */
+       } foo_t;
 
 Don't use "uchar", "u_char", "ushort", "u_short", "uint", "u_int",
 "ulong", "u_long" or "boolean"; they aren't defined on all platforms.
@@ -207,7 +208,7 @@ argument.  You must do
        call_routine2(xxx, format, ap);
        va_end(ap);
 
-rather 
+rather
        va_start(ap, format);
        call_routine1(xxx, format, ap);
        call_routine2(xxx, format, ap);
@@ -1048,8 +1049,6 @@ proto_reg_handoff_PROTOABBREV(void)
  */
                PROTOABBREV_handle = new_create_dissector_handle(dissect_PROTOABBREV,
                                                                 proto_PROTOABBREV);
-               dissector_add("PARENT_SUBFIELD", ID_VALUE, PROTOABBREV_handle);
-
                initialized = TRUE;
        } else {
 
@@ -1808,6 +1807,7 @@ integral fields.
 
 strings
 -------
+-- value_string
 Some integer fields, of type FT_UINT*, need labels to represent the true
 value of a field.  You could think of those fields as having an
 enumerated data type, rather than an integral data type.
@@ -1834,23 +1834,37 @@ indicate the end of the array).  The 'strings' field would be set to
 If the field has a numeric rather than an enumerated type, the 'strings'
 field would be set to NULL.
 
+-- Extended value strings
 You can also use an extended version of the value_string for faster lookups.
 It requires a value_string as input.
-It will use the value as a pointer to the string if all values from 0 to max
-are present in the array; otherwise if the values are in assending order
-a binary search will be used. The init macro will perform a check on the value string
+If all of a contiguous range of values from min to max are present in the array
+the value will be used as as a direct index into a value_string array.
+
+If the values in the array are not contiguous (ie: there are "gaps"), but are in assending order
+a binary search will be used.
+
+Note: "gaps" in a value_string array can be filled with "empty" entries eg: {value, "Unknown"} so that
+direct access to the array is is possible.
+
+The init macro (see below) will perform a check on the value string
 the first time it is used to determine which search algorithm fits and fall back to a linear search
 if the value_string does not meet the criteria above.
 
-Use this macro to initialise the extended value_string:
+Use this macro to initialise the extended value_string at comile time:
 
 static value_string_ext valstringname_ext = VALUE_STRING_EXT_INIT(valstringname);
 
-For FT_(U)INT* fields that need a 'valstringname_ext' struct, the 'strings' field
+Extended value strings can be created at runtime by calling
+   value_string_ext_new(<ptr to value_string array>,
+                        <total number of entries in the value_string_array>, /* include {0, NULL} entry */
+                        <value_string_name>);
+
+For hf[] array FT_(U)INT* fields that need a 'valstringname_ext' struct, the 'strings' field
 would be set to '&valstringname_ext)'. Furthermore, 'display' field must be
 ORed with 'BASE_EXT_STRING' (e.g. BASE_DEC|BASE_EXT_STRING).
 
 
+-- Ranges
 If the field has a numeric type that might logically fit in ranges of values
 one can use a range_string struct.
 
@@ -1876,6 +1890,7 @@ For FT_(U)INT* fields that need a 'range_string' struct, the 'strings' field
 would be set to 'RVALS(rvalstringname)'. Furthermore, 'display' field must be
 ORed with 'BASE_RANGE_STRING' (e.g. BASE_DEC|BASE_RANGE_STRING).
 
+-- Booleans
 FT_BOOLEANs have a default map of 0 = "False", 1 (or anything else) = "True".
 Sometimes it is useful to change the labels for boolean values (e.g.,
 to "Yes"/"No", "Fast"/"Slow", etc.).  For these mappings, a struct called
@@ -2714,7 +2729,7 @@ clicks as well, launching the configured browser with this URL as parameter.
 
 1.7 Utility routines.
 
-1.7.1 match_strval and val_to_str.
+1.7.1 match_strval, match_strval_ext, val_to_str and val_to_str_ext.
 
 A dissector may need to convert a value to a string, using a
 'value_string' structure, by hand, rather than by declaring a field with
@@ -2749,6 +2764,17 @@ You can use it in a call to generate a COL_INFO line for a frame such as
 
        col_add_fstr(COL_INFO, ", %s", val_to_str(val, table, "Unknown %d"));
 
+The match_strval_ext and val_to_str_ext functions are "extended" versions
+of match_strval and val_to_str. They should be used for large value-string
+arrays which contain many entries. They implement value to string conversions
+which will do either a direct access or a binary search of the
+value string array if possible. See "Extended Value Strings" under
+section  1.6 "Constructing the protocol tree" for more information.
+
+See epan/value_string.h for detailed information on the various value_string
+functions.
+
+
 1.7.2 match_strrval and rval_to_str.
 
 A dissector may need to convert a range of values to a string, using a
@@ -3555,7 +3581,12 @@ Where: module - Returned by the prefs_register_protocol routine
         description - Comments added to the preference file above the
                       preference value
         var      - pointer to the storage location that is updated when the
-                   field is changed in the preference dialog box
+                   field is changed in the preference dialog box.  Note that
+                   with string preferences the given pointer is overwritten
+                   with a pointer to a new copy of the string during the
+                   preference registration.  The passed-in string may be
+                   freed, but you must keep another pointer to the string
+                   in order to free it.
         base     - Base that the unsigned integer is expected to be in,
                    see strtoul(3).
         enumvals - an array of enum_val_t structures.  This must be