55 Commits

Author SHA1 Message Date
Petteri Aimonen
7713d43bc3 Implement support for oneofs (C unions).
Basic test included, should probably add an oneof to the AllTypes test also.

Update issue 131
Status: Started
2015-01-04 19:39:37 +02:00
Petteri Aimonen
50c67ecec4 Add int_size option for generator.
This allows overriding the integer field types to e.g. uint8_t for
saving RAM.

Update issue 139
Status: FixedInGit
2015-01-04 12:02:15 +02:00
Petteri Aimonen
418f7d88b3 Add support for POINTER type in extensions 2014-12-26 18:23:36 +02:00
Petteri Aimonen
62b4a8ecaa Rename UNUSED() and STATIC_ASSERT() macros with PB_ prefix.
This avoids possible namespace conflicts with other macros.
2014-08-18 20:49:48 +03:00
Petteri Aimonen
1dd9f1900f Change the _count fields to use pb_size_t datatype.
Update issue 82
Status: FixedInGit
2014-08-18 20:09:52 +03:00
Petteri Aimonen
7edf250a62 Switch pb_encode to use the common iterator logic in pb_common.c
Update issue 128
Status: FixedInGit
2014-08-10 13:01:09 +03:00
Petteri Aimonen
b63e582bdb Add a convenience function pb_get_encoded_size()
There is minimal size penalty from this, and it is probably much more
intuitive to use than PB_OSTREAM_SIZING itself.

This has been suggested before also, but I ended up refusing it back
them. Reconsidering it now, I see that an intuitive API is much better
than any amount of documentation explaining a non-intuitive API.

Update issue 16
Status: FixedInGit
2014-04-05 11:26:39 +03:00
Petteri Aimonen
70dee34da6 Add some missing 'static' specifiers
Update issue 91
Status: FixedInGit
2014-04-02 21:08:15 +03:00
Petteri Aimonen
99434724d0 Fix splint warnings, add splint test case 2014-04-02 21:07:30 +03:00
Petteri Aimonen
9be2cfe968 Get rid of pb_bytes_ptr_t, just allocate pb_bytes_array_t dynamically.
This makes the internal logic much simpler, and also keeps the datatypes
more similar between STATIC/POINTER cases. It will still be a bit cumbersome
to use because of variable length array member. Macros PB_BYTES_ARRAY_T(n) and
PB_BYTES_ARRAY_T_ALLOCSIZE(n) have been added to make life a bit easier.

This has the drawback that it is no longer as easy to use externally allocated
byte array as input for bytes field in pointer mode. However, this is still
easy to do using callbacks, so it shouldn't be a large issue.
2014-03-15 08:45:58 +02:00
Petteri Aimonen
bc4ded3b43 Fix missing error messages in pb_encode.c 2013-12-29 18:35:57 +02:00
Petteri Aimonen
ef07635e35 Rename encode_static_field -> encode_basic_field. 2013-12-29 18:35:57 +02:00
Petteri Aimonen
25516b0591 Organize allocation logic in generator, add pb_bytes_ptr_t.
Allocation decision is now made before the field data type is decided.
This way the data type decisions can more cleanly account for the allocation
type, i.e. FT_DEFAULT logic etc.

Added pb_bytes_ptr_t for pointer-allocated bytes-fields. There is no point
generating separate structs for these, as they would all be of the same type.
2013-12-29 18:35:57 +02:00
Petteri Aimonen
414e637867 Const-correctness and small cleanup. 2013-12-29 18:35:57 +02:00
Martin Donath
4ae3b2e566 Generating and encoding messages with dynamic allocaiton 2013-12-29 18:35:57 +02:00
Petteri Aimonen
ee5b12c537 Add PB_LTYPE_UVARINT to fix encoding of negative int32 values.
Apparently int32 values that are negative must be cast into int64 first
before being encoded. Because uint32 still needs to be cast to uint64,
the cases for int32 and uint32 had to be separated.

Update issue 97
Status: FixedInGit
2013-12-21 12:16:03 +02:00
Petteri Aimonen
287207841d Remove the NANOPB_INTERNALS functions from public API.
These have been deprecated since nanopb-0.1.6 (some since 0.1.3).
Equivalent functions with better interface are available in the API.

