Create a message descriptor type.
This replaces the sentinel at the end of the pb_field_t array for each message type. git-svn-id: https://svn.kapsi.fi/jpa/nanopb-dev@1007 e3a754e5-d11d-0410-8d38-ebb782a927b9
This commit is contained in:
committed by
Petteri Aimonen
parent
dcf43a6416
commit
43b8e20744
@@ -74,7 +74,7 @@ This is the way to get the size of the message without storing it anywhere::
|
||||
|
||||
Person myperson = ...;
|
||||
pb_ostream_t sizestream = {0};
|
||||
pb_encode(&sizestream, Person_fields, &myperson);
|
||||
pb_encode(&sizestream, Person_msg, &myperson);
|
||||
printf("Encoded size is %d\n", sizestream.bytes_written);
|
||||
|
||||
**Example 2:**
|
||||
@@ -221,10 +221,10 @@ This callback reads multiple integers and prints them::
|
||||
return true;
|
||||
}
|
||||
|
||||
Field description array
|
||||
=======================
|
||||
Message descriptor
|
||||
==================
|
||||
|
||||
For using the *pb_encode* and *pb_decode* functions, you need an array of pb_field_t constants describing the structure you wish to encode. This description is usually autogenerated from .proto file.
|
||||
For using the *pb_encode* and *pb_decode* functions, you need a message descriptor describing the structure you wish to encode. This description is usually autogenerated from .proto file.
|
||||
|
||||
For example this submessage in the Person.proto file::
|
||||
|
||||
@@ -235,20 +235,27 @@ For example this submessage in the Person.proto file::
|
||||
}
|
||||
}
|
||||
|
||||
generates this field description array for the structure *Person_PhoneNumber*::
|
||||
generates these declarations and definitions for the structure *Person_PhoneNumber*::
|
||||
|
||||
typedef PB_MSG_STRUCT(2) Person_PhoneNumber_msg_t;
|
||||
extern const Person_PhoneNumber_msg_t Person_PhoneNumber_real_msg;
|
||||
#define Person_PhoneNumber_msg ((const pb_message_t*)&Person_PhoneNumber_real_msg)
|
||||
|
||||
const Person_PhoneNumber_msg_t Person_PhoneNumber_real_msg = {
|
||||
2,
|
||||
{
|
||||
|
||||
const pb_field_t Person_PhoneNumber_fields[3] = {
|
||||
{1, PB_HTYPE_REQUIRED | PB_LTYPE_STRING,
|
||||
offsetof(Person_PhoneNumber, number), 0,
|
||||
pb_membersize(Person_PhoneNumber, number), 0, 0},
|
||||
|
||||
{2, PB_HTYPE_OPTIONAL | PB_LTYPE_VARINT,
|
||||
pb_delta(Person_PhoneNumber, type, number),
|
||||
pb_delta_end(Person_PhoneNumber, type, number),
|
||||
pb_delta(Person_PhoneNumber, has_type, type),
|
||||
pb_membersize(Person_PhoneNumber, type), 0,
|
||||
&Person_PhoneNumber_type_default},
|
||||
|
||||
PB_LAST_FIELD
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user