forked from osmocom/wireshark
epan: Refactor floating point display types
Remove the redundant BASE_FLOAT field display type. The name BASE_FLOAT is meaningless and the value aliased to BASE_NONE. Require BASE_NONE instead of BASE_FLOAT (corresponding to the printf() %g format). Add new float display types using BASE_DEC, BASE_HEX and BASE_EXP corresponfing to %f, %a and %e respectively. Add support for BASE_CUSTOM with floats.pespin/osmux-wip
parent
269e4b7d10
commit
80f16015e2
|
@ -162,6 +162,12 @@ FIELDDISPLAY --For FT_UINT{8,16,24,32,40,48,56,64} and
|
|||
|
||||
BASE_NONE can be used in the same way as with FT_UINT8.
|
||||
|
||||
--For FT_FLOAT, FT_DOUBLE:
|
||||
BASE_NONE, BASE_DEC, BASE_HEX, BASE_EXP or BASE_CUSTOM.
|
||||
|
||||
BASE_NONE uses BASE_DEC or BASE_EXP, similarly to the
|
||||
%g double format for the printf() function.
|
||||
|
||||
--For FT_ABSOLUTE_TIME:
|
||||
|
||||
ABSOLUTE_TIME_LOCAL, ABSOLUTE_TIME_UTC, or
|
||||
|
|
|
@ -281,6 +281,10 @@ Too many protocols have been updated to list here.
|
|||
* proto.h: The field display types "STR_ASCII" and "STR_UNICODE" have been removed.
|
||||
Use "BASE_NONE" instead.
|
||||
|
||||
* proto.h: The field display types for floats have been extended and refactored.
|
||||
The type BASE_FLOAT has been removed. Use BASE_NONE instead. New display
|
||||
types for floats are BASE_DEC, BASE_HEX, BASE_EXP and BASE_CUSTOM.
|
||||
|
||||
== Getting Wireshark
|
||||
|
||||
Wireshark source code and installation packages are available from
|
||||
|
|
|
@ -13931,12 +13931,12 @@ proto_register_btatt(void)
|
|||
},
|
||||
{&hf_btatt_glucose_measurement_glucose_concentration_kg_per_l,
|
||||
{"Glucose Concentration [kg/l]", "btatt.glucose_measurement.glucose_concentration.kg_per_l",
|
||||
FT_IEEE_11073_SFLOAT, BASE_FLOAT, NULL, 0x0,
|
||||
FT_IEEE_11073_SFLOAT, BASE_NONE, NULL, 0x0,
|
||||
NULL, HFILL}
|
||||
},
|
||||
{&hf_btatt_glucose_measurement_glucose_concentration_mol_per_l,
|
||||
{"Glucose Concentration [mol/l]", "btatt.glucose_measurement.glucose_concentration.mol_per_l",
|
||||
FT_IEEE_11073_SFLOAT, BASE_FLOAT, NULL, 0x0,
|
||||
FT_IEEE_11073_SFLOAT, BASE_NONE, NULL, 0x0,
|
||||
NULL, HFILL}
|
||||
},
|
||||
{&hf_btatt_glucose_measurement_type_and_sample_location,
|
||||
|
@ -14186,12 +14186,12 @@ proto_register_btatt(void)
|
|||
},
|
||||
{&hf_btatt_temperature_measurement_value_celsius,
|
||||
{"Value [Celsius]", "btatt.temperature_measurement.value.celsius",
|
||||
FT_IEEE_11073_FLOAT, BASE_FLOAT, NULL, 0x00,
|
||||
FT_IEEE_11073_FLOAT, BASE_NONE, NULL, 0x00,
|
||||
NULL, HFILL}
|
||||
},
|
||||
{&hf_btatt_temperature_measurement_value_fahrenheit,
|
||||
{"Value [Fahrenheit]", "btatt.temperature_measurement.value.fahrenheit",
|
||||
FT_IEEE_11073_FLOAT, BASE_FLOAT, NULL, 0x00,
|
||||
FT_IEEE_11073_FLOAT, BASE_NONE, NULL, 0x00,
|
||||
NULL, HFILL}
|
||||
},
|
||||
{&hf_btatt_temperature_measurement_timestamp,
|
||||
|
@ -14266,7 +14266,7 @@ proto_register_btatt(void)
|
|||
},
|
||||
{&hf_btatt_glucose_measurement_context_carbohydrate_kg,
|
||||
{"Carbohydrate [kg]", "btatt.glucose_measurement_context.carbohydrate.kg",
|
||||
FT_IEEE_11073_SFLOAT, BASE_FLOAT, NULL, 0x0,
|
||||
FT_IEEE_11073_SFLOAT, BASE_NONE, NULL, 0x0,
|
||||
NULL, HFILL}
|
||||
},
|
||||
{&hf_btatt_glucose_measurement_context_meal,
|
||||
|
@ -14306,17 +14306,17 @@ proto_register_btatt(void)
|
|||
},
|
||||
{&hf_btatt_glucose_measurement_context_medication_l,
|
||||
{"Medication [l]", "btatt.glucose_measurement_context.medication.l",
|
||||
FT_IEEE_11073_SFLOAT, BASE_FLOAT, NULL, 0x0,
|
||||
FT_IEEE_11073_SFLOAT, BASE_NONE, NULL, 0x0,
|
||||
NULL, HFILL}
|
||||
},
|
||||
{&hf_btatt_glucose_measurement_context_medication_kg,
|
||||
{"Medication [kg]", "btatt.glucose_measurement_context.medication.kg",
|
||||
FT_IEEE_11073_SFLOAT, BASE_FLOAT, NULL, 0x0,
|
||||
FT_IEEE_11073_SFLOAT, BASE_NONE, NULL, 0x0,
|
||||
NULL, HFILL}
|
||||
},
|
||||
{&hf_btatt_glucose_measurement_context_hba1c,
|
||||
{"HbA1c", "btatt.glucose_measurement_context.hba1c",
|
||||
FT_IEEE_11073_SFLOAT, BASE_FLOAT, NULL, 0x0,
|
||||
FT_IEEE_11073_SFLOAT, BASE_NONE, NULL, 0x0,
|
||||
NULL, HFILL}
|
||||
},
|
||||
{&hf_btatt_blood_pressure_measurement_flags,
|
||||
|
@ -14356,32 +14356,32 @@ proto_register_btatt(void)
|
|||
},
|
||||
{&hf_btatt_blood_pressure_measurement_compound_value_systolic_kpa,
|
||||
{"Systolic [kPa]", "btatt.blood_pressure_measurement.compound_value.systolic.kpa",
|
||||
FT_IEEE_11073_SFLOAT, BASE_FLOAT, NULL, 0x0,
|
||||
FT_IEEE_11073_SFLOAT, BASE_NONE, NULL, 0x0,
|
||||
NULL, HFILL}
|
||||
},
|
||||
{&hf_btatt_blood_pressure_measurement_compound_value_diastolic_kpa,
|
||||
{"Diastolic [kPa]", "btatt.blood_pressure_measurement.compound_value.diastolic.kpa",
|
||||
FT_IEEE_11073_SFLOAT, BASE_FLOAT, NULL, 0x0,
|
||||
FT_IEEE_11073_SFLOAT, BASE_NONE, NULL, 0x0,
|
||||
NULL, HFILL}
|
||||
},
|
||||
{&hf_btatt_blood_pressure_measurement_compound_value_mean_arterial_pressure_kpa,
|
||||
{"Arterial Pressure [kPa]", "btatt.blood_pressure_measurement.compound_value.arterial_pressure.kpa",
|
||||
FT_IEEE_11073_SFLOAT, BASE_FLOAT, NULL, 0x0,
|
||||
FT_IEEE_11073_SFLOAT, BASE_NONE, NULL, 0x0,
|
||||
NULL, HFILL}
|
||||
},
|
||||
{&hf_btatt_blood_pressure_measurement_compound_value_systolic_mmhg,
|
||||
{"Systolic [mmHg]", "btatt.blood_pressure_measurement.compound_value.systolic.mmhg",
|
||||
FT_IEEE_11073_SFLOAT, BASE_FLOAT, NULL, 0x0,
|
||||
FT_IEEE_11073_SFLOAT, BASE_NONE, NULL, 0x0,
|
||||
NULL, HFILL}
|
||||
},
|
||||
{&hf_btatt_blood_pressure_measurement_compound_value_diastolic_mmhg,
|
||||
{"Diastolic [mmHg]", "btatt.blood_pressure_measurement.compound_value.diastolic.mmhg",
|
||||
FT_IEEE_11073_SFLOAT, BASE_FLOAT, NULL, 0x0,
|
||||
FT_IEEE_11073_SFLOAT, BASE_NONE, NULL, 0x0,
|
||||
NULL, HFILL}
|
||||
},
|
||||
{&hf_btatt_blood_pressure_measurement_compound_value_mean_arterial_pressure_mmhg,
|
||||
{"Arterial Pressure [mmHg]", "btatt.blood_pressure_measurement.compound_value.arterial_pressure.mmhg",
|
||||
FT_IEEE_11073_SFLOAT, BASE_FLOAT, NULL, 0x0,
|
||||
FT_IEEE_11073_SFLOAT, BASE_NONE, NULL, 0x0,
|
||||
NULL, HFILL}
|
||||
},
|
||||
{&hf_btatt_blood_pressure_measurement_timestamp,
|
||||
|
@ -14391,7 +14391,7 @@ proto_register_btatt(void)
|
|||
},
|
||||
{&hf_btatt_blood_pressure_measurement_pulse_rate,
|
||||
{"Pulse Rate", "btatt.blood_pressure_measurement.pulse_rate",
|
||||
FT_IEEE_11073_SFLOAT, BASE_FLOAT, NULL, 0x0,
|
||||
FT_IEEE_11073_SFLOAT, BASE_NONE, NULL, 0x0,
|
||||
NULL, HFILL}
|
||||
},
|
||||
{&hf_btatt_blood_pressure_measurement_user_id,
|
||||
|
@ -15798,7 +15798,7 @@ proto_register_btatt(void)
|
|||
},
|
||||
{&hf_btatt_cgm_measurement_glucose_concentration,
|
||||
{"Glucose Concentration", "btatt.cgm_measurement.glucose_concentration",
|
||||
FT_IEEE_11073_SFLOAT, BASE_FLOAT, NULL, 0x0,
|
||||
FT_IEEE_11073_SFLOAT, BASE_NONE, NULL, 0x0,
|
||||
NULL, HFILL}
|
||||
},
|
||||
{&hf_btatt_cgm_measurement_time_offset,
|
||||
|
@ -15938,12 +15938,12 @@ proto_register_btatt(void)
|
|||
},
|
||||
{&hf_btatt_cgm_measurement_trend_information,
|
||||
{"Trend Information", "btatt.cgm_measurement.trend_information",
|
||||
FT_IEEE_11073_SFLOAT, BASE_FLOAT, NULL, 0x0,
|
||||
FT_IEEE_11073_SFLOAT, BASE_NONE, NULL, 0x0,
|
||||
NULL, HFILL}
|
||||
},
|
||||
{&hf_btatt_cgm_measurement_quality,
|
||||
{"Quality", "btatt.cgm_measurement.quality",
|
||||
FT_IEEE_11073_SFLOAT, BASE_FLOAT, NULL, 0x0,
|
||||
FT_IEEE_11073_SFLOAT, BASE_NONE, NULL, 0x0,
|
||||
NULL, HFILL}
|
||||
},
|
||||
{&hf_btatt_cgm_e2e_crc,
|
||||
|
@ -16098,7 +16098,7 @@ proto_register_btatt(void)
|
|||
},
|
||||
{&hf_btatt_cgm_specific_ops_control_point_calibration_glucose_concentration,
|
||||
{"Calibration Glucose Concentration", "btatt.cgm_specific_ops_control_point.operand.calibration_glucose_concentration",
|
||||
FT_IEEE_11073_SFLOAT, BASE_FLOAT, NULL, 0x0,
|
||||
FT_IEEE_11073_SFLOAT, BASE_NONE, NULL, 0x0,
|
||||
NULL, HFILL}
|
||||
},
|
||||
{&hf_btatt_cgm_specific_ops_control_point_calibration_time,
|
||||
|
@ -16148,12 +16148,12 @@ proto_register_btatt(void)
|
|||
},
|
||||
{&hf_btatt_cgm_specific_ops_control_point_operand_alert_level,
|
||||
{"Alert Level [mg/dL]", "btatt.cgm_specific_ops_control_point.operand.alert_level",
|
||||
FT_IEEE_11073_SFLOAT, BASE_FLOAT, NULL, 0x0,
|
||||
FT_IEEE_11073_SFLOAT, BASE_NONE, NULL, 0x0,
|
||||
NULL, HFILL}
|
||||
},
|
||||
{&hf_btatt_cgm_specific_ops_control_point_operand_alert_level_rate,
|
||||
{"Alert Level Rate [mg/dL/min]", "btatt.cgm_specific_ops_control_point.operand.alert_level_rate",
|
||||
FT_IEEE_11073_SFLOAT, BASE_FLOAT, NULL, 0x0,
|
||||
FT_IEEE_11073_SFLOAT, BASE_NONE, NULL, 0x0,
|
||||
NULL, HFILL}
|
||||
},
|
||||
{&hf_btatt_cgm_specific_ops_control_point_request_opcode,
|
||||
|
@ -16573,12 +16573,12 @@ proto_register_btatt(void)
|
|||
},
|
||||
{&hf_btatt_plx_spo2,
|
||||
{"SpO2", "btatt.plxs.spot_check_measurement.spo2",
|
||||
FT_IEEE_11073_SFLOAT, BASE_FLOAT, NULL, 0x0,
|
||||
FT_IEEE_11073_SFLOAT, BASE_NONE, NULL, 0x0,
|
||||
NULL, HFILL}
|
||||
},
|
||||
{&hf_btatt_plx_pulse_rate,
|
||||
{"Pulse Rate", "btatt.plxs.spot_check_measurement.pulse_rate",
|
||||
FT_IEEE_11073_SFLOAT, BASE_FLOAT, NULL, 0x0,
|
||||
FT_IEEE_11073_SFLOAT, BASE_NONE, NULL, 0x0,
|
||||
NULL, HFILL}
|
||||
},
|
||||
{&hf_btatt_plx_spot_check_measurement_timestamp,
|
||||
|
@ -16743,7 +16743,7 @@ proto_register_btatt(void)
|
|||
},
|
||||
{&hf_btatt_plx_pulse_amplitude_index,
|
||||
{"Pulse Amplitude Index", "btatt.plxs.spot_check_measurement.pulse_amplitude_index",
|
||||
FT_IEEE_11073_SFLOAT, BASE_FLOAT, NULL, 0x0,
|
||||
FT_IEEE_11073_SFLOAT, BASE_NONE, NULL, 0x0,
|
||||
NULL, HFILL}
|
||||
},
|
||||
{&hf_btatt_plx_spo2pr_spot_check,
|
||||
|
|
|
@ -6618,7 +6618,7 @@ void proto_register_ieee802154(void)
|
|||
NULL, HFILL }},
|
||||
|
||||
{ &hf_ieee802154_tap_rss,
|
||||
{ "RSS", "wpan-tap.rss", FT_FLOAT, BASE_FLOAT|BASE_UNIT_STRING, &units_dbm, 0x0,
|
||||
{ "RSS", "wpan-tap.rss", FT_FLOAT, BASE_NONE|BASE_UNIT_STRING, &units_dbm, 0x0,
|
||||
NULL, HFILL }},
|
||||
|
||||
{ &hf_ieee802154_ch_num,
|
||||
|
@ -6690,11 +6690,11 @@ void proto_register_ieee802154(void)
|
|||
NULL, HFILL }},
|
||||
|
||||
{ &hf_ieee802154_chplan_start,
|
||||
{ "Channel0 freq", "wpan-tap.chplan.start", FT_FLOAT, BASE_FLOAT|BASE_UNIT_STRING, &units_khz, 0x0,
|
||||
{ "Channel0 freq", "wpan-tap.chplan.start", FT_FLOAT, BASE_NONE|BASE_UNIT_STRING, &units_khz, 0x0,
|
||||
"Channel 0 center frequency", HFILL }},
|
||||
|
||||
{ &hf_ieee802154_chplan_spacing,
|
||||
{ "Spacing", "wpan-tap.chplan.spacing", FT_FLOAT, BASE_FLOAT|BASE_UNIT_STRING, &units_khz, 0x0,
|
||||
{ "Spacing", "wpan-tap.chplan.spacing", FT_FLOAT, BASE_NONE|BASE_UNIT_STRING, &units_khz, 0x0,
|
||||
"Channel spacing", HFILL }},
|
||||
|
||||
{ &hf_ieee802154_chplan_channels,
|
||||
|
@ -6702,7 +6702,7 @@ void proto_register_ieee802154(void)
|
|||
"Number of channels", HFILL }},
|
||||
|
||||
{ &hf_ieee802154_ch_freq,
|
||||
{ "Frequency", "wpan-tap.ch_freq", FT_FLOAT, BASE_FLOAT|BASE_UNIT_STRING, &units_khz, 0x0,
|
||||
{ "Frequency", "wpan-tap.ch_freq", FT_FLOAT, BASE_NONE|BASE_UNIT_STRING, &units_khz, 0x0,
|
||||
"Channel center frequency", HFILL }},
|
||||
|
||||
{ &hf_ieee802154_frame_start_offset,
|
||||
|
|
|
@ -2319,10 +2319,10 @@ get_param_attributes(guint8 data_type, guint32 id_ref) {
|
|||
ret.type = FT_INT64;
|
||||
} else if (g_strcmp0(tmp->data_type, "float32") == 0) {
|
||||
ret.type = FT_FLOAT;
|
||||
ret.display_base = BASE_FLOAT;
|
||||
ret.display_base = BASE_NONE;
|
||||
} else if (g_strcmp0(tmp->data_type, "float64") == 0) {
|
||||
ret.type = FT_DOUBLE;
|
||||
ret.display_base = BASE_FLOAT;
|
||||
ret.display_base = BASE_NONE;
|
||||
} else {
|
||||
ret.type = FT_NONE;
|
||||
}
|
||||
|
|
|
@ -5128,22 +5128,22 @@ proto_register_woww(void)
|
|||
},
|
||||
{ &hf_woww_character_position_x,
|
||||
{ "Position X", "woww.character.position.x",
|
||||
FT_FLOAT, BASE_FLOAT, NULL, 0,
|
||||
FT_FLOAT, BASE_NONE, NULL, 0,
|
||||
NULL, HFILL }
|
||||
},
|
||||
{ &hf_woww_character_position_y,
|
||||
{ "Position Y", "woww.character.position.y",
|
||||
FT_FLOAT, BASE_FLOAT, NULL, 0,
|
||||
FT_FLOAT, BASE_NONE, NULL, 0,
|
||||
NULL, HFILL }
|
||||
},
|
||||
{ &hf_woww_character_position_z,
|
||||
{ "Position Z", "woww.character.position.z",
|
||||
FT_FLOAT, BASE_FLOAT, NULL, 0,
|
||||
FT_FLOAT, BASE_NONE, NULL, 0,
|
||||
NULL, HFILL }
|
||||
},
|
||||
{ &hf_woww_character_orientation,
|
||||
{ "Orientation", "woww.character.orientation",
|
||||
FT_FLOAT, BASE_FLOAT, NULL, 0,
|
||||
FT_FLOAT, BASE_NONE, NULL, 0,
|
||||
"Heading in degrees, with 0 being north", HFILL }
|
||||
},
|
||||
{ &hf_woww_character_guild_id,
|
||||
|
@ -5213,37 +5213,37 @@ proto_register_woww(void)
|
|||
},
|
||||
{ &hf_woww_movement_swim_pitch,
|
||||
{ "Swim Pitch", "woww.movement.swim_pitch",
|
||||
FT_FLOAT, BASE_FLOAT, NULL, 0,
|
||||
FT_FLOAT, BASE_NONE, NULL, 0,
|
||||
NULL, HFILL }
|
||||
},
|
||||
{ &hf_woww_movement_fallen_time,
|
||||
{ "Fallen Time", "woww.movement.fallen_time",
|
||||
FT_FLOAT, BASE_FLOAT, NULL, 0,
|
||||
FT_FLOAT, BASE_NONE, NULL, 0,
|
||||
NULL, HFILL }
|
||||
},
|
||||
{ &hf_woww_movement_jump_velocity,
|
||||
{ "Jump Velocity", "woww.movement.jump.velocity",
|
||||
FT_FLOAT, BASE_FLOAT, NULL, 0,
|
||||
FT_FLOAT, BASE_NONE, NULL, 0,
|
||||
NULL, HFILL }
|
||||
},
|
||||
{ &hf_woww_movement_jump_cos_anchor_pitch,
|
||||
{ "Jump Cos Anchor", "woww.movement.jump.cos_anchor",
|
||||
FT_FLOAT, BASE_FLOAT, NULL, 0,
|
||||
FT_FLOAT, BASE_NONE, NULL, 0,
|
||||
NULL, HFILL }
|
||||
},
|
||||
{ &hf_woww_movement_jump_sin_anchor_pitch,
|
||||
{ "Jump Sin Anchor", "woww.movement.jump.sin_anchor",
|
||||
FT_FLOAT, BASE_FLOAT, NULL, 0,
|
||||
FT_FLOAT, BASE_NONE, NULL, 0,
|
||||
NULL, HFILL }
|
||||
},
|
||||
{ &hf_woww_movement_jump_current_speed,
|
||||
{ "Jump Current Speed", "woww.movement.jump.current_speed",
|
||||
FT_FLOAT, BASE_FLOAT, NULL, 0,
|
||||
FT_FLOAT, BASE_NONE, NULL, 0,
|
||||
NULL, HFILL }
|
||||
},
|
||||
{ &hf_woww_movement_fall_start_elevation,
|
||||
{ "Fall Start Elevation", "woww.movement.fall.start_elevation",
|
||||
FT_FLOAT, BASE_FLOAT, NULL, 0,
|
||||
FT_FLOAT, BASE_NONE, NULL, 0,
|
||||
NULL, HFILL }
|
||||
},
|
||||
{ &hf_woww_timestamp,
|
||||
|
|
|
@ -44,8 +44,8 @@ static ws_enum_t all_enums[] = {
|
|||
ENUM(BASE_CUSTOM),
|
||||
ENUM(BASE_DEC),
|
||||
ENUM(BASE_DEC_HEX),
|
||||
ENUM(BASE_EXP),
|
||||
ENUM(BASE_EXT_STRING),
|
||||
ENUM(BASE_FLOAT),
|
||||
ENUM(BASE_HEX),
|
||||
ENUM(BASE_HEX_DEC),
|
||||
ENUM(BASE_NETMASK),
|
||||
|
|
140
epan/proto.c
140
epan/proto.c
|
@ -230,6 +230,9 @@ static void fill_label_char(field_info *fi, gchar *label_str);
|
|||
static void fill_label_number(field_info *fi, gchar *label_str, gboolean is_signed);
|
||||
static void fill_label_number64(field_info *fi, gchar *label_str, gboolean is_signed);
|
||||
|
||||
static size_t fill_display_label_float(field_info *fi, gchar *label_str);
|
||||
static void fill_label_float(field_info *fi, gchar *label_str);
|
||||
|
||||
static const char *hfinfo_char_value_format_display(int display, char buf[7], guint32 value);
|
||||
static const char *hfinfo_number_value_format_display(const header_field_info *hfinfo, int display, char buf[32], guint32 value);
|
||||
static const char *hfinfo_number_value_format_display64(const header_field_info *hfinfo, int display, char buf[48], guint64 value);
|
||||
|
@ -6679,29 +6682,8 @@ proto_item_fill_display_label(field_info *finfo, gchar *display_label_str, const
|
|||
break;
|
||||
|
||||
case FT_FLOAT:
|
||||
if (hfinfo->display & BASE_UNIT_STRING) {
|
||||
double d_value = fvalue_get_floating(&finfo->value);
|
||||
snprintf(display_label_str, label_str_size,
|
||||
"%." G_STRINGIFY(FLT_DIG) "g%s", d_value,
|
||||
unit_name_string_get_double(d_value, (const unit_name_string*)hfinfo->strings));
|
||||
} else {
|
||||
snprintf(display_label_str, label_str_size,
|
||||
"%." G_STRINGIFY(FLT_DIG) "g", fvalue_get_floating(&finfo->value));
|
||||
}
|
||||
label_len = (int)strlen(display_label_str);
|
||||
break;
|
||||
|
||||
case FT_DOUBLE:
|
||||
if (hfinfo->display & BASE_UNIT_STRING) {
|
||||
double d_value = fvalue_get_floating(&finfo->value);
|
||||
snprintf(display_label_str, label_str_size,
|
||||
"%." G_STRINGIFY(DBL_DIG) "g%s", d_value,
|
||||
unit_name_string_get_double(d_value, (const unit_name_string*)hfinfo->strings));
|
||||
} else {
|
||||
snprintf(display_label_str, label_str_size,
|
||||
"%." G_STRINGIFY(DBL_DIG) "g", fvalue_get_floating(&finfo->value));
|
||||
}
|
||||
label_len = (int)strlen(display_label_str);
|
||||
label_len = (int)fill_display_label_float(finfo, display_label_str);
|
||||
break;
|
||||
|
||||
case FT_STRING:
|
||||
|
@ -8306,7 +8288,6 @@ static const value_string hf_display[] = {
|
|||
{ BASE_DEC_HEX|BASE_VAL64_STRING, "BASE_DEC_HEX|BASE_VAL64_STRING" },
|
||||
{ BASE_HEX_DEC|BASE_VAL64_STRING, "BASE_HEX_DEC|BASE_VAL64_STRING" },
|
||||
{ BASE_CUSTOM|BASE_VAL64_STRING, "BASE_CUSTOM|BASE_VAL64_STRING" },
|
||||
/* Alias: BASE_NONE { BASE_FLOAT, "BASE_FLOAT" }, */
|
||||
{ ABSOLUTE_TIME_LOCAL, "ABSOLUTE_TIME_LOCAL" },
|
||||
{ ABSOLUTE_TIME_UTC, "ABSOLUTE_TIME_UTC" },
|
||||
{ ABSOLUTE_TIME_DOY_UTC, "ABSOLUTE_TIME_DOY_UTC" },
|
||||
|
@ -8364,7 +8345,7 @@ tmp_fld_check_assert(header_field_info *hfinfo)
|
|||
/* These types of fields are allowed to have value_strings,
|
||||
* true_false_strings or a protocol_t struct
|
||||
*/
|
||||
if (hfinfo->strings != NULL) {
|
||||
if (hfinfo->strings != NULL && FIELD_DISPLAY(hfinfo->display) != BASE_CUSTOM) {
|
||||
switch (hfinfo->type) {
|
||||
|
||||
/*
|
||||
|
@ -8781,19 +8762,26 @@ tmp_fld_check_assert(header_field_info *hfinfo)
|
|||
break;
|
||||
case FT_FLOAT:
|
||||
case FT_DOUBLE:
|
||||
if (FIELD_DISPLAY(hfinfo->display) != BASE_NONE) {
|
||||
tmp_str = val_to_str_wmem(NULL, hfinfo->display, hf_display, "(Bit count: %d)");
|
||||
REPORT_DISSECTOR_BUG("Field '%s' (%s) is an %s but is being displayed as %s instead of BASE_NONE",
|
||||
hfinfo->name, hfinfo->abbrev,
|
||||
ftype_name(hfinfo->type),
|
||||
tmp_str);
|
||||
wmem_free(NULL, tmp_str);
|
||||
switch (FIELD_DISPLAY(hfinfo->display)) {
|
||||
case BASE_NONE:
|
||||
case BASE_DEC:
|
||||
case BASE_HEX:
|
||||
case BASE_EXP:
|
||||
case BASE_CUSTOM:
|
||||
break;
|
||||
default:
|
||||
tmp_str = val_to_str_wmem(NULL, hfinfo->display, hf_display, "(Unknown: 0x%x)");
|
||||
REPORT_DISSECTOR_BUG("Field '%s' (%s) is a float value (%s)"
|
||||
" but is being displayed as %s",
|
||||
hfinfo->name, hfinfo->abbrev,
|
||||
ftype_name(hfinfo->type), tmp_str);
|
||||
wmem_free(NULL, tmp_str);
|
||||
}
|
||||
if (hfinfo->bitmask != 0)
|
||||
REPORT_DISSECTOR_BUG("Field '%s' (%s) is an %s but has a bitmask",
|
||||
hfinfo->name, hfinfo->abbrev,
|
||||
ftype_name(hfinfo->type));
|
||||
if ((hfinfo->strings != NULL) && (!(hfinfo->display & BASE_UNIT_STRING)))
|
||||
if (FIELD_DISPLAY(hfinfo->display) != BASE_CUSTOM && (hfinfo->strings != NULL) && !(hfinfo->display & BASE_UNIT_STRING))
|
||||
REPORT_DISSECTOR_BUG("Field '%s' (%s) is an %s but has a strings value",
|
||||
hfinfo->name, hfinfo->abbrev,
|
||||
ftype_name(hfinfo->type));
|
||||
|
@ -9277,36 +9265,9 @@ proto_item_fill_label(field_info *fi, gchar *label_str)
|
|||
break;
|
||||
|
||||
case FT_FLOAT:
|
||||
{
|
||||
double d_value = fvalue_get_floating(&fi->value);
|
||||
if (hfinfo->display & BASE_UNIT_STRING) {
|
||||
snprintf(label_str, ITEM_LABEL_LENGTH,
|
||||
"%s: %." G_STRINGIFY(FLT_DIG) "g%s",
|
||||
hfinfo->name, d_value,
|
||||
unit_name_string_get_double(d_value, (const unit_name_string*)hfinfo->strings));
|
||||
} else {
|
||||
snprintf(label_str, ITEM_LABEL_LENGTH,
|
||||
"%s: %." G_STRINGIFY(FLT_DIG) "g",
|
||||
hfinfo->name, d_value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case FT_DOUBLE:
|
||||
{
|
||||
double d_value = fvalue_get_floating(&fi->value);
|
||||
if (hfinfo->display & BASE_UNIT_STRING) {
|
||||
snprintf(label_str, ITEM_LABEL_LENGTH,
|
||||
"%s: %." G_STRINGIFY(DBL_DIG) "g%s",
|
||||
hfinfo->name, d_value,
|
||||
unit_name_string_get_double(d_value, (const unit_name_string*)hfinfo->strings));
|
||||
} else {
|
||||
snprintf(label_str, ITEM_LABEL_LENGTH,
|
||||
"%s: %." G_STRINGIFY(DBL_DIG) "g",
|
||||
hfinfo->name, d_value);
|
||||
}
|
||||
fill_label_float(fi, label_str);
|
||||
break;
|
||||
}
|
||||
|
||||
case FT_ABSOLUTE_TIME:
|
||||
tmp = abs_time_to_str(NULL, fvalue_get_time(&fi->value), hfinfo->display, TRUE);
|
||||
|
@ -9939,6 +9900,65 @@ fill_label_number64(field_info *fi, gchar *label_str, gboolean is_signed)
|
|||
}
|
||||
}
|
||||
|
||||
static size_t
|
||||
fill_display_label_float(field_info *fi, gchar *label_str)
|
||||
{
|
||||
int display;
|
||||
int digits;
|
||||
int n;
|
||||
double value;
|
||||
|
||||
display = FIELD_DISPLAY(fi->hfinfo->display);
|
||||
value = fvalue_get_floating(&fi->value);
|
||||
|
||||
if (display == BASE_CUSTOM) {
|
||||
const custom_fmt_func_double_t fmtfunc = (const custom_fmt_func_double_t)fi->hfinfo->strings;
|
||||
DISSECTOR_ASSERT(fmtfunc);
|
||||
fmtfunc(label_str, value);
|
||||
return strlen(label_str);
|
||||
}
|
||||
|
||||
switch (display) {
|
||||
case BASE_NONE:
|
||||
if (fi->hfinfo->type == FT_FLOAT)
|
||||
digits = FLT_DIG;
|
||||
else
|
||||
digits = DBL_DIG;
|
||||
|
||||
n = snprintf(label_str, ITEM_LABEL_LENGTH, "%.*g", digits, value);
|
||||
break;
|
||||
case BASE_DEC:
|
||||
n = snprintf(label_str, ITEM_LABEL_LENGTH, "%f", value);
|
||||
break;
|
||||
case BASE_HEX:
|
||||
n = snprintf(label_str, ITEM_LABEL_LENGTH, "%a", value);
|
||||
break;
|
||||
case BASE_EXP:
|
||||
n = snprintf(label_str, ITEM_LABEL_LENGTH, "%e", value);
|
||||
break;
|
||||
default:
|
||||
ws_assert_not_reached();
|
||||
}
|
||||
if (n < 0) {
|
||||
return 0; /* error */
|
||||
}
|
||||
if (n > ITEM_LABEL_LENGTH) {
|
||||
ws_warning("label length too small");
|
||||
return strlen(label_str);
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
void
|
||||
fill_label_float(field_info *fi, gchar *label_str)
|
||||
{
|
||||
gchar tmp[ITEM_LABEL_LENGTH];
|
||||
|
||||
fill_display_label_float(fi, tmp);
|
||||
label_fill(label_str, 0, fi->hfinfo, tmp);
|
||||
}
|
||||
|
||||
int
|
||||
hfinfo_bitshift(const header_field_info *hfinfo)
|
||||
{
|
||||
|
|
20
epan/proto.h
20
epan/proto.h
|
@ -81,6 +81,8 @@ typedef void (*custom_fmt_func_t)(gchar *, guint32);
|
|||
|
||||
typedef void (*custom_fmt_func_64_t)(gchar *, guint64);
|
||||
|
||||
typedef void (*custom_fmt_func_double_t)(gchar *, double);
|
||||
|
||||
/** Make a custom format function pointer look like a void pointer. Used to set header_field_info.strings.
|
||||
*
|
||||
* We cast to gsize first, which 1) is guaranteed to be wide enough to
|
||||
|
@ -662,16 +664,14 @@ void proto_report_dissector_bug(const char *format, ...)
|
|||
typedef enum {
|
||||
BASE_NONE = 0, /**< none */
|
||||
|
||||
/* Integral types */
|
||||
BASE_DEC = 1, /**< decimal */
|
||||
BASE_HEX = 2, /**< hexadecimal */
|
||||
BASE_OCT = 3, /**< octal */
|
||||
BASE_DEC_HEX = 4, /**< decimal (hexadecimal) */
|
||||
BASE_HEX_DEC = 5, /**< hexadecimal (decimal) */
|
||||
BASE_CUSTOM = 6, /**< call custom routine (in ->strings) to format */
|
||||
|
||||
/* Float types */
|
||||
BASE_FLOAT = BASE_NONE, /**< decimal-format float */
|
||||
/* Integral and float types */
|
||||
BASE_DEC = 1, /**< decimal [integer, float] */
|
||||
BASE_HEX = 2, /**< hexadecimal [integer, float] */
|
||||
BASE_OCT = 3, /**< octal [integer] */
|
||||
BASE_DEC_HEX = 4, /**< decimal (hexadecimal) [integer] */
|
||||
BASE_HEX_DEC = 5, /**< hexadecimal (decimal) [integer] */
|
||||
BASE_CUSTOM = 6, /**< call custom routine to format [integer, float] */
|
||||
BASE_EXP = 7, /**< exponential [float] */
|
||||
|
||||
/* Byte separators */
|
||||
SEP_DOT = 8, /**< hexadecimal bytes with a period (.) between each byte */
|
||||
|
|
|
@ -1316,7 +1316,7 @@ init_pn_io_rtc1(int proto)
|
|||
},
|
||||
{ &hf_pn_pa_profile_value_float,
|
||||
{ "Value", "pn_io.pa.value",
|
||||
FT_FLOAT, BASE_FLOAT, NULL, 0x0,
|
||||
FT_FLOAT, BASE_NONE, NULL, 0x0,
|
||||
NULL, HFILL }
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue