Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
Macros | Typedefs | Functions
protobuf-helper.h File Reference
#include <wsutil/value_string.h>

Go to the source code of this file.

Macros

#define protobuf_field_type_VALUE_STRING_LIST(XXX)
 
#define PROTOBUF_MAX_FIELD_TYPE   18
 

Typedefs

typedef struct PbwDescriptorPool PbwDescriptorPool
 
typedef struct PbwMethodDescriptor PbwMethodDescriptor
 
typedef struct PbwDescriptor PbwDescriptor
 
typedef struct PbwFieldDescriptor PbwFieldDescriptor
 
typedef struct PbwEnumDescriptor PbwEnumDescriptor
 
typedef struct PbwEnumValueDescriptor PbwEnumValueDescriptor
 
typedef void(* pbw_report_error_cb_t) (const char *msg_format,...)
 

Functions

 VALUE_STRING_ENUM (protobuf_field_type)
 
 VALUE_STRING_ARRAY_GLOBAL_DCL (protobuf_field_type)
 
void pbw_reinit_DescriptorPool (PbwDescriptorPool **pool, const char **directories, pbw_report_error_cb_t error_cb)
 
int pbw_load_proto_file (PbwDescriptorPool *pool, const char *filename)
 Loads a Protocol Buffers file into the descriptor pool.
 
const PbwMethodDescriptor * pbw_DescriptorPool_FindMethodByName (const PbwDescriptorPool *pool, const char *name)
 Finds a method descriptor by name in a descriptor pool.
 
const char * pbw_MethodDescriptor_name (const PbwMethodDescriptor *method)
 Get the name of a Protocol Buffers method descriptor.
 
const char * pbw_MethodDescriptor_full_name (const PbwMethodDescriptor *method)
 Get the full name of a method descriptor.
 
const PbwDescriptor * pbw_MethodDescriptor_input_type (const PbwMethodDescriptor *method)
 Retrieves the input type descriptor for a method.
 
const PbwDescriptor * pbw_MethodDescriptor_output_type (const PbwMethodDescriptor *method)
 Retrieves the output type of a method descriptor.
 
const PbwDescriptor * pbw_DescriptorPool_FindMessageTypeByName (const PbwDescriptorPool *pool, const char *name)
 Finds a message type by its name in a descriptor pool.
 
const char * pbw_Descriptor_name (const PbwDescriptor *message)
 Retrieves the name of a Protocol Buffers descriptor.
 
const char * pbw_Descriptor_full_name (const PbwDescriptor *message)
 Get the full name of a Protocol Buffers descriptor.
 
int pbw_Descriptor_field_count (const PbwDescriptor *message)
 Get the count of fields in a Protocol Buffers descriptor.
 
const PbwFieldDescriptor * pbw_Descriptor_field (const PbwDescriptor *message, int field_index)
 Retrieves a field descriptor by index from a message descriptor.
 
const PbwFieldDescriptor * pbw_Descriptor_FindFieldByNumber (const PbwDescriptor *message, int number)
 Finds a field descriptor by its number in a message descriptor.
 
const PbwFieldDescriptor * pbw_Descriptor_FindFieldByName (const PbwDescriptor *message, const char *name)
 Finds a field descriptor by name in a message descriptor.
 
const char * pbw_FieldDescriptor_full_name (const PbwFieldDescriptor *field)
 Get the full name of a field descriptor.
 
const char * pbw_FieldDescriptor_name (const PbwFieldDescriptor *field)
 Retrieves the name of a Protocol Buffers field descriptor.
 
int pbw_FieldDescriptor_number (const PbwFieldDescriptor *field)
 Retrieves the number associated with a Protocol Buffers field descriptor.
 
int pbw_FieldDescriptor_type (const PbwFieldDescriptor *field)
 Get the type of a Protocol Buffers field descriptor.
 
int pbw_FieldDescriptor_is_repeated (const PbwFieldDescriptor *field)
 Check if a field descriptor is repeated.
 
int pbw_FieldDescriptor_is_packed (const PbwFieldDescriptor *field)
 Checks if the given field descriptor is packed.
 
const char * pbw_FieldDescriptor_typeName (wmem_allocator_t *scope, int field_type)
 Retrieves the type name for a given field type.
 
const PbwDescriptor * pbw_FieldDescriptor_message_type (const PbwFieldDescriptor *field)
 Retrieves the message type associated with a Protocol Buffers field descriptor.
 
const PbwEnumDescriptor * pbw_FieldDescriptor_enum_type (const PbwFieldDescriptor *field)
 Get the enum type of a field descriptor.
 
bool pbw_FieldDescriptor_is_required (const PbwFieldDescriptor *field)
 Check if a field descriptor is required.
 
bool pbw_FieldDescriptor_has_default_value (const PbwFieldDescriptor *field)
 Check if a field descriptor has a default value.
 
int32_t pbw_FieldDescriptor_default_value_int32 (const PbwFieldDescriptor *field)
 Retrieves the default value for an int32 field descriptor.
 
int64_t pbw_FieldDescriptor_default_value_int64 (const PbwFieldDescriptor *field)
 Retrieves the default value for a field descriptor as an int64.
 
uint32_t pbw_FieldDescriptor_default_value_uint32 (const PbwFieldDescriptor *field)
 Retrieves the default value for a uint32 field descriptor.
 
uint64_t pbw_FieldDescriptor_default_value_uint64 (const PbwFieldDescriptor *field)
 Get the default value for a uint64 field descriptor.
 
float pbw_FieldDescriptor_default_value_float (const PbwFieldDescriptor *field)
 Retrieves the default value of a float field descriptor.
 
double pbw_FieldDescriptor_default_value_double (const PbwFieldDescriptor *field)
 Retrieves the default value of a double field descriptor.
 
bool pbw_FieldDescriptor_default_value_bool (const PbwFieldDescriptor *field)
 Get the default value of a boolean field descriptor.
 
const char * pbw_FieldDescriptor_default_value_string (const PbwFieldDescriptor *field, int *size)
 Get the default value string of a protobuf field descriptor.
 
const PbwEnumValueDescriptor * pbw_FieldDescriptor_default_value_enum (const PbwFieldDescriptor *field)
 Get the default value of an enum field descriptor.
 
const char * pbw_EnumDescriptor_name (const PbwEnumDescriptor *anEnum)
 Get the name of an enum descriptor.
 
const char * pbw_EnumDescriptor_full_name (const PbwEnumDescriptor *anEnum)
 Get the full name of an enum descriptor.
 
int pbw_EnumDescriptor_value_count (const PbwEnumDescriptor *anEnum)
 Get the count of values in an enum descriptor.
 
const PbwEnumValueDescriptor * pbw_EnumDescriptor_value (const PbwEnumDescriptor *anEnum, int value_index)
 Retrieves a PbwEnumValueDescriptor by its index.
 
const PbwEnumValueDescriptor * pbw_EnumDescriptor_FindValueByNumber (const PbwEnumDescriptor *anEnum, int number)
 Finds an enum value descriptor by its number.
 
const PbwEnumValueDescriptor * pbw_EnumDescriptor_FindValueByName (const PbwEnumDescriptor *anEnum, const char *name)
 Finds a value descriptor by name in an enum descriptor.
 
const char * pbw_EnumValueDescriptor_name (const PbwEnumValueDescriptor *enumValue)
 Get the name of an EnumValueDescriptor.
 
const char * pbw_EnumValueDescriptor_full_name (const PbwEnumValueDescriptor *enumValue)
 Get the full name of an enum value descriptor.
 
int pbw_EnumValueDescriptor_number (const PbwEnumValueDescriptor *enumValue)
 Get the number associated with a Protocol Buffers enum value descriptor.
 
void pbw_foreach_message (const PbwDescriptorPool *pool, void(*cb)(const PbwDescriptor *message, void *userdata), void *userdata)
 Iterates over all messages in a descriptor pool and applies a callback function to each.
 

Detailed Description

C Wrapper Layer of Protocol Buffers Language library. Copyright 2019, Huang Qiangxiong qiang.nosp@m.xion.nosp@m.g.hua.nosp@m.ng@q.nosp@m.q.com

Wireshark - Network traffic analyzer By Gerald Combs geral.nosp@m.d@wi.nosp@m.resha.nosp@m.rk.o.nosp@m.rg Copyright 1998 Gerald Combs

SPDX-License-Identifier: GPL-2.0-or-later

Macro Definition Documentation

