summaryrefslogtreecommitdiffstats
path: root/pb_encode.c
AgeCommit message (Collapse)AuthorFilesLines
2016-12-09Enable clang integer sanitizer and clean up a few warnings.Petteri Aimonen1-2/+3
Changed to use simple indexing instead of while (count--) in buf_read()/buf_write(), because the count overflowed from 0 to max on the last iteration. While the unsigned integer overflow is defined and behaviour was correct, making this simple change allowed enabling the sanitizer which might catch true errors elsewhere in the code.
2016-12-09Refactor proto3 logic into pb_check_proto3_default_value()Petteri Aimonen1-26/+55
Mainly to clean up the code. Also fixed handling of PB_LTYPE_FIXED_LENGTH_BYTES for proto3 files.
2016-12-09Fix potential unaligned accessGuillaume Lager1-5/+9
If the type is string, do not try to deference it as int16, int32 or int64. This may lead to unalign memory access, which may cause trap on some architectures (ARM)
2016-10-10Fix typo in encodingberni1551-1/+4
2016-10-09Prevent fields with default value from encoding when proto3 option is setBernhard Krämer1-0/+17
2016-08-04Add inline allocation of bytes fieldsTom Roeder1-4/+11
This commit adds a new FT_INLINE allocation type that forces bytes fields to be inlined into the struct. E.g., pb_byte_t my_bytes[32]. This requires max_size for the bytes field. The FT_INLINE type is represented as a new LTYPE: FT_LTYPE_FIXED_LENGTH_BYTES. This commit also updates the documentation with FT_INLINE and FT_LTYPE_FIXED_LENGTH_BYTES. Added an AUTHORS file in apparent order of appearance in the git log history from $(git log --all).
2016-01-27Fix a few remaining bugs related to CHAR_BIT!=8 platforms.Petteri Aimonen1-26/+30
2016-01-27Replace uint8_t with a pb_byte_t typedef.Petteri Aimonen1-31/+34
This supports platforms where uint8_t does not exist. If you are using a custom pb_syshdr.h, this may require adding definitions for uint_least8_t etc.
2016-01-26Get rid of type punning in pb_encode_fixedXX().Petteri Aimonen1-26/+18
This was never very clean code, but it was fast. Hopefully compilers are smart enough to optimize it away, or the speed difference is not very large. This should be checked. However working code is always more important than fast code, and the previous way couldn't really work for platforms that do not have byte-sized memory access. Related to PR #191.
2015-01-04Implement support for oneofs (C unions).Petteri Aimonen1-0/+11
Basic test included, should probably add an oneof to the AllTypes test also. Update issue 131 Status: Started
2015-01-04Add int_size option for generator.Petteri Aimonen1-1/+5
This allows overriding the integer field types to e.g. uint8_t for saving RAM. Update issue 139 Status: FixedInGit
2014-12-26Add support for POINTER type in extensionsPetteri Aimonen1-1/+12
2014-08-18Rename UNUSED() and STATIC_ASSERT() macros with PB_ prefix.Petteri Aimonen1-3/+3
This avoids possible namespace conflicts with other macros.
2014-08-18Change the _count fields to use pb_size_t datatype.Petteri Aimonen1-2/+2
Update issue 82 Status: FixedInGit
2014-08-10Switch pb_encode to use the common iterator logic in pb_common.cPetteri Aimonen1-24/+21
Update issue 128 Status: FixedInGit
2014-04-05Add a convenience function pb_get_encoded_size()Petteri Aimonen1-0/+11
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-02Add some missing 'static' specifiersPetteri Aimonen1-9/+8
Update issue 91 Status: FixedInGit
2014-04-02Fix splint warnings, add splint test casePetteri Aimonen1-3/+3
2014-03-15Get rid of pb_bytes_ptr_t, just allocate pb_bytes_array_t dynamically.Petteri Aimonen1-16/+26
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.
2013-12-29Fix missing error messages in pb_encode.cPetteri Aimonen1-1/+6
2013-12-29Rename encode_static_field -> encode_basic_field.Petteri Aimonen1-4/+4
2013-12-29Organize allocation logic in generator, add pb_bytes_ptr_t.Petteri Aimonen1-3/+3
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-29Const-correctness and small cleanup.Petteri Aimonen1-21/+25
2013-12-29Generating and encoding messages with dynamic allocaitonMartin Donath1-14/+53
2013-12-21Add PB_LTYPE_UVARINT to fix encoding of negative int32 values.Petteri Aimonen1-2/+21
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-10-29Remove the NANOPB_INTERNALS functions from public API.Petteri Aimonen1-1/+7
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-29Declare static functions before use.Petteri Aimonen1-1/+12
For compliance with MISRA C rules (issue 91).
2013-10-29Cleanup of comments.Petteri Aimonen1-8/+19
2013-10-29Rename some internal functions to have unique namesPetteri Aimonen1-2/+2
2013-10-24Detect invalid sizes when encoding bytes fields.Petteri Aimonen1-1/+4
2013-10-20Check array max size when encoding.Petteri Aimonen1-0/+3
Update issue 90 Status: FixedInGit
2013-07-22Fix bugs in extension support when multiple extension fields are present.Petteri Aimonen1-1/+6
2013-07-17Extension support implemented for decoder.Petteri Aimonen1-1/+2
Testing is still needed. Also only 'optional' extension fields are supported now, 'repeated' fields are not yet supported.
2013-07-17Implement extension support for the encoderPetteri Aimonen1-21/+73
2013-07-06Add pb_decode_delimited and pb_encode_delimited wrapper functions.Petteri Aimonen1-0/+5
Update issue 74 Status: FixedInGit
2013-04-14Handle unterminated strings when encoding.Petteri Aimonen1-2/+10
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-02Change the callback function to use void**.Petteri Aimonen1-1/+8
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-03-09Add PB_SYSTEM_HEADER compile time option.Petteri Aimonen1-1/+0
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-09Implement error message support for the encoder side.Petteri Aimonen1-14/+23
Update issue 7 Status: FixedInGit
2013-02-20Separate PB_HTYPE to PB_ATYPE and PB_HTYPE.Petteri Aimonen1-33/+64
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-20Rename PB_HTYPE_ARRAY -> PB_HTYPE_REPEATED.Petteri Aimonen1-2/+2
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-06Add compile-time option PB_BUFFER_ONLY.Petteri Aimonen1-1/+10
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-05Performance improvement: replace memcpy with loop.Petteri Aimonen1-1/+4
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.
2012-09-03Enable -Wconversion for core and fix the warnings.Petteri Aimonen1-5/+5
This should help avoid issue 33 in the future.
2012-09-02Clean up one (uint64_t) cast.Petteri Aimonen1-2/+2
2012-08-26Fix warnings with -Wcast-qual. Add test for C++ compile.Petteri Aimonen1-14/+14
Update issue 27 Status: FixedInGit
2012-08-09Declare warn_unused_result only on GCC >= 3.4.0.Petteri Aimonen1-5/+5
Thanks to cea.max.simoes for bug report & fix. Update issue 25 Status: FixedInGit
2012-07-18Fixed a few compiler warnings, added check.Petteri Aimonen1-2/+2
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-05Apparently some compilers don't want to automatically cast size_t to uint64_t.Petteri Aimonen1-4/+4
2012-07-05Fix some typos in __BIG_ENDIAN__ codePetteri Aimonen1-2/+2