Commit f64633bd authored by Stanislav Kinsbursky's avatar Stanislav Kinsbursky Committed by Pavel Emelyanov

protobuf: service helper for show routine introduced

Signed-off-by: 's avatarStanislav Kinsbursky <skinsbursky@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 3f1b07f5
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
#endif /* BUG_ON_HANDLER */ #endif /* BUG_ON_HANDLER */
#define BUG_ON(condition) BUG_ON_HANDLER((condition)) #define BUG_ON(condition) BUG_ON_HANDLER((condition))
#define BUG() BUG_ON(true)
/* /*
* Write buffer @ptr of @size bytes into @fd file * Write buffer @ptr of @size bytes into @fd file
......
...@@ -221,6 +221,49 @@ static void show_bool(void *msg, pb_pr_ctl_t *ctl) ...@@ -221,6 +221,49 @@ static void show_bool(void *msg, pb_pr_ctl_t *ctl)
pr_msg("False"); pr_msg("False");
} }
static size_t pb_show_prepare_field_context(const ProtobufCFieldDescriptor *fd,
pb_pr_ctl_t *ctl)
{
pb_pr_field_t *field = &ctl->cur;
size_t fsize;
switch (fd->type) {
case PROTOBUF_C_TYPE_ENUM:
ctl->arg = (void *)fd->descriptor;
case PROTOBUF_C_TYPE_INT32:
case PROTOBUF_C_TYPE_SINT32:
case PROTOBUF_C_TYPE_UINT32:
case PROTOBUF_C_TYPE_SFIXED32:
case PROTOBUF_C_TYPE_FLOAT:
fsize = 4;
break;
case PROTOBUF_C_TYPE_INT64:
case PROTOBUF_C_TYPE_SINT64:
case PROTOBUF_C_TYPE_SFIXED64:
case PROTOBUF_C_TYPE_FIXED32:
case PROTOBUF_C_TYPE_UINT64:
case PROTOBUF_C_TYPE_FIXED64:
case PROTOBUF_C_TYPE_DOUBLE:
fsize = 8;
break;
case PROTOBUF_C_TYPE_MESSAGE:
ctl->arg = (void *)fd->descriptor;
field->data = (void *)(*(long *)field->data);
case PROTOBUF_C_TYPE_STRING:
fsize = sizeof (void *);
break;
case PROTOBUF_C_TYPE_BOOL:
fsize = sizeof (protobuf_c_boolean);
break;
case PROTOBUF_C_TYPE_BYTES:
fsize = sizeof (ProtobufCBinaryData);
break;
default:
BUG();
}
return fsize;
}
static void pb_show_field(const ProtobufCFieldDescriptor *fd, static void pb_show_field(const ProtobufCFieldDescriptor *fd,
unsigned long nr_fields, pb_pr_ctl_t *ctl) unsigned long nr_fields, pb_pr_ctl_t *ctl)
{ {
...@@ -233,13 +276,14 @@ static void pb_show_field(const ProtobufCFieldDescriptor *fd, ...@@ -233,13 +276,14 @@ static void pb_show_field(const ProtobufCFieldDescriptor *fd,
pr_msg("%s: ", fd->name); pr_msg("%s: ", fd->name);
fsize = pb_show_prepare_field_context(fd, ctl);
switch (fd->type) { switch (fd->type) {
case PROTOBUF_C_TYPE_INT32: case PROTOBUF_C_TYPE_INT32:
case PROTOBUF_C_TYPE_SINT32: case PROTOBUF_C_TYPE_SINT32:
case PROTOBUF_C_TYPE_UINT32: case PROTOBUF_C_TYPE_UINT32:
case PROTOBUF_C_TYPE_SFIXED32: case PROTOBUF_C_TYPE_SFIXED32:
show = pb_msg_int32x; show = pb_msg_int32x;
fsize = 4;
break; break;
case PROTOBUF_C_TYPE_INT64: case PROTOBUF_C_TYPE_INT64:
case PROTOBUF_C_TYPE_SINT64: case PROTOBUF_C_TYPE_SINT64:
...@@ -248,22 +292,15 @@ static void pb_show_field(const ProtobufCFieldDescriptor *fd, ...@@ -248,22 +292,15 @@ static void pb_show_field(const ProtobufCFieldDescriptor *fd,
case PROTOBUF_C_TYPE_UINT64: case PROTOBUF_C_TYPE_UINT64:
case PROTOBUF_C_TYPE_FIXED64: case PROTOBUF_C_TYPE_FIXED64:
show = pb_msg_int64x; show = pb_msg_int64x;
fsize = 8;
break; break;
case PROTOBUF_C_TYPE_STRING: case PROTOBUF_C_TYPE_STRING:
show = pb_msg_string; show = pb_msg_string;
fsize = sizeof (void *);
break; break;
case PROTOBUF_C_TYPE_MESSAGE: case PROTOBUF_C_TYPE_MESSAGE:
field->data = (void *)(*(long *)field->data);
ctl->arg = (void *)fd->descriptor;
show = show_nested_message; show = show_nested_message;
fsize = sizeof (void *);
break; break;
case PROTOBUF_C_TYPE_ENUM: case PROTOBUF_C_TYPE_ENUM:
show = show_enum; show = show_enum;
ctl->arg = (void *)fd->descriptor;
fsize = 4;
break; break;
case PROTOBUF_C_TYPE_BOOL: case PROTOBUF_C_TYPE_BOOL:
show = show_bool; show = show_bool;
......
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