◆ protobuf_field_type_VALUE_STRING_LIST

#define protobuf_field_type_VALUE_STRING_LIST (   XXX)
Value:
XXX(PROTOBUF_TYPE_NONE, 0, "") \
XXX(PROTOBUF_TYPE_DOUBLE, 1, "double") \
XXX(PROTOBUF_TYPE_FLOAT, 2, "float") \
XXX(PROTOBUF_TYPE_INT64, 3, "int64") \
XXX(PROTOBUF_TYPE_UINT64, 4, "uint64") \
XXX(PROTOBUF_TYPE_INT32, 5, "int32") \
XXX(PROTOBUF_TYPE_FIXED64, 6, "fixed64") \
XXX(PROTOBUF_TYPE_FIXED32, 7, "fixed32") \
XXX(PROTOBUF_TYPE_BOOL, 8, "bool") \
XXX(PROTOBUF_TYPE_STRING, 9, "string") \
XXX(PROTOBUF_TYPE_GROUP, 10, "group") \
XXX(PROTOBUF_TYPE_MESSAGE, 11, "message") \
XXX(PROTOBUF_TYPE_BYTES, 12, "bytes") \
XXX(PROTOBUF_TYPE_UINT32, 13, "uint32") \
XXX(PROTOBUF_TYPE_ENUM, 14, "enum") \
XXX(PROTOBUF_TYPE_SFIXED32, 15, "sfixed32") \
XXX(PROTOBUF_TYPE_SFIXED64, 16, "sfixed64") \
XXX(PROTOBUF_TYPE_SINT32, 17, "sint32") \
XXX(PROTOBUF_TYPE_SINT64, 18, "sint64")

Function Documentation

◆ pbw_Descriptor_field()

const PbwFieldDescriptor * pbw_Descriptor_field ( const PbwDescriptor *  message,
int  field_index 
)

Retrieves a field descriptor by index from a message descriptor.

Parameters
messageThe message descriptor to search within.
field_indexThe index of the field descriptor to retrieve.
Returns
const PbwFieldDescriptor* A pointer to the retrieved field descriptor, or NULL if not found.

◆ pbw_Descriptor_field_count()

int pbw_Descriptor_field_count ( const PbwDescriptor *  message)

Get the count of fields in a Protocol Buffers descriptor.

Parameters
messagePointer to the Protocol Buffers descriptor.
Returns
int The number of fields in the descriptor.

◆ pbw_Descriptor_FindFieldByName()

const PbwFieldDescriptor * pbw_Descriptor_FindFieldByName ( const PbwDescriptor *  message,
const char *  name 
)

Finds a field descriptor by name in a message descriptor.

Parameters
messageThe message descriptor to search within.
nameThe name of the field to find.
Returns
const PbwFieldDescriptor* A pointer to the found field descriptor, or NULL if not found.

◆ pbw_Descriptor_FindFieldByNumber()

const PbwFieldDescriptor * pbw_Descriptor_FindFieldByNumber ( const PbwDescriptor *  message,
int  number 
)

Finds a field descriptor by its number in a message descriptor.

Parameters
messageThe message descriptor to search within.
numberThe field number to find.
Returns
const PbwFieldDescriptor* A pointer to the found field descriptor, or NULL if not found.

◆ pbw_Descriptor_full_name()

const char * pbw_Descriptor_full_name ( const PbwDescriptor *  message)

Get the full name of a Protocol Buffers descriptor.

Parameters
messagePointer to the PbwDescriptor structure.
Returns
const char* The full name of the descriptor.

◆ pbw_Descriptor_name()

const char * pbw_Descriptor_name ( const PbwDescriptor *  message)

Retrieves the name of a Protocol Buffers descriptor.

Parameters
messagePointer to the PbwDescriptor structure.
Returns
const char* The full name of the descriptor.

◆ pbw_DescriptorPool_FindMessageTypeByName()

const PbwDescriptor * pbw_DescriptorPool_FindMessageTypeByName ( const PbwDescriptorPool *  pool,
const char *  name 
)

Finds a message type by its name in a descriptor pool.

Parameters
poolThe descriptor pool to search within.
nameThe name of the message type to find.
Returns
const PbwDescriptor* A pointer to the found message type, or NULL if not found.

