Support dynamic allocation for string, bytes and message fields.
This is turned on by passing -p to nanopb_generator.py or setting the (nanopb).pointer option for a .proto field. git-svn-id: https://svn.kapsi.fi/jpa/nanopb-dev@1081 e3a754e5-d11d-0410-8d38-ebb782a927b9
This commit is contained in:
committed by
Petteri Aimonen
parent
8e5337e9ef
commit
c66c6b43c4
@@ -28,7 +28,7 @@ PB_LTYPE_STRING 0x04 Null-terminated string.
|
||||
PB_LTYPE_SUBMESSAGE 0x05 Submessage structure.
|
||||
==================== ===== ================================================
|
||||
|
||||
The high-order nibble defines whether the field is required, optional, repeated or callback:
|
||||
The high-order nibble defines whether the field is required, optional, repeated or callback, and whether it is a pointer:
|
||||
|
||||
==================== ===== ================================================
|
||||
HTYPE identifier Value Field handling
|
||||
@@ -41,6 +41,10 @@ PB_HTYPE_ARRAY 0x20 A repeated field with preallocated array.
|
||||
PB_HTYPE_CALLBACK 0x30 A field with dynamic storage size, data is
|
||||
actually a pointer to a structure containing a
|
||||
callback function.
|
||||
PB_HTYPE_POINTER 0x80 For required, optional and array non-scalar
|
||||
fields, uses a pointer type (char* for strings,
|
||||
pb_bytes_t for bytes, or a pointer for
|
||||
submessages).
|
||||
==================== ===== ================================================
|
||||
|
||||
pb_field_t
|
||||
@@ -79,6 +83,16 @@ An byte array with a field for storing the length::
|
||||
|
||||
In an actual array, the length of *bytes* may be different.
|
||||
|
||||
pb_bytes_t
|
||||
----------
|
||||
A byte array with fields for storing the allocated and current lengths::
|
||||
|
||||
typedef struct {
|
||||
size_t alloced;
|
||||
size_t size;
|
||||
uint8_t *bytes;
|
||||
} pb_bytes_array_t;
|
||||
|
||||
pb_callback_t
|
||||
-------------
|
||||
Part of a message structure, for fields with type PB_HTYPE_CALLBACK::
|
||||
@@ -368,6 +382,22 @@ In addition to EOF, the pb_decode implementation supports terminating a message
|
||||
|
||||
For optional fields, this function applies the default value and clears the corresponding bit in *has_fields* if the field is not present.
|
||||
|
||||
pb_clean
|
||||
--------
|
||||
Release and clear all the unused pointers of a structure. ::
|
||||
|
||||
bool pb_clean(const pb_message_t *msg, void *dest_struct);
|
||||
|
||||
:msg: A message descriptor. Usually autogenerated.
|
||||
:dest_struct: Pointer to structure to be cleaned.
|
||||
:returns: True on success, false if one of the unused message fields has a pointer type that this function cannot handle.
|
||||
|
||||
For each string or submessage with pointer type, this function calls *free()* on the pointer and sets the pointer to NULL.
|
||||
|
||||
For bytes fields with pointer type, this function calls *free()* on the allocated data, nulls that pointer and zeros the size fields in the generated pb_bytes_t structure.
|
||||
|
||||
For repeated fields, it applies the corresponding operation above to each unused element of the generated array.
|
||||
|
||||
.. sidebar:: Field decoders
|
||||
|
||||
The functions with names beginning with *pb_dec_* are called field decoders. Each PB_LTYPE has an own field decoder, which handles translating from Protocol Buffers data to C data.
|
||||
|
||||
Reference in New Issue
Block a user