mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-18 00:58:31 +00:00
protobuf: vertical output support introduced
Will be used for single-entry images. Signed-off-by: Stanislav Kinsbursky <skinsbursky@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
parent
5809e7d0b3
commit
705411f4bc
2 changed files with 24 additions and 8 deletions
|
|
@ -59,12 +59,17 @@ extern int pb_write_object_with_header(int fd, void *obj,
|
|||
#include <google/protobuf-c/protobuf-c.h>
|
||||
|
||||
extern void do_pb_show_plain(int fd, const ProtobufCMessageDescriptor *d,
|
||||
pb_unpack_t unpack, pb_free_t free);
|
||||
pb_unpack_t unpack, pb_free_t free, int single_entry);
|
||||
|
||||
/* Don't have objects at hands to also do typechecking here */
|
||||
#define pb_show_plain(__fd, __proto_message_name) \
|
||||
do_pb_show_plain(__fd, &__proto_message_name##__descriptor, \
|
||||
(pb_unpack_t)__proto_message_name##__unpack, \
|
||||
(pb_free_t)__proto_message_name##__free_unpacked)
|
||||
(pb_free_t)__proto_message_name##__free_unpacked, 0)
|
||||
|
||||
#define pb_show_vertical(__fd, __proto_message_name) \
|
||||
do_pb_show_plain(__fd, &__proto_message_name##__descriptor, \
|
||||
(pb_unpack_t)__proto_message_name##__unpack, \
|
||||
(pb_free_t)__proto_message_name##__free_unpacked, 1)
|
||||
|
||||
#endif /* PROTOBUF_H__ */
|
||||
|
|
|
|||
23
protobuf.c
23
protobuf.c
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
struct pb_pr_ctrl_s {
|
||||
void *arg;
|
||||
int single_entry;
|
||||
};
|
||||
|
||||
typedef struct pb_pr_ctrl_s pb_pr_ctl_t;
|
||||
|
|
@ -47,13 +48,18 @@ static void pb_msg_unk(void *obj, pb_pr_ctl_t *ctl)
|
|||
pr_msg("unknown object %p\n", obj);
|
||||
}
|
||||
|
||||
static void print_nested_message_braces(pb_pr_ctl_t *ctl, int side)
|
||||
{
|
||||
pr_msg("%s%s", (side) ? "]" : "[", (ctl->single_entry) ? "\n" : " ");
|
||||
}
|
||||
|
||||
static void pb_show_msg(const void *msg, pb_pr_ctl_t *ctl);
|
||||
|
||||
static void show_nested_message(void *msg, pb_pr_ctl_t *ctl)
|
||||
{
|
||||
pr_msg("[ ");
|
||||
print_nested_message_braces(ctl, 0);
|
||||
pb_show_msg(msg, ctl);
|
||||
pr_msg(" ] ");
|
||||
print_nested_message_braces(ctl, 1);
|
||||
}
|
||||
|
||||
static void show_enum(void *msg, pb_pr_ctl_t *ctl)
|
||||
|
|
@ -133,7 +139,10 @@ static void pb_show_field(const ProtobufCFieldDescriptor *fd, void *where,
|
|||
show(where, ctl);
|
||||
}
|
||||
|
||||
pr_msg(" ");
|
||||
if (ctl->single_entry)
|
||||
pr_msg("\n");
|
||||
else
|
||||
pr_msg(" ");
|
||||
}
|
||||
|
||||
static void pb_show_msg(const void *msg, pb_pr_ctl_t *ctl)
|
||||
|
|
@ -164,9 +173,9 @@ static void pb_show_msg(const void *msg, pb_pr_ctl_t *ctl)
|
|||
}
|
||||
|
||||
void do_pb_show_plain(int fd, const ProtobufCMessageDescriptor *md,
|
||||
pb_unpack_t unpack, pb_free_t free)
|
||||
pb_unpack_t unpack, pb_free_t free, int single_entry)
|
||||
{
|
||||
pb_pr_ctl_t ctl = {NULL};
|
||||
pb_pr_ctl_t ctl = {NULL, single_entry};
|
||||
|
||||
while (1) {
|
||||
void *obj;
|
||||
|
|
@ -176,8 +185,10 @@ void do_pb_show_plain(int fd, const ProtobufCMessageDescriptor *md,
|
|||
|
||||
ctl.arg = (void *)md;
|
||||
pb_show_msg(obj, &ctl);
|
||||
pr_msg("\n");
|
||||
free(obj, NULL);
|
||||
if (single_entry)
|
||||
break;
|
||||
pr_msg("\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue