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