Update issue 91
Status: FixedInGit
2013-10-29 16:32:47 +02:00
Petteri Aimonen
0074deba9a Declare static functions before use.
For compliance with MISRA C rules (issue 91).
2013-10-29 16:24:50 +02:00
Petteri Aimonen
4d69cc2f3e Cleanup of comments. 2013-10-29 16:19:07 +02:00
Petteri Aimonen
cd3af3272d Rename some internal functions to have unique names 2013-10-29 15:32:51 +02:00
Petteri Aimonen
ed564186e1 Detect invalid sizes when encoding bytes fields. 2013-10-24 21:45:39 +03:00
Petteri Aimonen
e83fbd18d3 Check array max size when encoding.
Update issue 90
Status: FixedInGit
2013-10-20 21:42:00 +03:00
Petteri Aimonen
1f13e8cd2c Fix bugs in extension support when multiple extension fields are present. 2013-07-22 18:59:15 +03:00
Petteri Aimonen
64947cb382 Extension support implemented for decoder.
Testing is still needed. Also only 'optional' extension fields
are supported now, 'repeated' fields are not yet supported.
2013-07-17 20:21:51 +03:00
Petteri Aimonen
ebddda9b5c Implement extension support for the encoder 2013-07-17 19:23:19 +03:00
Petteri Aimonen
bb985e9927 Add pb_decode_delimited and pb_encode_delimited wrapper functions.
Update issue 74
Status: FixedInGit
2013-07-06 16:16:00 +03:00
Petteri Aimonen
d2063ff0b6 Handle unterminated strings when encoding.
If the null terminator is not present, string will be limited to the
data size of the field.

If you are still using the pb_enc_string (deprecated since 0.1.3) from
callbacks, now would be an excellent time to stop. The pb_field_t for
the callback will not contain proper data_size. Use pb_encode_string()
instead.

Update issue 68
Status: FixedInGit
2013-04-14 09:46:39 +03:00
Petteri Aimonen
214b0eae8a Change the callback function to use void**.
NOTE: This change breaks backwards-compatibility by default.
If you have old callback functions, you can define PB_OLD_CALLBACK_STYLE
to retain the old behaviour.

If you want to convert your old callbacks to new signature, you need
to do the following:

1) Change decode callback argument to   void **arg
      and encode callback argument to   void * const *arg.

2) Change any reference to arg into *arg.

The rationale for making the new behaviour the default is that it
simplifies the common case of "allocate some memory in decode callback".

Update issue 69
Status: FixedInGit
2013-04-02 19:55:21 +03:00
Petteri Aimonen
03e5393072 Add PB_SYSTEM_HEADER compile time option.
This allows replacing the C99 standard include file names with
a single system-specific file. It should provide all the necessary
system functions (typedefs, memset, memcpy, strlen).

Update issue 62
Status: FixedInGit
2013-03-09 14:56:34 +02:00
Petteri Aimonen
0352647118 Implement error message support for the encoder side.
Update issue 7
Status: FixedInGit
2013-03-09 14:49:15 +02:00
Petteri Aimonen
41f98343c8 Separate PB_HTYPE to PB_ATYPE and PB_HTYPE.
Also clean up the logic so that it is easier to implement more
allocation types in the future.

Update issue 53
Status: FixedInGit
2013-02-20 22:55:59 +02:00
Petteri Aimonen
69085d9387 Rename PB_HTYPE_ARRAY -> PB_HTYPE_REPEATED.
This is a more logical name in parallel with PB_HTYPE_REQUIRED and PB_HTYPE_OPTIONAL.

Warning: This breaks backwards-compatibility of generated .pb.c files.
You will have to regenerate the files and recompile.
2013-02-20 21:58:18 +02:00
Petteri Aimonen
4ba6a3027d Add compile-time option PB_BUFFER_ONLY.
This allows slight optimizations if only memory buffer support
(as opposed to stream callbacks) is wanted. On ARM difference
is -12% execution time, -4% code size when enabled.
2013-02-06 20:54:25 +02:00
Petteri Aimonen
c372ebc665 Performance improvement: replace memcpy with loop.
In the pb_istream_from_buffer and pb_ostream_from_buffer, memcpy was
used to transfer values to the buffer. For the common case of
count = 1-10 bytes, a simple loop is faster.
2013-02-05 22:06:36 +02:00
Petteri Aimonen
b214de4e1e Enable -Wconversion for core and fix the warnings.
This should help avoid issue 33 in the future.
2012-09-03 17:35:14 +03:00
Petteri Aimonen
07d44cf632 Clean up one (uint64_t) cast. 2012-09-02 20:14:22 +03:00
Petteri Aimonen
a06dba6e49 Fix warnings with -Wcast-qual. Add test for C++ compile.
Update issue 27
Status: FixedInGit
2012-08-26 15:21:20 +03:00
Petteri Aimonen
8d5086f052 Declare warn_unused_result only on GCC >= 3.4.0.
Thanks to cea.max.simoes for bug report & fix.