◆ pbw_DescriptorPool_FindMethodByName()

const PbwMethodDescriptor * pbw_DescriptorPool_FindMethodByName ( const PbwDescriptorPool *  pool,
const char *  name 
)

Finds a method descriptor by name in a descriptor pool.

Parameters
poolThe descriptor pool to search within.
nameThe name of the method descriptor to find.
Returns
const PbwMethodDescriptor* A pointer to the found method descriptor, or NULL if not found.

◆ pbw_EnumDescriptor_FindValueByName()

const PbwEnumValueDescriptor * pbw_EnumDescriptor_FindValueByName ( const PbwEnumDescriptor *  anEnum,
const char *  name 
)

Finds a value descriptor by name in an enum descriptor.

Parameters
anEnumThe enum descriptor to search within.
nameThe name of the value descriptor to find.
Returns
const PbwEnumValueDescriptor* A pointer to the found value descriptor, or NULL if not found.

◆ pbw_EnumDescriptor_FindValueByNumber()

const PbwEnumValueDescriptor * pbw_EnumDescriptor_FindValueByNumber ( const PbwEnumDescriptor *  anEnum,
int  number 
)

Finds an enum value descriptor by its number.

Parameters
anEnumThe enum descriptor to search within.
numberThe number of the enum value to find.
Returns
const PbwEnumValueDescriptor* A pointer to the found enum value descriptor, or NULL if not found.

◆ pbw_EnumDescriptor_full_name()

const char * pbw_EnumDescriptor_full_name ( const PbwEnumDescriptor *  anEnum)

Get the full name of an enum descriptor.

Parameters
anEnumPointer to the PbwEnumDescriptor structure.
Returns
const char* The full name of the enum descriptor.

◆ pbw_EnumDescriptor_name()

const char * pbw_EnumDescriptor_name ( const PbwEnumDescriptor *  anEnum)

Get the name of an enum descriptor.

Parameters
anEnumThe enum descriptor to get the name from.
Returns
const char* The name of the enum descriptor.

◆ pbw_EnumDescriptor_value()

const PbwEnumValueDescriptor * pbw_EnumDescriptor_value ( const PbwEnumDescriptor *  anEnum,
int  value_index 
)

Retrieves a PbwEnumValueDescriptor by its index.

Parameters
anEnumThe PbwEnumDescriptor to search within.
value_indexThe index of the value descriptor to retrieve.
Returns
const PbwEnumValueDescriptor* A pointer to the retrieved value descriptor, or NULL if not found.

◆ pbw_EnumDescriptor_value_count()

int pbw_EnumDescriptor_value_count ( const PbwEnumDescriptor *  anEnum)

Get the count of values in an enum descriptor.

Parameters
anEnumThe enum descriptor to query.
Returns
The number of values in the enum descriptor.

◆ pbw_EnumValueDescriptor_full_name()

const char * pbw_EnumValueDescriptor_full_name ( const PbwEnumValueDescriptor *  enumValue)

Get the full name of an enum value descriptor.

Parameters
enumValueThe enum value descriptor to query.
Returns
const char* The full name of the enum value descriptor.

◆ pbw_EnumValueDescriptor_name()

const char * pbw_EnumValueDescriptor_name ( const PbwEnumValueDescriptor *  enumValue)

Get the name of an EnumValueDescriptor.

Parameters
enumValuePointer to the EnumValueDescriptor.
Returns
const char* The name of the EnumValueDescriptor.

◆ pbw_EnumValueDescriptor_number()

int pbw_EnumValueDescriptor_number ( const PbwEnumValueDescriptor *  enumValue)

Get the number associated with a Protocol Buffers enum value descriptor.

Parameters
enumValuePointer to the Protocol Buffers enum value descriptor.
Returns
The number associated with the enum value descriptor.

◆ pbw_FieldDescriptor_default_value_bool()

bool pbw_FieldDescriptor_default_value_bool ( const PbwFieldDescriptor *  field)

Get the default value of a boolean field descriptor.

Parameters
fieldThe PbwFieldDescriptor to query.
Returns
bool The default value of the field.

◆ pbw_FieldDescriptor_default_value_double()

double pbw_FieldDescriptor_default_value_double ( const PbwFieldDescriptor *  field)

Retrieves the default value of a double field descriptor.

