Merge the generated has_<name> fields into a single one.

git-svn-id: https://svn.kapsi.fi/jpa/nanopb-dev@1008 e3a754e5-d11d-0410-8d38-ebb782a927b9
This commit is contained in:
Michael Poole
2011-11-13 18:10:19 +00:00
committed by Petteri Aimonen
parent 43b8e20744
commit 8e5337e9ef
12 changed files with 87 additions and 40 deletions

View File

@@ -250,14 +250,34 @@ generates these declarations and definitions for the structure *Person_PhoneNumb
pb_membersize(Person_PhoneNumber, number), 0, 0},
{2, PB_HTYPE_OPTIONAL | PB_LTYPE_VARINT,
pb_delta_end(Person_PhoneNumber, type, number),
pb_delta(Person_PhoneNumber, has_type, type),
pb_delta_end(Person_PhoneNumber, type, number), 0,
pb_membersize(Person_PhoneNumber, type), 0,
&Person_PhoneNumber_type_default},
}
};
#define Person_PhoneNumber_has(STRUCT, FIELD) PB_HAS_FIELD(STRUCT, Person_PhoneNumber, FIELD)
#define Person_PhoneNumber_set(STRUCT, FIELD) PB_SET_FIELD(STRUCT, Person_PhoneNumber, FIELD)
#define Person_PhoneNumber_clear(STRUCT, FIELD) PB_CLEAR_FIELD(STRUCT, Person_PhoneNumber, FIELD)
#define Person_PhoneNumber_number_index 0
#define Person_PhoneNumber_number_tag 1
#define Person_PhoneNumber_type_index 1
#define Person_PhoneNumber_type_tag 2
Optional Fields
===============
The *has_fields* member of each generated structure is an array where
each bit indicates the presence of the corresponding (optional) field.
The generated header file provides helper macros to read and update
that array; in the previous example, they are
*Person_PhoneNumber_has*, *Person_PhoneNumber_set* and
*Person_PhoneNumber_clear*.
For convenience, *pb_encode* only checks these bits for optional
fields. *pb_decode* sets the corresponding bit for every field it
decodes, whether the field is optional or not.
Return values and error handling
================================

View File

@@ -34,8 +34,8 @@ The high-order nibble defines whether the field is required, optional, repeated
HTYPE identifier Value Field handling
==================== ===== ================================================
PB_HTYPE_REQUIRED 0x00 Verify that field exists in decoded message.
PB_HTYPE_OPTIONAL 0x10 Use separate *has_<field>* boolean to specify
whether the field is present.
PB_HTYPE_OPTIONAL 0x10 Use the structure's *has_fields* bit array to
specify whether the field is present.
PB_HTYPE_ARRAY 0x20 A repeated field with preallocated array.
Separate *<field>_count* for number of items.
PB_HTYPE_CALLBACK 0x30 A field with dynamic storage size, data is
@@ -61,7 +61,7 @@ Describes a single structure field with memory position in relation to others. T
:tag: Tag number of the field or 0 to terminate a list of fields.
:type: LTYPE and HTYPE of the field.
:data_offset: Offset of field data, relative to the end of the previous field.
:size_offset: Offset of *bool* flag for optional fields or *size_t* count for arrays, relative to field data.
:size_offset: Offset of *size_t* count for arrays, relative to field data.
:data_size: Size of a single data entry, in bytes. For PB_LTYPE_BYTES, the size of the byte array inside the containing structure. For PB_HTYPE_CALLBACK, size of the C data type if known.
:array_size: Maximum number of entries in an array, if it is an array type.
:ptr: Pointer to default value for optional fields, or to submessage description for PB_LTYPE_SUBMESSAGE.
@@ -366,9 +366,7 @@ In Protocol Buffers binary format, EOF is only allowed between fields. If it hap
In addition to EOF, the pb_decode implementation supports terminating a message with a 0 byte. This is compatible with the official Protocol Buffers because 0 is never a valid field tag.
For optional fields, this function applies the default value and sets *has_<field>* to false if the field is not present.
Because of memory concerns, the detection of missing required fields is not perfect if the structure contains more than 32 fields.
For optional fields, this function applies the default value and clears the corresponding bit in *has_fields* if the field is not present.
.. sidebar:: Field decoders