Update issue 25
Status: FixedInGit
2012-08-09 16:15:23 +03:00
Petteri Aimonen
10b5da12dc Fixed a few compiler warnings, added check.
Main code is now compiled (for tests) with -pedantic -Wextra.
The test programs are not as strictly bound, but this should
improve the chances that atleast the core library compiles with
most compilers without warnings.
2012-07-18 21:09:13 +03:00
Petteri Aimonen
01a1556898 Apparently some compilers don't want to automatically cast size_t to uint64_t. 2012-07-05 18:27:07 +03:00
Petteri Aimonen
efef38cf78 Fix some typos in __BIG_ENDIAN__ code 2012-07-05 18:24:11 +03:00
Petteri Aimonen
7e1059628c Fix non-constant initializer errors with some compilers.
Fixes issue #13. Thanks to Kevin Worth for reporting.
2012-06-13 21:43:40 +03:00
Petteri Aimonen
d1ca88d20e Fixing compiler warnings, mostly related to unused parameters.
Thanks to David Hotham for the patch. Fixes issue 8.
2012-04-18 20:15:36 +03:00
Petteri Aimonen
9fbe9a5de3 Refactoring the field encoder interface.
Replaced the confusing pb_enc_* functions with new pb_encode_* functions that
have a cleaner interface. Updated documentation.

Got rid of the endian_copy stuff in pb_encode.c, instead using C casts to do it automatically.
This makes the code safer and also reduces binary size by about 5%.

Fixes Issue 6.
2012-03-01 13:46:52 +02:00
Petteri Aimonen
1506450b11 Fixed a bug related to submessage encoding into memory buffer.
Stream state was not copied back from substream in pb_enc_submessage,
which caused garbage output if the stream callback modified the state.

Expanded tests to cover this problem.

Thanks to Paweł Pery for debugging and reporting this problem.


git-svn-id: https://svn.kapsi.fi/jpa/nanopb@1089 e3a754e5-d11d-0410-8d38-ebb782a927b9
2011-12-30 08:43:50 +00:00
Petteri Aimonen
13b6988b64 Fix some compiler warnings in strict C89 mode
Contributed by Michael Poole.


git-svn-id: https://svn.kapsi.fi/jpa/nanopb@1004 e3a754e5-d11d-0410-8d38-ebb782a927b9
2011-11-10 16:19:55 +00:00
Petteri Aimonen
fcfc99f766 Fixed a bunch of bugs related to callback fields.
Most importantly, callback fields in submessages were being overwritten with garbage, causing segfaults.

Additionally, converted PB_LTYPE_FIXED to PB_LTYPE_FIXED32 and PB_LTYPE_FIXED64. This makes the interface
a bit easier to use, and in addition runs faster.


git-svn-id: https://svn.kapsi.fi/jpa/nanopb@975 e3a754e5-d11d-0410-8d38-ebb782a927b9
2011-09-13 16:14:08 +00:00
Petteri Aimonen
a353417021 More unittests
git-svn-id: https://svn.kapsi.fi/jpa/nanopb@966 e3a754e5-d11d-0410-8d38-ebb782a927b9
2011-08-23 18:50:09 +00:00
Petteri Aimonen
64ac18c884 Changed autogenerated file naming from foo.c to foo.pb.c
git-svn-id: https://svn.kapsi.fi/jpa/nanopb@965 e3a754e5-d11d-0410-8d38-ebb782a927b9
2011-08-23 16:16:33 +00:00
Petteri Aimonen
8b635924ba check return values
git-svn-id: https://svn.kapsi.fi/jpa/nanopb@961 e3a754e5-d11d-0410-8d38-ebb782a927b9
2011-08-23 13:33:43 +00:00