Parameters
fieldThe PbwFieldDescriptor for which to retrieve the default value.
Returns
The default value as a double.

◆ pbw_FieldDescriptor_default_value_enum()

const PbwEnumValueDescriptor * pbw_FieldDescriptor_default_value_enum ( const PbwFieldDescriptor *  field)

Get the default value of an enum field descriptor.

Parameters
fieldThe PbwFieldDescriptor to query.
Returns
const PbwEnumValueDescriptor* The default value as an enum value descriptor.

◆ pbw_FieldDescriptor_default_value_float()

float pbw_FieldDescriptor_default_value_float ( const PbwFieldDescriptor *  field)

Retrieves the default value of a float field descriptor.

Parameters
fieldPointer to the PbwFieldDescriptor structure.
Returns
The default value as a float.

◆ pbw_FieldDescriptor_default_value_int32()

int32_t pbw_FieldDescriptor_default_value_int32 ( const PbwFieldDescriptor *  field)

Retrieves the default value for an int32 field descriptor.

Parameters
fieldThe PbwFieldDescriptor to query.
Returns
int32_t The default value of the field.

◆ pbw_FieldDescriptor_default_value_int64()

int64_t pbw_FieldDescriptor_default_value_int64 ( const PbwFieldDescriptor *  field)

Retrieves the default value for a field descriptor as an int64.

Parameters
fieldThe PbwFieldDescriptor to query.
Returns
int64_t The default value of the field.

◆ pbw_FieldDescriptor_default_value_string()

const char * pbw_FieldDescriptor_default_value_string ( const PbwFieldDescriptor *  field,
int *  size 
)

Get the default value string of a protobuf field descriptor.

Parameters
fieldThe PbwFieldDescriptor to query.
sizePointer to an integer where the length of the default value string will be stored.
Returns
const char* The default value string, or NULL if not applicable.

◆ pbw_FieldDescriptor_default_value_uint32()

uint32_t pbw_FieldDescriptor_default_value_uint32 ( const PbwFieldDescriptor *  field)

Retrieves the default value for a uint32 field descriptor.

Parameters
fieldPointer to the PbwFieldDescriptor structure.
Returns
The default value as a uint32_t.

◆ pbw_FieldDescriptor_default_value_uint64()

uint64_t pbw_FieldDescriptor_default_value_uint64 ( const PbwFieldDescriptor *  field)

Get the default value for a uint64 field descriptor.

Parameters
fieldThe PbwFieldDescriptor to query.
Returns
uint64_t The default value of the field.

◆ pbw_FieldDescriptor_enum_type()

const PbwEnumDescriptor * pbw_FieldDescriptor_enum_type ( const PbwFieldDescriptor *  field)

Get the enum type of a field descriptor.

Parameters
fieldThe PbwFieldDescriptor to query.
Returns
const PbwEnumDescriptor* The enum type of the field, or NULL if not an enum field.

◆ pbw_FieldDescriptor_full_name()

const char * pbw_FieldDescriptor_full_name ( const PbwFieldDescriptor *  field)

Get the full name of a field descriptor.

Parameters
fieldThe field descriptor to query.
Returns
const char* The full name of the field.

◆ pbw_FieldDescriptor_has_default_value()

bool pbw_FieldDescriptor_has_default_value ( const PbwFieldDescriptor *  field)

Check if a field descriptor has a default value.

Parameters
fieldThe field descriptor to check.
Returns
int 1 if the field has a default value, 0 otherwise.

◆ pbw_FieldDescriptor_is_packed()

int pbw_FieldDescriptor_is_packed ( const PbwFieldDescriptor *  field)

Checks if the given field descriptor is packed.

Parameters
fieldThe field descriptor to check.
Returns
true if the field is packed, false otherwise.

◆ pbw_FieldDescriptor_is_repeated()

int pbw_FieldDescriptor_is_repeated ( const PbwFieldDescriptor *  field)

Check if a field descriptor is repeated.

Parameters
fieldThe field descriptor to check.
Returns
int Returns non-zero if the field is repeated, zero otherwise.

◆ pbw_FieldDescriptor_is_required()

bool pbw_FieldDescriptor_is_required ( const PbwFieldDescriptor *  field)

Check if a field descriptor is required.

