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:
Michael Poole
2011-11-13 18:10:11 +00:00
committed by Petteri Aimonen
parent dcf43a6416
commit 43b8e20744
17 changed files with 127 additions and 101 deletions

View File

@@ -27,7 +27,7 @@ So a typical project might include these files:
- pb_encode.h and pb_encode.c (needed for encoding messages)
2) Protocol description (you can have many):
- person.proto (just an example)
- person.pb.c (autogenerated, contains initializers for const arrays)
- person.pb.c (autogenerated, contains initializers for message descriptors)
- person.pb.h (autogenerated, contains type declarations)
Features and limitations
@@ -74,14 +74,16 @@ You should now have in *message.pb.h*::
int32_t value;
} Example;
extern const pb_field_t Example_fields[2];
typedef PB_MSG_STRUCT(1) Example_msg_t;
extern const Example_msg_t Example_real_msg;
#define Example_msg ((const pb_message_t*)&Example_real_msg)
Now in your main program do this to encode a message::
Example mymessage = {42};
uint8_t buffer[10];
pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
pb_encode(&stream, Example_fields, &mymessage);
pb_encode(&stream, Example_msg, &mymessage);
After that, buffer will contain the encoded message.
The number of bytes in the message is stored in *stream.bytes_written*.