1===================================== 2Nanopb: Migration from older versions 3===================================== 4 5.. include :: menu.rst 6 7This document details all the breaking changes that have been made to nanopb 8since its initial release. For each change, the rationale and required 9modifications of user applications are explained. Also any error indications 10are included, in order to make it easier to find this document. 11 12.. contents :: 13 14Nanopb-0.3.9.4, 0.4.0 (2019-xx-xx) 15================================== 16 17Fix generation of min/max defines for enum types 18------------------------------------------------ 19 20**Rationale:** Nanopb generator makes #defines for enum minimum and maximum 21value. Previously these defines incorrectly had the first and last enum value, 22instead of the actual minimum and maximum. (issue #405) 23 24**Changes:** Minimum define now always has the smallest value, and maximum 25define always has the largest value. 26 27**Required actions:** If these defines are used and enum values in .proto file 28are not defined in ascending order, user code behaviour may change. Check that 29user code doesn't expect the old, incorrect first/last behaviour. 30 31Fix undefined behavior related to bool fields 32--------------------------------------------- 33 34**Rationale:** In C99, `bool` variables are not allowed to have other values 35than `true` and `false`. Compilers use this fact in optimization, and constructs 36like `int foo = msg.has_field ? 100 : 0` will give unexpected results otherwise. 37Previously nanopb didn't enforce that decoded bool fields had valid values. 38 39**Changes:** Bool fields are now handled separately as `PB_LTYPE_BOOL`. The 40`LTYPE` descriptor numbers for other field types were renumbered. 41 42**Required actions:** Source code files must be recompiled, but regenerating 43`.pb.h`/`.pb.c` files from `.proto` is not required. If user code directly uses 44the nanopb internal field representation (search for `PB_LTYPE_VARINT` in source), 45it may need updating. 46 47Nanopb-0.3.9.1, 0.4.0 (2018-04-14) 48================================== 49 50Fix handling of string and bytes default values 51----------------------------------------------- 52 53**Rationale:** Previously nanopb didn't properly decode special character 54escapes like \\200 emitted by protoc. This caused these escapes to end up 55verbatim in the default values in .pb.c file. 56 57**Changes:** Escapes are now decoded, and e.g. "\\200" or "\\x80" results in 58{0x80} for bytes field and "\\x80" for string field. 59 60**Required actions:** If code has previously relied on '\\' in default value 61being passed through verbatim, it must now be changed to '\\\\'. 62 63Nanopb-0.3.8 (2017-03-05) 64========================= 65 66Fully drain substreams before closing 67------------------------------------- 68 69**Rationale:** If the substream functions were called directly and the caller 70did not completely empty the substring before closing it, the parent stream 71would be put into an incorrect state. 72 73**Changes:** *pb_close_string_substream* can now error and returns a boolean. 74 75**Required actions:** Add error checking onto any call to 76*pb_close_string_substream*. 77 78Change oneof format in .pb.c files 79---------------------------------- 80 81**Rationale:** Previously two oneofs in a single message would be erroneously 82handled as part of the same union. 83 84**Changes:** Oneofs fields now use special *PB_DATAOFFSET_UNION* offset type 85in generated .pb.c files to distinguish whether they are the first or following 86field inside an union. 87 88**Required actions:** Regenerate *.pb.c/.pb.h* files with new nanopb version if 89oneofs are used. 90 91Nanopb-0.3.5 (2016-02-13) 92========================= 93 94Add support for platforms without uint8_t 95----------------------------------------- 96**Rationale:** Some platforms cannot access 8-bit sized values directly, and 97do not define *uint8_t*. Nanopb previously didn't support these platforms. 98 99**Changes:** References to *uint8_t* were replaced with several alternatives, 100one of them being a new *pb_byte_t* typedef. This in turn uses *uint_least8_t* 101which means the smallest available type. 102 103**Required actions:** If your platform does not have a standards-compliant 104*stdint.h*, it may lack the definition for *[u]int_least8_t*. This must be 105added manually, example can be found in *extra/pb_syshdr.h*. 106 107**Error indications:** Compiler error: "unknown type name 'uint_least8_t'". 108 109Nanopb-0.3.2 (2015-01-24) 110========================= 111 112Add support for OneOfs 113---------------------- 114**Rationale:** Previously nanopb did not support the *oneof* construct in 115*.proto* files. Those fields were generated as regular *optional* fields. 116 117**Changes:** OneOfs are now generated as C unions. Callback fields are not 118supported inside oneof and generator gives an error. 119 120**Required actions:** The generator option *no_unions* can be used to restore old 121behaviour and to allow callbacks to be used. To use unions, one change is 122needed: use *which_xxxx* field to detect which field is present, instead 123of *has_xxxx*. Compare the value against *MyStruct_myfield_tag*. 124 125**Error indications:** Generator error: "Callback fields inside of oneof are 126not supported". Compiler error: "Message" has no member named "has_xxxx". 127 128Nanopb-0.3.0 (2014-08-26) 129========================= 130 131Separate field iterator logic to pb_common.c 132-------------------------------------------- 133**Rationale:** Originally, the field iteration logic was simple enough to be 134duplicated in *pb_decode.c* and *pb_encode.c*. New field types have made the 135logic more complex, which required the creation of a new file to contain the 136common functionality. 137 138**Changes:** There is a new file, *pb_common.c*, which must be included in 139builds. 140 141**Required actions:** Add *pb_common.c* to build rules. This file is always 142required. Either *pb_decode.c* or *pb_encode.c* can still be left out if some 143functionality is not needed. 144 145**Error indications:** Linker error: undefined reference to 146*pb_field_iter_begin*, *pb_field_iter_next* or similar. 147 148Change data type of field counts to pb_size_t 149--------------------------------------------- 150**Rationale:** Often nanopb is used with small arrays, such as 255 items or 151less. Using a full *size_t* field to store the array count wastes memory if 152there are many arrays. There already exists parameters *PB_FIELD_16BIT* and 153*PB_FIELD_32BIT* which tell nanopb what is the maximum size of arrays in use. 154 155**Changes:** Generator will now use *pb_size_t* for the array *_count* fields. 156The size of the type will be controlled by the *PB_FIELD_16BIT* and 157*PB_FIELD_32BIT* compilation time options. 158 159**Required actions:** Regenerate all *.pb.h* files. In some cases casts to the 160*pb_size_t* type may need to be added in the user code when accessing the 161*_count* fields. 162 163**Error indications:** Incorrect data at runtime, crashes. But note that other 164changes in the same version already require regenerating the files and have 165better indications of errors, so this is only an issue for development 166versions. 167 168Renamed some macros and identifiers 169----------------------------------- 170**Rationale:** Some names in nanopb core were badly chosen and conflicted with 171ISO C99 reserved names or lacked a prefix. While they haven't caused trouble 172so far, it is reasonable to switch to non-conflicting names as these are rarely 173used from user code. 174 175**Changes:** The following identifier names have changed: 176 177 * Macros: 178 179 * STATIC_ASSERT(x) -> PB_STATIC_ASSERT(x) 180 * UNUSED(x) -> PB_UNUSED(x) 181 182 * Include guards: 183 184 * _PB_filename_ -> PB_filename_INCLUDED 185 186 * Structure forward declaration tags: 187 188 * _pb_field_t -> pb_field_s 189 * _pb_bytes_array_t -> pb_bytes_array_s 190 * _pb_callback_t -> pb_callback_s 191 * _pb_extension_type_t -> pb_extension_type_s 192 * _pb_extension_t -> pb_extension_s 193 * _pb_istream_t -> pb_istream_s 194 * _pb_ostream_t -> pb_ostream_s 195 196**Required actions:** Regenerate all *.pb.c* files. If you use any of the above 197identifiers in your application code, perform search-replace to the new name. 198 199**Error indications:** Compiler errors on lines with the macro/type names. 200 201Nanopb-0.2.9 (2014-08-09) 202========================= 203 204Change semantics of generator -e option 205--------------------------------------- 206**Rationale:** Some compilers do not accept filenames with two dots (like 207in default extension .pb.c). The *-e* option to the generator allowed changing 208the extension, but not skipping the extra dot. 209 210**Changes:** The *-e* option in generator will no longer add the prepending 211dot. The default value has been adjusted accordingly to *.pb.c* to keep the 212default behaviour the same as before. 213 214**Required actions:** Only if using the generator -e option. Add dot before 215the parameter value on the command line. 216 217**Error indications:** File not found when trying to compile generated files. 218 219Nanopb-0.2.7 (2014-04-07) 220========================= 221 222Changed pointer-type bytes field datatype 223----------------------------------------- 224**Rationale:** In the initial pointer encoding support since nanopb-0.2.5, 225the bytes type used a separate *pb_bytes_ptr_t* type to represent *bytes* 226fields. This made it easy to encode data from a separate, user-allocated 227buffer. However, it made the internal logic more complex and was inconsistent 228with the other types. 229 230**Changes:** Dynamically allocated bytes fields now have the *pb_bytes_array_t* 231type, just like statically allocated ones. 232 233**Required actions:** Only if using pointer-type fields with the bytes datatype. 234Change any access to *msg->field.size* to *msg->field->size*. Change any 235allocation to reserve space of amount *PB_BYTES_ARRAY_T_ALLOCSIZE(n)*. If the 236data pointer was begin assigned from external source, implement the field using 237a callback function instead. 238 239**Error indications:** Compiler error: unknown type name *pb_bytes_ptr_t*. 240 241Nanopb-0.2.4 (2013-11-07) 242========================= 243 244Remove the NANOPB_INTERNALS compilation option 245---------------------------------------------- 246**Rationale:** Having the option in the headers required the functions to 247be non-static, even if the option is not used. This caused errors on some 248static analysis tools. 249 250**Changes:** The *#ifdef* and associated functions were removed from the 251header. 252 253**Required actions:** Only if the *NANOPB_INTERNALS* option was previously 254used. Actions are as listed under nanopb-0.1.3 and nanopb-0.1.6. 255 256**Error indications:** Compiler warning: implicit declaration of function 257*pb_dec_string*, *pb_enc_string*, or similar. 258 259Nanopb-0.2.1 (2013-04-14) 260========================= 261 262Callback function signature 263--------------------------- 264**Rationale:** Previously the auxilary data to field callbacks was passed 265as *void\**. This allowed passing of any data, but made it unnecessarily 266complex to return a pointer from callback. 267 268**Changes:** The callback function parameter was changed to *void\*\**. 269 270**Required actions:** You can continue using the old callback style by 271defining *PB_OLD_CALLBACK_STYLE*. Recommended action is to: 272 273 * Change the callback signatures to contain *void\*\** for decoders and 274 *void \* const \** for encoders. 275 * Change the callback function body to use *\*arg* instead of *arg*. 276 277**Error indications:** Compiler warning: assignment from incompatible 278pointer type, when initializing *funcs.encode* or *funcs.decode*. 279 280Nanopb-0.2.0 (2013-03-02) 281========================= 282 283Reformatted generated .pb.c file using macros 284--------------------------------------------- 285**Rationale:** Previously the generator made a list of C *pb_field_t* 286initializers in the .pb.c file. This led to a need to regenerate all .pb.c 287files after even small changes to the *pb_field_t* definition. 288 289**Changes:** Macros were added to pb.h which allow for cleaner definition 290of the .pb.c contents. By changing the macro definitions, changes to the 291field structure are possible without breaking compatibility with old .pb.c 292files. 293 294**Required actions:** Regenerate all .pb.c files from the .proto sources. 295 296**Error indications:** Compiler warning: implicit declaration of function 297*pb_delta_end*. 298 299Changed pb_type_t definitions 300----------------------------- 301**Rationale:** The *pb_type_t* was previously an enumeration type. This 302caused warnings on some compilers when using bitwise operations to set flags 303inside the values. 304 305**Changes:** The *pb_type_t* was changed to *typedef uint8_t*. The values 306were changed to *#define*. Some value names were changed for consistency. 307 308**Required actions:** Only if you directly access the `pb_field_t` contents 309in your own code, something which is not usually done. Needed changes: 310 311 * Change *PB_HTYPE_ARRAY* to *PB_HTYPE_REPEATED*. 312 * Change *PB_HTYPE_CALLBACK* to *PB_ATYPE()* and *PB_ATYPE_CALLBACK*. 313 314**Error indications:** Compiler error: *PB_HTYPE_ARRAY* or *PB_HTYPE_CALLBACK* 315undeclared. 316 317Nanopb-0.1.6 (2012-09-02) 318========================= 319 320Refactored field decoder interface 321---------------------------------- 322**Rationale:** Similarly to field encoders in nanopb-0.1.3. 323 324**Changes:** New functions with names *pb_decode_\** were added. 325 326**Required actions:** By defining NANOPB_INTERNALS, you can still keep using 327the old functions. Recommended action is to replace any calls with the newer 328*pb_decode_\** equivalents. 329 330**Error indications:** Compiler warning: implicit declaration of function 331*pb_dec_string*, *pb_dec_varint*, *pb_dec_submessage* or similar. 332 333Nanopb-0.1.3 (2012-06-12) 334========================= 335 336Refactored field encoder interface 337---------------------------------- 338**Rationale:** The old *pb_enc_\** functions were designed mostly for the 339internal use by the core. Because they are internally accessed through 340function pointers, their signatures had to be common. This led to a confusing 341interface for external users. 342 343**Changes:** New functions with names *pb_encode_\** were added. These have 344easier to use interfaces. The old functions are now only thin wrappers for 345the new interface. 346 347**Required actions:** By defining NANOPB_INTERNALS, you can still keep using 348the old functions. Recommended action is to replace any calls with the newer 349*pb_encode_\** equivalents. 350 351**Error indications:** Compiler warning: implicit declaration of function 352*pb_enc_string*, *pb_enc_varint, *pb_enc_submessage* or similar. 353 354