Parameters
fieldThe field descriptor to check.
Returns
true if the field is required, false otherwise.

◆ pbw_FieldDescriptor_message_type()

const PbwDescriptor * pbw_FieldDescriptor_message_type ( const PbwFieldDescriptor *  field)

Retrieves the message type associated with a Protocol Buffers field descriptor.

Parameters
fieldPointer to the PbwFieldDescriptor structure.
Returns
const PbwDescriptor* Pointer to the message type descriptor, or NULL if not applicable.

◆ pbw_FieldDescriptor_name()

const char * pbw_FieldDescriptor_name ( const PbwFieldDescriptor *  field)

Retrieves the name of a Protocol Buffers field descriptor.

Parameters
fieldPointer to the PbwFieldDescriptor structure.
Returns
The name of the field as a string.

◆ pbw_FieldDescriptor_number()

int pbw_FieldDescriptor_number ( const PbwFieldDescriptor *  field)

Retrieves the number associated with a Protocol Buffers field descriptor.

Parameters
fieldPointer to the Protocol Buffers field descriptor.
Returns
The number of the field descriptor.

◆ pbw_FieldDescriptor_type()

int pbw_FieldDescriptor_type ( const PbwFieldDescriptor *  field)

Get the type of a Protocol Buffers field descriptor.

Parameters
fieldPointer to the Protocol Buffers field descriptor.
Returns
The type of the field descriptor.

◆ pbw_FieldDescriptor_typeName()

const char * pbw_FieldDescriptor_typeName ( wmem_allocator_t scope,
int  field_type 
)

Retrieves the type name for a given field type.

Parameters
scopeThe memory allocator scope.
field_typeThe field type to retrieve the type name for.
Returns
const char* The type name of the field type.

◆ pbw_foreach_message()

void pbw_foreach_message ( const PbwDescriptorPool *  pool,
void(*)(const PbwDescriptor *message, void *userdata)  cb,
void *  userdata 
)

Iterates over all messages in a descriptor pool and applies a callback function to each.

Parameters
poolThe descriptor pool containing the messages.
cbCallback function to be applied to each message, taking a PbwDescriptor pointer and user data as arguments.
userdataUser data to be passed to the callback function.

◆ pbw_load_proto_file()

int pbw_load_proto_file ( PbwDescriptorPool *  pool,
const char *  filename 
)

Loads a Protocol Buffers file into the descriptor pool.

Parameters
poolThe descriptor pool to load the file into.
filenameThe path to the Protocol Buffers file to load.
Returns
int 0 on success, non-zero on failure.

◆ pbw_MethodDescriptor_full_name()

const char * pbw_MethodDescriptor_full_name ( const PbwMethodDescriptor *  method)

Get the full name of a method descriptor.

Parameters
methodThe method descriptor to query.
Returns
const PbwDescriptor* The full name of the method.

◆ pbw_MethodDescriptor_input_type()

const PbwDescriptor * pbw_MethodDescriptor_input_type ( const PbwMethodDescriptor *  method)

Retrieves the input type descriptor for a method.

Parameters
methodPointer to the PbwMethodDescriptor object.
Returns
const PbwDescriptor* Pointer to the input type descriptor, or NULL if not found.

◆ pbw_MethodDescriptor_name()

const char * pbw_MethodDescriptor_name ( const PbwMethodDescriptor *  method)

Get the name of a Protocol Buffers method descriptor.

Parameters
methodPointer to the PbwMethodDescriptor structure.
Returns
const char* The name of the method descriptor.

◆ pbw_MethodDescriptor_output_type()

const PbwDescriptor * pbw_MethodDescriptor_output_type ( const PbwMethodDescriptor *  method)

Retrieves the output type of a method descriptor.

Parameters
methodThe method descriptor to query.
Returns
const PbwDescriptor* A pointer to the output descriptor of the method.

◆ pbw_reinit_DescriptorPool()

void pbw_reinit_DescriptorPool ( PbwDescriptorPool **  pool,
const char **  directories,
pbw_report_error_cb_t  error_cb 
)

Reinitialize PbwDescriptorPool according to proto files directories.

Parameters
poolThe output DescriptorPool will be created. If *pool is not NULL, it will free it first.
directoriesThe root directories containing proto files. Must end with NULL element.
error_cbThe error reporter callback function.