documentation
git-svn-id: https://svn.kapsi.fi/jpa/nanopb@969 e3a754e5-d11d-0410-8d38-ebb782a927b9
This commit is contained in:
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
|||||||
Copyright (c) 2011 Petteri Aimonen <jpa@kapsi.fi>
|
Copyright (c) 2011 Petteri Aimonen <jpa at nanopb.mail.kapsi.fi>
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
|
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
|
||||||
|
|
||||||
|
|||||||
@@ -21,10 +21,10 @@ So a typical project might include these files:
|
|||||||
|
|
||||||
1) Nanopb runtime library:
|
1) Nanopb runtime library:
|
||||||
- pb.h
|
- pb.h
|
||||||
- pb_decode.h and pb_decode.c
|
- pb_decode.h and pb_decode.c (needed for decoding messages)
|
||||||
- pb_encode.h and pb_encode.c
|
- pb_encode.h and pb_encode.c (needed for encoding messages)
|
||||||
2) Protocol description (you can have many):
|
2) Protocol description (you can have many):
|
||||||
- person.proto
|
- person.proto (just an example)
|
||||||
- person.c (autogenerated, contains initializers for const arrays)
|
- person.c (autogenerated, contains initializers for const arrays)
|
||||||
- person.h (autogenerated, contains type declarations)
|
- person.h (autogenerated, contains type declarations)
|
||||||
|
|
||||||
@@ -59,12 +59,12 @@ For starters, consider this simple message::
|
|||||||
required int32 value = 1;
|
required int32 value = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Save this in *example.proto* and compile it::
|
Save this in *message.proto* and compile it::
|
||||||
|
|
||||||
user@host:~$ protoc -omessage.pb message.proto
|
user@host:~$ protoc -omessage.pb message.proto
|
||||||
user@host:~$ python ../generator/nanopb_generator.py message.pb
|
user@host:~$ python nanopb/generator/nanopb_generator.py message.pb
|
||||||
|
|
||||||
You should now have in *example.h*::
|
You should now have in *message.pb.h*::
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t value;
|
int32_t value;
|
||||||
@@ -81,7 +81,20 @@ Now in your main program do this to encode a message::
|
|||||||
|
|
||||||
After that, buffer will contain the encoded message.
|
After that, buffer will contain the encoded message.
|
||||||
The number of bytes in the message is stored in *stream.bytes_written*.
|
The number of bytes in the message is stored in *stream.bytes_written*.
|
||||||
You can feed the message to *protoc --decode=Example example.proto* to verify its validity.
|
You can feed the message to *protoc --decode=Example message.proto* to verify its validity.
|
||||||
|
|
||||||
|
For complete examples of the simple cases, see *tests/test_decode1.c* and *tests/test_encode1.c*. For an example with network interface, see the *example* subdirectory.
|
||||||
|
|
||||||
|
Compiler requirements
|
||||||
|
=====================
|
||||||
|
Nanopb should compile with most ansi-C compatible compilers. It however requires a few header files to be available:
|
||||||
|
|
||||||
|
#) *string.h*, with these functions: *strlen*, *memcpy*, *memset*
|
||||||
|
#) *stdint.h*, for definitions of *int32_t* etc.
|
||||||
|
#) *stddef.h*, for definition of *size_t*
|
||||||
|
#) *stdbool.h*, for definition of *bool*
|
||||||
|
|
||||||
|
If these header files do not come with your compiler, you should be able to find suitable replacements online. Mostly the requirements are very simple, just a few basic functions and typedefs.
|
||||||
|
|
||||||
Debugging and testing
|
Debugging and testing
|
||||||
=====================
|
=====================
|
||||||
|
|||||||
Reference in New Issue
Block a user