[CRIU] Re: [PATCH] protobuf: add helper function to calculate field
size
Cyrill Gorcunov
gorcunov at openvz.org
Fri Jul 27 10:06:45 EDT 2012
On Fri, Jul 27, 2012 at 05:53:19PM +0400, Kinsbursky Stanislav wrote:
> Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
>
> ---
> protobuf.c | 35 ++++++++++++++++++++++++++++++-----
> 1 files changed, 30 insertions(+), 5 deletions(-)
>
> diff --git a/protobuf.c b/protobuf.c
> index f5b5bd4..5970494 100644
> --- a/protobuf.c
> +++ b/protobuf.c
> @@ -97,12 +97,41 @@ static void show_enum(void *msg, pb_pr_ctl_t *ctl)
> pr_msg("%d", val);
> }
>
> +static size_t get_field_size(int type)
> +{
> + switch (type) {
> + case PROTOBUF_C_TYPE_INT32:
> + case PROTOBUF_C_TYPE_SINT32:
> + case PROTOBUF_C_TYPE_UINT32:
> + case PROTOBUF_C_TYPE_SFIXED32:
> + case PROTOBUF_C_TYPE_ENUM:
> + case PROTOBUF_C_TYPE_FLOAT:
> + return 4;
> + 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:
> + return 8;
> + case PROTOBUF_C_TYPE_STRING:
> + case PROTOBUF_C_TYPE_MESSAGE:
> + return sizeof (void *);
> + case PROTOBUF_C_TYPE_BOOL:
> + return sizeof (protobuf_c_boolean);
> + case PROTOBUF_C_TYPE_BYTES:
> + return sizeof (ProtobufCBinaryData);
> + }
> + return 0;
> +}
Stas, for some reason you've indented "case" statements, while
we prefer kernel style and do not indent them in general.
Not a big deal but could you shift them one tab left please?
A to zopa kakaya-to ;)
Cyrill
More information about the CRIU
mailing list