mirror of
https://github.com/nanopb/nanopb.git
synced 2026-06-06 20:18:31 +00:00
Unsorted enums in message specifications do not result in correct min/max values per the protobuf spec for cpp code: https://developers.google.com/protocol-buffers/docs/reference/cpp-generated#enum The google cpp compiler uses the min/max _value_ instead of the position of the enum entry in the message spec, so this patch updates nanopb to do the same. Example input: ```protobuf syntax = "proto3"; enum Language { UNKNOWN = 0; ENGLISH_EN_GB = 12; ENGLISH_EN_US = 1; FRENCH_FR_FR = 2; ITALIAN_IT_IT = 3; GERMAN_DE_DE = 4; SPANISH_ES_AR = 13; SPANISH_ES_ES = 5; SPANISH_ES_MX = 14; SWEDISH_SV_SE = 6; DUTCH_NL_NL = 7; KOREAN_KO_KR = 8; JAPANESE_JA_JP = 9; CHINESE_SIMPLIFIED_ZH_CN = 10; CHINESE_TRADITIONAL_ZH_TW = 11; } ``` This would previously result in: ```c #define _Language_MIN Language_UNKNOWN #define _Language_MAX Language_CHINESE_TRADITIONAL_ZH_TW #define _Language_ARRAYSIZE ((Language)(Language_CHINESE_TRADITIONAL_ZH_TW+1)) ``` After this patch, ```c #define _Language_MIN Language_UNKNOWN #define _Language_MAX Language_SPANISH_ES_MX #define _Language_ARRAYSIZE ((Language)(Language_SPANISH_ES_MX+1)) ``` Add a test `enum_minmax` to cover this case.
23 lines
440 B
Protocol Buffer
23 lines
440 B
Protocol Buffer
/* Test out-of-order enum values.
|
|
*/
|
|
|
|
syntax = "proto3";
|
|
|
|
enum Language {
|
|
UNKNOWN = 0;
|
|
ENGLISH_EN_GB = 12;
|
|
ENGLISH_EN_US = 1;
|
|
FRENCH_FR_FR = 2;
|
|
ITALIAN_IT_IT = 3;
|
|
GERMAN_DE_DE = 4;
|
|
SPANISH_ES_AR = 13;
|
|
SPANISH_ES_ES = 5;
|
|
SPANISH_ES_MX = 14;
|
|
SWEDISH_SV_SE = 6;
|
|
DUTCH_NL_NL = 7;
|
|
KOREAN_KO_KR = 8;
|
|
JAPANESE_JA_JP = 9;
|
|
CHINESE_SIMPLIFIED_ZH_CN = 10;
|
|
CHINESE_TRADITIONAL_ZH_TW = 11;
|
|
}
|