how to define enum field?

41 views
Skip to first unread message

ken cao

unread,
Nov 12, 2019, 1:19:12 AM11/12/19
to Protocol Buffers
The Style Guide(https://developers.google.com/protocol-buffers/docs/style) suggest that "The zero value enum should have the suffix UNSPECIFIED."

I followed this guide, build a proto, generated a client_type.pb.h in c++ language.

like this:
enum ClientType : int {
  CLIENT_TYPE_UNSPECIFIED = 0,
  CLIENT_TYPE_PHONE = 3,
  CLIENT_TYPE_PAD = 6,
  CLIENT_TYPE_PC = 9,
  CLIENT_TYPE_LANDLINE = 12,
  ClientType_INT_MIN_SENTINEL_DO_NOT_USE_ = std::numeric_limits<::PROTOBUF_NAMESPACE_ID::int32>::min(),
  ClientType_INT_MAX_SENTINEL_DO_NOT_USE_ = std::numeric_limits<::PROTOBUF_NAMESPACE_ID::int32>::max()
};
bool ClientType_IsValid(int value);
constexpr ClientType ClientType_MIN = CLIENT_TYPE_UNSPECIFIED;
constexpr ClientType ClientType_MAX = CLIENT_TYPE_LANDLINE;
constexpr int ClientType_ARRAYSIZE = ClientType_MAX + 1;

But I can't use ClientType_IsValid to check this enum is valid I geted or not.
Because CLIENT_TYPE_UNSPECIFIED is not valid.

Thankyou very much!
Reply all
Reply to author
Forward
0 new messages