Commit dffd0aa6 authored by Pavel Emelyanov's avatar Pavel Emelyanov

protobuf: Introduce enum showing function

Try hard to find the symbolic (declared in .proto file) name
for the given value.

Will use enums in fdinfo, thus prepare.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 0cf04ac7
...@@ -51,6 +51,24 @@ static void show_nested_message(void *msg, void *md) ...@@ -51,6 +51,24 @@ static void show_nested_message(void *msg, void *md)
pr_msg(" ] "); pr_msg(" ] ");
} }
static void show_enum(void *msg, void *md)
{
ProtobufCEnumDescriptor *d = md;
const char *val_name = NULL;
int val, i;
val = *(int *)msg;
for (i = 0; i < d->n_values; i++)
if (d->values[i].value == val) {
val_name = d->values[i].name;
break;
}
if (val_name != NULL)
pr_msg("%s", val_name);
else
pr_msg("%d", val);
}
static void pb_show_field(const ProtobufCFieldDescriptor *fd, void *where, static void pb_show_field(const ProtobufCFieldDescriptor *fd, void *where,
unsigned long nr_fields) unsigned long nr_fields)
...@@ -89,10 +107,13 @@ static void pb_show_field(const ProtobufCFieldDescriptor *fd, void *where, ...@@ -89,10 +107,13 @@ static void pb_show_field(const ProtobufCFieldDescriptor *fd, void *where,
show = show_nested_message; show = show_nested_message;
fsize = sizeof (void *); fsize = sizeof (void *);
break; break;
case PROTOBUF_C_TYPE_ENUM:
show = show_enum;
arg = (void *)fd->descriptor;
break;
case PROTOBUF_C_TYPE_FLOAT: case PROTOBUF_C_TYPE_FLOAT:
case PROTOBUF_C_TYPE_DOUBLE: case PROTOBUF_C_TYPE_DOUBLE:
case PROTOBUF_C_TYPE_BOOL: case PROTOBUF_C_TYPE_BOOL:
case PROTOBUF_C_TYPE_ENUM:
case PROTOBUF_C_TYPE_BYTES: case PROTOBUF_C_TYPE_BYTES:
default: default:
show = pb_msg_unk; show = pb_msg_unk;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment