mirror of
https://github.com/protobuf-c/protobuf-c.git
synced 2024-12-27 22:01:02 +08:00
minor adjustments to the field flags patch
rename PROTOBUF_C_FIELD_FLAGS_PACKED to PROTOBUF_C_FIELD_FLAG_PACKED. rename ProtobufCFieldFlagType to ProtobufCFieldFlag. wrap some particular long lines. update documentation. for clarity, use a "uint32_t" instead of "unsigned" for the 'flags' field in _ProtobufCFieldDescriptor.
This commit is contained in:
parent
9c6f2fe4d3
commit
8a71fdab60
@ -388,7 +388,7 @@ repeated_field_get_packed_size(const ProtobufCFieldDescriptor *field,
|
|||||||
if (count == 0)
|
if (count == 0)
|
||||||
return 0;
|
return 0;
|
||||||
header_size = get_tag_size(field->id);
|
header_size = get_tag_size(field->id);
|
||||||
if (0 == (field->flags & PROTOBUF_C_FIELD_FLAGS_PACKED))
|
if (0 == (field->flags & PROTOBUF_C_FIELD_FLAG_PACKED))
|
||||||
header_size *= count;
|
header_size *= count;
|
||||||
|
|
||||||
switch (field->type) {
|
switch (field->type) {
|
||||||
@ -449,7 +449,7 @@ repeated_field_get_packed_size(const ProtobufCFieldDescriptor *field,
|
|||||||
/* case PROTOBUF_C_TYPE_GROUP: -- NOT SUPPORTED */
|
/* case PROTOBUF_C_TYPE_GROUP: -- NOT SUPPORTED */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 != (field->flags & PROTOBUF_C_FIELD_FLAGS_PACKED))
|
if (0 != (field->flags & PROTOBUF_C_FIELD_FLAG_PACKED))
|
||||||
header_size += uint32_size(rv);
|
header_size += uint32_size(rv);
|
||||||
return header_size + rv;
|
return header_size + rv;
|
||||||
}
|
}
|
||||||
@ -872,7 +872,7 @@ repeated_field_pack(const ProtobufCFieldDescriptor *field,
|
|||||||
void *array = *(void * const *) member;
|
void *array = *(void * const *) member;
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
|
||||||
if (0 != (field->flags & PROTOBUF_C_FIELD_FLAGS_PACKED)) {
|
if (0 != (field->flags & PROTOBUF_C_FIELD_FLAG_PACKED)) {
|
||||||
unsigned header_len;
|
unsigned header_len;
|
||||||
unsigned len_start;
|
unsigned len_start;
|
||||||
unsigned min_length;
|
unsigned min_length;
|
||||||
@ -1300,7 +1300,7 @@ repeated_field_pack_to_buffer(const ProtobufCFieldDescriptor *field,
|
|||||||
|
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
return 0;
|
return 0;
|
||||||
if (0 != (field->flags & PROTOBUF_C_FIELD_FLAGS_PACKED)) {
|
if (0 != (field->flags & PROTOBUF_C_FIELD_FLAG_PACKED)) {
|
||||||
uint8_t scratch[MAX_UINT64_ENCODED_SIZE * 2];
|
uint8_t scratch[MAX_UINT64_ENCODED_SIZE * 2];
|
||||||
size_t rv = tag_pack(field->id, scratch);
|
size_t rv = tag_pack(field->id, scratch);
|
||||||
size_t payload_len = get_packed_payload_length(field, count, array);
|
size_t payload_len = get_packed_payload_length(field, count, array);
|
||||||
@ -2169,7 +2169,8 @@ parse_member(ScannedMember *scanned_member,
|
|||||||
case PROTOBUF_C_LABEL_REPEATED:
|
case PROTOBUF_C_LABEL_REPEATED:
|
||||||
if (scanned_member->wire_type ==
|
if (scanned_member->wire_type ==
|
||||||
PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED &&
|
PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED &&
|
||||||
(0 != (field->flags & PROTOBUF_C_FIELD_FLAGS_PACKED) || is_packable_type(field->type)))
|
(0 != (field->flags & PROTOBUF_C_FIELD_FLAG_PACKED) ||
|
||||||
|
is_packable_type(field->type)))
|
||||||
{
|
{
|
||||||
return parse_packed_repeated_member(scanned_member,
|
return parse_packed_repeated_member(scanned_member,
|
||||||
member, message);
|
member, message);
|
||||||
@ -2446,7 +2447,8 @@ protobuf_c_message_unpack(const ProtobufCMessageDescriptor *desc,
|
|||||||
size_t *n = STRUCT_MEMBER_PTR(size_t, rv,
|
size_t *n = STRUCT_MEMBER_PTR(size_t, rv,
|
||||||
field->quantifier_offset);
|
field->quantifier_offset);
|
||||||
if (wire_type == PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED &&
|
if (wire_type == PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED &&
|
||||||
(0 != (field->flags & PROTOBUF_C_FIELD_FLAGS_PACKED) || is_packable_type(field->type)))
|
(0 != (field->flags & PROTOBUF_C_FIELD_FLAG_PACKED) ||
|
||||||
|
is_packable_type(field->type)))
|
||||||
{
|
{
|
||||||
size_t count;
|
size_t count;
|
||||||
if (!count_packed_elements(field->type,
|
if (!count_packed_elements(field->type,
|
||||||
|
@ -228,8 +228,8 @@ typedef void (*ProtobufCMessageInit)(ProtobufCMessage *);
|
|||||||
* otherwise NULL.
|
* otherwise NULL.
|
||||||
* 'default_value' is a pointer to a default value for this field,
|
* 'default_value' is a pointer to a default value for this field,
|
||||||
* where allowed.
|
* where allowed.
|
||||||
* 'packed' is only for REPEATED fields (it is 0 otherwise); this is if
|
* 'flags' is a flag word. Zero or more of the bits defined in the
|
||||||
* the repeated fields is marked with the 'packed' options.
|
* ProtobufCFieldFlag enum may be set.
|
||||||
*/
|
*/
|
||||||
struct _ProtobufCFieldDescriptor {
|
struct _ProtobufCFieldDescriptor {
|
||||||
const char *name;
|
const char *name;
|
||||||
@ -240,7 +240,7 @@ struct _ProtobufCFieldDescriptor {
|
|||||||
unsigned offset;
|
unsigned offset;
|
||||||
const void *descriptor; /* for MESSAGE and ENUM types */
|
const void *descriptor; /* for MESSAGE and ENUM types */
|
||||||
const void *default_value; /* can be NULL */
|
const void *default_value; /* can be NULL */
|
||||||
unsigned flags;
|
uint32_t flags;
|
||||||
|
|
||||||
unsigned reserved_flags;
|
unsigned reserved_flags;
|
||||||
void *reserved2;
|
void *reserved2;
|
||||||
@ -248,8 +248,9 @@ struct _ProtobufCFieldDescriptor {
|
|||||||
};
|
};
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
PROTOBUF_C_FIELD_FLAGS_PACKED = (1 << 0),
|
/* Set if the field is repeated and marked with the 'packed' option. */
|
||||||
} ProtobufCFieldFlagType;
|
PROTOBUF_C_FIELD_FLAG_PACKED = (1 << 0),
|
||||||
|
} ProtobufCFieldFlag;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ProtobufCMessageDescriptor: description of a message.
|
* ProtobufCMessageDescriptor: description of a message.
|
||||||
|
@ -128,7 +128,7 @@ void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer,
|
|||||||
if (descriptor_->label() == FieldDescriptor::LABEL_REPEATED
|
if (descriptor_->label() == FieldDescriptor::LABEL_REPEATED
|
||||||
&& is_packable_type (descriptor_->type())
|
&& is_packable_type (descriptor_->type())
|
||||||
&& descriptor_->options().packed())
|
&& descriptor_->options().packed())
|
||||||
variables["flags"] += " | PROTOBUF_C_FIELD_FLAGS_PACKED";
|
variables["flags"] += " | PROTOBUF_C_FIELD_FLAG_PACKED";
|
||||||
|
|
||||||
printer->Print(variables,
|
printer->Print(variables,
|
||||||
"{\n"
|
"{\n"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user