Adding another enum and field usage just to see what it looks like

This commit is contained in:
Dan Buch
2012-05-07 22:31:40 -04:00
parent af3b05be3d
commit 438aa1db17
5 changed files with 374 additions and 56 deletions

View File

@@ -27,6 +27,7 @@ const ::google::protobuf::EnumDescriptor* Person_PhoneType_descriptor_ = NULL;
const ::google::protobuf::Descriptor* AddressBook_descriptor_ = NULL;
const ::google::protobuf::internal::GeneratedMessageReflection*
AddressBook_reflection_ = NULL;
const ::google::protobuf::EnumDescriptor* Gender_descriptor_ = NULL;
} // namespace
@@ -38,10 +39,11 @@ void protobuf_AssignDesc_addressbook_2eproto() {
"addressbook.proto");
GOOGLE_CHECK(file != NULL);
Person_descriptor_ = file->message_type(0);
static const int Person_offsets_[4] = {
static const int Person_offsets_[5] = {
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Person, name_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Person, id_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Person, email_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Person, type_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Person, phone_),
};
Person_reflection_ =
@@ -87,6 +89,7 @@ void protobuf_AssignDesc_addressbook_2eproto() {
::google::protobuf::DescriptorPool::generated_pool(),
::google::protobuf::MessageFactory::generated_factory(),
sizeof(AddressBook));
Gender_descriptor_ = file->enum_type(0);
}
namespace {
@@ -125,14 +128,16 @@ void protobuf_AddDesc_addressbook_2eproto() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
"\n\021addressbook.proto\022\010tutorial\"\332\001\n\006Person"
"\n\021addressbook.proto\022\010tutorial\"\200\002\n\006Person"
"\022\014\n\004name\030\001 \002(\t\022\n\n\002id\030\002 \002(\005\022\r\n\005email\030\003 \001("
"\t\022+\n\005phone\030\004 \003(\0132\034.tutorial.Person.Phone"
"Number\032M\n\013PhoneNumber\022\016\n\006number\030\001 \002(\t\022.\n"
"\004type\030\002 \001(\0162\032.tutorial.Person.PhoneType:"
"\004HOME\"+\n\tPhoneType\022\n\n\006MOBILE\020\000\022\010\n\004HOME\020\001"
"\022\010\n\004WORK\020\002\"/\n\013AddressBook\022 \n\006person\030\001 \003("
"\0132\020.tutorial.Person", 299);
"\t\022$\n\004type\030\004 \001(\0162\020.tutorial.Gender:\004NONE\022"
"+\n\005phone\030\005 \003(\0132\034.tutorial.Person.PhoneNu"
"mber\032M\n\013PhoneNumber\022\016\n\006number\030\001 \002(\t\022.\n\004t"
"ype\030\002 \001(\0162\032.tutorial.Person.PhoneType:\004H"
"OME\"+\n\tPhoneType\022\n\n\006MOBILE\020\000\022\010\n\004HOME\020\001\022\010"
"\n\004WORK\020\002\"/\n\013AddressBook\022 \n\006person\030\001 \003(\0132"
"\020.tutorial.Person*3\n\006Gender\022\010\n\004NONE\020\000\022\010\n"
"\004MALE\020\001\022\n\n\006FEMALE\020\002\022\t\n\005OTHER\020\003", 390);
::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
"addressbook.proto", &protobuf_RegisterTypes);
Person::default_instance_ = new Person();
@@ -151,6 +156,22 @@ struct StaticDescriptorInitializer_addressbook_2eproto {
}
} static_descriptor_initializer_addressbook_2eproto_;
const ::google::protobuf::EnumDescriptor* Gender_descriptor() {
protobuf_AssignDescriptorsOnce();
return Gender_descriptor_;
}
bool Gender_IsValid(int value) {
switch(value) {
case 0:
case 1:
case 2:
case 3:
return true;
default:
return false;
}
}
// ===================================================================
@@ -452,6 +473,7 @@ void Person_PhoneNumber::Swap(Person_PhoneNumber* other) {
const int Person::kNameFieldNumber;
const int Person::kIdFieldNumber;
const int Person::kEmailFieldNumber;
const int Person::kTypeFieldNumber;
const int Person::kPhoneFieldNumber;
#endif // !_MSC_VER
@@ -474,6 +496,7 @@ void Person::SharedCtor() {
name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
id_ = 0;
email_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
type_ = 0;
::memset(_has_bits_, 0, sizeof(_has_bits_));
}
@@ -525,6 +548,7 @@ void Person::Clear() {
email_->clear();
}
}
type_ = 0;
}
phone_.Clear();
::memset(_has_bits_, 0, sizeof(_has_bits_));
@@ -582,12 +606,33 @@ bool Person::MergePartialFromCodedStream(
} else {
goto handle_uninterpreted;
}
if (input->ExpectTag(34)) goto parse_phone;
if (input->ExpectTag(32)) goto parse_type;
break;
}
// repeated .tutorial.Person.PhoneNumber phone = 4;
// optional .tutorial.Gender type = 4 [default = NONE];
case 4: {
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_VARINT) {
parse_type:
int value;
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>(
input, &value)));
if (tutorial::Gender_IsValid(value)) {
set_type(static_cast< tutorial::Gender >(value));
} else {
mutable_unknown_fields()->AddVarint(4, value);
}
} else {
goto handle_uninterpreted;
}
if (input->ExpectTag(42)) goto parse_phone;
break;
}
// repeated .tutorial.Person.PhoneNumber phone = 5;
case 5: {
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) {
parse_phone:
@@ -596,7 +641,7 @@ bool Person::MergePartialFromCodedStream(
} else {
goto handle_uninterpreted;
}
if (input->ExpectTag(34)) goto parse_phone;
if (input->ExpectTag(42)) goto parse_phone;
if (input->ExpectAtEnd()) return true;
break;
}
@@ -642,10 +687,16 @@ void Person::SerializeWithCachedSizes(
3, this->email(), output);
}
// repeated .tutorial.Person.PhoneNumber phone = 4;
// optional .tutorial.Gender type = 4 [default = NONE];
if (has_type()) {
::google::protobuf::internal::WireFormatLite::WriteEnum(
4, this->type(), output);
}
// repeated .tutorial.Person.PhoneNumber phone = 5;
for (int i = 0; i < this->phone_size(); i++) {
::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray(
4, this->phone(i), output);
5, this->phone(i), output);
}
if (!unknown_fields().empty()) {
@@ -681,11 +732,17 @@ void Person::SerializeWithCachedSizes(
3, this->email(), target);
}
// repeated .tutorial.Person.PhoneNumber phone = 4;
// optional .tutorial.Gender type = 4 [default = NONE];
if (has_type()) {
target = ::google::protobuf::internal::WireFormatLite::WriteEnumToArray(
4, this->type(), target);
}
// repeated .tutorial.Person.PhoneNumber phone = 5;
for (int i = 0; i < this->phone_size(); i++) {
target = ::google::protobuf::internal::WireFormatLite::
WriteMessageNoVirtualToArray(
4, this->phone(i), target);
5, this->phone(i), target);
}
if (!unknown_fields().empty()) {
@@ -720,8 +777,14 @@ int Person::ByteSize() const {
this->email());
}
// optional .tutorial.Gender type = 4 [default = NONE];
if (has_type()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::EnumSize(this->type());
}
}
// repeated .tutorial.Person.PhoneNumber phone = 4;
// repeated .tutorial.Person.PhoneNumber phone = 5;
total_size += 1 * this->phone_size();
for (int i = 0; i < this->phone_size(); i++) {
total_size +=
@@ -765,6 +828,9 @@ void Person::MergeFrom(const Person& from) {
if (from.has_email()) {
set_email(from.email());
}
if (from.has_type()) {
set_type(from.type());
}
}
mutable_unknown_fields()->MergeFrom(from.unknown_fields());
}
@@ -795,6 +861,7 @@ void Person::Swap(Person* other) {
std::swap(name_, other->name_);
std::swap(id_, other->id_);
std::swap(email_, other->email_);
std::swap(type_, other->type_);
phone_.Swap(&other->phone_);
std::swap(_has_bits_[0], other->_has_bits_[0]);
_unknown_fields_.Swap(&other->_unknown_fields_);

View File

@@ -56,6 +56,27 @@ inline bool Person_PhoneType_Parse(
return ::google::protobuf::internal::ParseNamedEnum<Person_PhoneType>(
Person_PhoneType_descriptor(), name, value);
}
enum Gender {
NONE = 0,
MALE = 1,
FEMALE = 2,
OTHER = 3
};
bool Gender_IsValid(int value);
const Gender Gender_MIN = NONE;
const Gender Gender_MAX = OTHER;
const int Gender_ARRAYSIZE = Gender_MAX + 1;
const ::google::protobuf::EnumDescriptor* Gender_descriptor();
inline const ::std::string& Gender_Name(Gender value) {
return ::google::protobuf::internal::NameOfEnum(
Gender_descriptor(), value);
}
inline bool Gender_Parse(
const ::std::string& name, Gender* value) {
return ::google::protobuf::internal::ParseNamedEnum<Gender>(
Gender_descriptor(), name, value);
}
// ===================================================================
class Person_PhoneNumber : public ::google::protobuf::Message {
@@ -264,10 +285,17 @@ class Person : public ::google::protobuf::Message {
inline ::std::string* mutable_email();
inline ::std::string* release_email();
// repeated .tutorial.Person.PhoneNumber phone = 4;
// optional .tutorial.Gender type = 4 [default = NONE];
inline bool has_type() const;
inline void clear_type();
static const int kTypeFieldNumber = 4;
inline tutorial::Gender type() const;
inline void set_type(tutorial::Gender value);
// repeated .tutorial.Person.PhoneNumber phone = 5;
inline int phone_size() const;
inline void clear_phone();
static const int kPhoneFieldNumber = 4;
static const int kPhoneFieldNumber = 5;
inline const ::tutorial::Person_PhoneNumber& phone(int index) const;
inline ::tutorial::Person_PhoneNumber* mutable_phone(int index);
inline ::tutorial::Person_PhoneNumber* add_phone();
@@ -284,16 +312,19 @@ class Person : public ::google::protobuf::Message {
inline void clear_has_id();
inline void set_has_email();
inline void clear_has_email();
inline void set_has_type();
inline void clear_has_type();
::google::protobuf::UnknownFieldSet _unknown_fields_;
::std::string* name_;
::std::string* email_;
::google::protobuf::RepeatedPtrField< ::tutorial::Person_PhoneNumber > phone_;
::google::protobuf::int32 id_;
int type_;
::google::protobuf::RepeatedPtrField< ::tutorial::Person_PhoneNumber > phone_;
mutable int _cached_size_;
::google::protobuf::uint32 _has_bits_[(4 + 31) / 32];
::google::protobuf::uint32 _has_bits_[(5 + 31) / 32];
friend void protobuf_AddDesc_addressbook_2eproto();
friend void protobuf_AssignDesc_addressbook_2eproto();
@@ -617,7 +648,30 @@ inline ::std::string* Person::release_email() {
}
}
// repeated .tutorial.Person.PhoneNumber phone = 4;
// optional .tutorial.Gender type = 4 [default = NONE];
inline bool Person::has_type() const {
return (_has_bits_[0] & 0x00000008u) != 0;
}
inline void Person::set_has_type() {
_has_bits_[0] |= 0x00000008u;
}
inline void Person::clear_has_type() {
_has_bits_[0] &= ~0x00000008u;
}
inline void Person::clear_type() {
type_ = 0;
clear_has_type();
}
inline tutorial::Gender Person::type() const {
return static_cast< tutorial::Gender >(type_);
}
inline void Person::set_type(tutorial::Gender value) {
GOOGLE_DCHECK(tutorial::Gender_IsValid(value));
set_has_type();
type_ = value;
}
// repeated .tutorial.Person.PhoneNumber phone = 5;
inline int Person::phone_size() const {
return phone_.size();
}
@@ -684,6 +738,10 @@ template <>
inline const EnumDescriptor* GetEnumDescriptor< ::tutorial::Person_PhoneType>() {
return ::tutorial::Person_PhoneType_descriptor();
}
template <>
inline const EnumDescriptor* GetEnumDescriptor< tutorial::Gender>() {
return tutorial::Gender_descriptor();
}
} // namespace google
} // namespace protobuf