11#ifndef __VALUE_STRING_H__
12#define __VALUE_STRING_H__
16#include "ws_symbol_export.h"
48 #define foo_VALUE_STRING_LIST(XXX) \
49 XXX( FOO_A, 1, "aaa" ) \
50 XXX( FOO_B, 3, "bbb" )
53 VALUE_STRING_ENUM(foo);
57 VALUE_STRING_ARRAY(foo);
60 VALUE_STRING_ARRAY_GLOBAL_DEF(foo);
61 VALUE_STRING_ARRAY_GLOBAL_DCL(foo);
64 #define bar_VALUE_STRING_LIST(XXX) \
68 VALUE_STRING_ENUM2(bar);
69 VALUE_STRING_ARRAY2(bar);
74#define VALUE_STRING_ENUM( array_name) _VS_ENUM_XXX( array_name, _VS_ENUM_ENTRY)
75#define VALUE_STRING_ARRAY( array_name) _VS_ARRAY_SC_XXX(array_name, _VS_ARRAY_ENTRY, static)
76#define VALUE_STRING_ARRAY_GLOBAL_DEF( array_name) _VS_ARRAY_XXX(array_name, _VS_ARRAY_ENTRY)
77#define VALUE_STRING_ARRAY_GLOBAL_DCL( array_name) _VS_ARRAY_SC_TYPE_NAME(array_name, extern)
79#define VALUE_STRING_ENUM2( array_name) _VS_ENUM_XXX( array_name, _VS_ENUM_ENTRY2)
80#define VALUE_STRING_ARRAY2( array_name) _VS_ARRAY_SC_XXX(array_name, _VS_ARRAY_ENTRY2, static)
81#define VALUE_STRING_ARRAY2_GLOBAL_DEF( array_name) _VS_ARRAY_XXX(array_name, _VS_ARRAY_ENTRY2)
82#define VALUE_STRING_ARRAY2_GLOBAL_DCL( array_name) _VS_ARRAY_SC_TYPE_NAME(array_name, extern)
85#define _VS_ENUM_XXX(array_name, macro) \
87 array_name##_VALUE_STRING_LIST(macro) \
88 _##array_name##_ENUM_DUMMY = 0 \
91#define _VS_ARRAY_SC_XXX(array_name, macro, sc) \
92 _VS_ARRAY_SC_TYPE_NAME(array_name, sc) = { \
93 array_name##_VALUE_STRING_LIST(macro) \
97#define _VS_ARRAY_XXX(array_name, macro) \
98 _VS_ARRAY_TYPE_NAME(array_name) = { \
99 array_name##_VALUE_STRING_LIST(macro) \
103#define _VS_ARRAY_SC_TYPE_NAME(array_name, sc) sc const value_string array_name[]
104#define _VS_ARRAY_TYPE_NAME(array_name) const value_string array_name[]
106#define _VS_ENUM_ENTRY( name, value, string) name = value,
107#define _VS_ARRAY_ENTRY(name, value, string) { value, string },
109#define _VS_ENUM_ENTRY2( name, value) name = value,
110#define _VS_ARRAY_ENTRY2(name, value) { value, #name },
335#define VALUE_STRING_EXT_VS_P(x) (x)->_vs_p
336#define VALUE_STRING_EXT_VS_NUM_ENTRIES(x) (x)->_vs_num_entries
337#define VALUE_STRING_EXT_VS_NAME(x) (x)->_vs_name
354#define VALUE_STRING_EXT_INIT(x) { _try_val_to_str_ext_init, 0, G_N_ELEMENTS(x)-1, x, #x, NULL }
483#define VAL64_STRING_EXT_VS_P(x) (x)->_vs_p
484#define VAL64_STRING_EXT_VS_NUM_ENTRIES(x) (x)->_vs_num_entries
485#define VAL64_STRING_EXT_VS_NAME(x) (x)->_vs_name
521#define VAL64_STRING_EXT_INIT(x) { _try_val64_to_str_ext_init, 0, G_N_ELEMENTS(x)-1, x, #x, NULL }
538val64_to_str_ext_const(
const uint64_t val,
val64_string_ext *vs,
const char *unknown_str);
546try_val64_to_str_idx_ext(
const uint64_t val,
val64_string_ext *vse,
int *idx);
566try_str_to_str_idx(
const char *val,
const string_string *vs,
int *idx);
583rval_to_str_const(
const uint32_t val,
const range_string *rs,
const char *unknown_str);
587try_rval_to_str(
const uint32_t val,
const range_string *rs);
591try_rval_to_str_idx(
const uint32_t val,
const range_string *rs,
int *idx);
595try_rval64_to_str(
const uint64_t val,
const range_string *rs);
599try_rval64_to_str_idx(
const uint64_t val,
const range_string *rs,
int *idx);
615 const uint8_t *value;
616 const size_t value_length;
627try_bytesval_to_str(
const uint8_t *val,
const size_t val_len,
const bytes_string *bs);
636try_bytesprefix_to_str(
const uint8_t *haystack,
const size_t haystack_len,
const bytes_string *bs);
639void register_external_value_string(
const char* name,
const value_string* vs);
642value_string* get_external_value_string(
const char* name);
645void register_external_value_string_ext(
const char* name,
const value_string_ext* vse);
653void value_string_externals_init(
void);
656void value_string_externals_cleanup(
void);
Definition value_string.h:614
Definition value_string.h:570
Definition value_string.h:550
Definition value_string.h:603
Extended metadata for a 64-bit value-string mapping array.
Definition value_string.h:474
const char * _vs_name
Definition value_string.h:479
uint64_t _vs_first_value
Definition value_string.h:476
unsigned _vs_num_entries
Definition value_string.h:477
_val64_string_match2_t _vs_match2
Definition value_string.h:475
wmem_allocator_t * _scope
Definition value_string.h:480
const val64_string * _vs_p
Definition value_string.h:478
Mapping between a 64-bit integer value and its string representation.
Definition value_string.h:196
uint64_t value
Definition value_string.h:197
const char * strptr
Definition value_string.h:198
Extended metadata for a value_string array.
Definition value_string.h:325
const value_string * _vs_p
Definition value_string.h:329
const char * _vs_name
Definition value_string.h:330
unsigned _vs_num_entries
Definition value_string.h:328
uint32_t _vs_first_value
Definition value_string.h:327
_value_string_match2_t _vs_match2
Definition value_string.h:326
wmem_allocator_t * _scope
Definition value_string.h:331
Mapping between a 32-bit integer value and its string representation.
Definition value_string.h:33
const char * strptr
Definition value_string.h:35
uint32_t value
Definition value_string.h:34
Definition wmem_allocator.h:27
WS_DLL_PUBLIC value_string_ext * value_string_ext_new(wmem_allocator_t *scope, const value_string *vs, unsigned vs_tot_num_entries, const char *vs_name)
Create a new extended value-string mapping structure.
Definition value_string.c:258
WS_DLL_PUBLIC const char * try_val_to_str_idx(const uint32_t val, const value_string *vs, int *idx)
Attempt to convert a numeric value to a string and retrieve its index.
Definition value_string.c:90
WS_DLL_PUBLIC const char * try_val_to_str_ext(const uint32_t val, value_string_ext *vse)
Attempt to convert a numeric value to a string using an extended value-string mapping.
Definition value_string.c:289
WS_DLL_PUBLIC char * val_to_str_ext(wmem_allocator_t *scope, const uint32_t val, value_string_ext *vse, const char *fmt) G_GNUC_PRINTF(4
Convert a numeric value to a string using an extended value-string mapping.
struct _val64_string val64_string
Mapping between a 64-bit integer value and its string representation.
WS_DLL_PUBLIC int value_str_value_compare(const void *a, const void *b)
Compare two value_string entries by their numeric value.
Definition value_string.c:32
WS_DLL_PUBLIC char WS_DLL_PUBLIC const char * val_to_str_const(const uint32_t val, const value_string *vs, const char *unknown_str)
Convert a numeric value to a constant string using a value-string mapping.
Definition value_string.c:70
WS_DLL_PUBLIC char WS_DLL_PUBLIC const char * val_to_str_ext_const(const uint32_t val, value_string_ext *vs, const char *unknown_str)
Convert a numeric value to a constant string using an extended value-string mapping.
Definition value_string.c:335
WS_DLL_PUBLIC const char * try_val_to_str(const uint32_t val, const value_string *vs)
Attempt to convert a numeric value to a string using a value-string mapping.
Definition value_string.c:112
WS_DLL_PUBLIC void value_string_ext_free(value_string_ext *vse)
Free an extended value-string mapping structure.
Definition value_string.c:282
WS_DLL_PUBLIC char * val_to_str(wmem_allocator_t *scope, const uint32_t val, const value_string *vs, const char *fmt) G_GNUC_PRINTF(4
Convert a numeric value to a string using a value-string mapping.
WS_DLL_PUBLIC const char * try_val_to_str_idx_ext(const uint32_t val, value_string_ext *vse, int *idx)
Attempt to convert a numeric value to a string and retrieve its index from an extended mapping.
Definition value_string.c:304
WS_DLL_PUBLIC const char * try_val64_to_str(const uint64_t val, const val64_string *vs)
Attempt to convert a 64-bit value to a string using a value-string mapping.
Definition value_string.c:173
WS_DLL_PUBLIC const char * val64_to_str_wmem(wmem_allocator_t *scope, const uint64_t val, const val64_string *vs, const char *fmt) G_GNUC_PRINTF(4
Convert a 64-bit value to a string using a value-string mapping.
WS_DLL_PUBLIC int str_to_val_idx(const char *val, const value_string *vs)
Retrieve the index of a string in a value-string mapping array.
Definition value_string.c:200
struct _value_string value_string
Mapping between a 32-bit integer value and its string representation.
WS_DLL_PUBLIC const value_string * _try_val_to_str_ext_init(const uint32_t val, value_string_ext *vse)
Attempt to initialize and retrieve a value-string entry from an extended mapping.
Definition value_string.c:402
WS_DLL_PUBLIC const val64_string * _try_val64_to_str_ext_init(const uint64_t val, val64_string_ext *vse)
Attempt to initialize and retrieve a 64-bit value-string entry from an extended mapping.
Definition value_string.c:673
WS_DLL_PUBLIC const char * try_val64_to_str_idx(const uint64_t val, const val64_string *vs, int *idx)
Attempt to convert a 64-bit value to a string and retrieve its index.
Definition value_string.c:152
WS_DLL_PUBLIC const char WS_DLL_PUBLIC const char * val64_to_str_const(const uint64_t val, const val64_string *vs, const char *unknown_str)
Convert a 64-bit value to a constant string using a value-string mapping.
Definition value_string.c:136
WS_DLL_PUBLIC uint32_t str_to_val(const char *val, const value_string *vs, const uint32_t err_val)
Convert a string to its corresponding numeric value using a value-string mapping.
Definition value_string.c:185