From 9c6f2fe4d3082008116b346b32eb237a3dadfc69 Mon Sep 17 00:00:00 2001 From: Andrei Nigmatulin Date: Wed, 2 Apr 2014 00:47:08 +0100 Subject: [PATCH] turned ProtobufCFieldDescriptor->packed into ->flags --- protobuf-c/protobuf-c.c | 12 ++++++------ protobuf-c/protobuf-c.h | 6 +++++- protoc-c/c_field.cc | 8 ++++---- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/protobuf-c/protobuf-c.c b/protobuf-c/protobuf-c.c index 5a79a3b..d31c589 100644 --- a/protobuf-c/protobuf-c.c +++ b/protobuf-c/protobuf-c.c @@ -388,7 +388,7 @@ repeated_field_get_packed_size(const ProtobufCFieldDescriptor *field, if (count == 0) return 0; header_size = get_tag_size(field->id); - if (!field->packed) + if (0 == (field->flags & PROTOBUF_C_FIELD_FLAGS_PACKED)) header_size *= count; switch (field->type) { @@ -449,7 +449,7 @@ repeated_field_get_packed_size(const ProtobufCFieldDescriptor *field, /* case PROTOBUF_C_TYPE_GROUP: -- NOT SUPPORTED */ } - if (field->packed) + if (0 != (field->flags & PROTOBUF_C_FIELD_FLAGS_PACKED)) header_size += uint32_size(rv); return header_size + rv; } @@ -872,7 +872,7 @@ repeated_field_pack(const ProtobufCFieldDescriptor *field, void *array = *(void * const *) member; unsigned i; - if (field->packed) { + if (0 != (field->flags & PROTOBUF_C_FIELD_FLAGS_PACKED)) { unsigned header_len; unsigned len_start; unsigned min_length; @@ -1300,7 +1300,7 @@ repeated_field_pack_to_buffer(const ProtobufCFieldDescriptor *field, if (count == 0) return 0; - if (field->packed) { + if (0 != (field->flags & PROTOBUF_C_FIELD_FLAGS_PACKED)) { uint8_t scratch[MAX_UINT64_ENCODED_SIZE * 2]; size_t rv = tag_pack(field->id, scratch); size_t payload_len = get_packed_payload_length(field, count, array); @@ -2169,7 +2169,7 @@ parse_member(ScannedMember *scanned_member, case PROTOBUF_C_LABEL_REPEATED: if (scanned_member->wire_type == PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED && - (field->packed || is_packable_type(field->type))) + (0 != (field->flags & PROTOBUF_C_FIELD_FLAGS_PACKED) || is_packable_type(field->type))) { return parse_packed_repeated_member(scanned_member, member, message); @@ -2446,7 +2446,7 @@ protobuf_c_message_unpack(const ProtobufCMessageDescriptor *desc, size_t *n = STRUCT_MEMBER_PTR(size_t, rv, field->quantifier_offset); if (wire_type == PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED && - (field->packed || is_packable_type(field->type))) + (0 != (field->flags & PROTOBUF_C_FIELD_FLAGS_PACKED) || is_packable_type(field->type))) { size_t count; if (!count_packed_elements(field->type, diff --git a/protobuf-c/protobuf-c.h b/protobuf-c/protobuf-c.h index 4560e5f..dcbb4ac 100644 --- a/protobuf-c/protobuf-c.h +++ b/protobuf-c/protobuf-c.h @@ -240,13 +240,17 @@ struct _ProtobufCFieldDescriptor { unsigned offset; const void *descriptor; /* for MESSAGE and ENUM types */ const void *default_value; /* can be NULL */ - protobuf_c_boolean packed; + unsigned flags; unsigned reserved_flags; void *reserved2; void *reserved3; }; +typedef enum { + PROTOBUF_C_FIELD_FLAGS_PACKED = (1 << 0), +} ProtobufCFieldFlagType; + /* * ProtobufCMessageDescriptor: description of a message. * diff --git a/protoc-c/c_field.cc b/protoc-c/c_field.cc index c6f1dac..847f125 100644 --- a/protoc-c/c_field.cc +++ b/protoc-c/c_field.cc @@ -123,12 +123,12 @@ void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer, variables["default_value"] = "NULL"; } + variables["flags"] = "0"; + if (descriptor_->label() == FieldDescriptor::LABEL_REPEATED && is_packable_type (descriptor_->type()) && descriptor_->options().packed()) - variables["packed"] = "1"; - else - variables["packed"] = "0"; + variables["flags"] += " | PROTOBUF_C_FIELD_FLAGS_PACKED"; printer->Print(variables, "{\n" @@ -154,7 +154,7 @@ void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer, printer->Print(variables, " PROTOBUF_C_OFFSETOF($classname$, $name$),\n"); printer->Print(variables, " $descriptor_addr$,\n"); printer->Print(variables, " $default_value$,\n"); - printer->Print(variables, " $packed$, /* packed */\n"); + printer->Print(variables, " $flags$, /* flags */\n"); printer->Print(variables, " 0,NULL,NULL /* reserved1,reserved2, etc */\n"); printer->Print("},\n"); }