Skip to content

Commit d5dab28

Browse files
authored
Merge pull request #3241 from cho-m/protobuf-34
Support building with Protobuf v34+
2 parents a103b4b + 09b50d2 commit d5dab28

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

src/brpc/nonreflectable_message.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,20 @@ class NonreflectableMessage : public ::google::protobuf::Message {
223223
struct NonreflectableMessageClassData : ClassDataFull {
224224
constexpr NonreflectableMessageClassData()
225225
: ClassDataFull(
226-
# if GOOGLE_PROTOBUF_VERSION >= 5029000
226+
# if GOOGLE_PROTOBUF_VERSION >= 7034000
227+
ClassData{
228+
&_instance, // prototype
229+
nullptr, // tc_table
230+
nullptr, // is_initialized
231+
nullptr, // merge_to_from
232+
::google::protobuf::internal::MessageCreator(), // message_creator
233+
0, // cached_size_offset
234+
false, // is_lite
235+
},
236+
nullptr, // descriptor_methods
237+
nullptr, // descriptor_table
238+
nullptr // get_metadata_tracker
239+
# elif GOOGLE_PROTOBUF_VERSION >= 5029000
227240
ClassData{
228241
&_instance, // prototype
229242
nullptr, // tc_table

src/json2pb/json_to_pb.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ static void string_append_value(const BUTIL_RAPIDJSON_NAMESPACE::Value& value,
119119
//otherwise will append error into error message and return false.
120120
inline bool value_invalid(const google::protobuf::FieldDescriptor* field, const char* type,
121121
const BUTIL_RAPIDJSON_NAMESPACE::Value& value, std::string* err) {
122-
bool optional = field->is_optional();
122+
bool optional = !field->is_required() && !field->is_repeated();
123123
if (err) {
124124
if (!err->empty()) {
125125
err->append(", ");

src/mcpack2pb/generator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ static bool generate_parsing(const google::protobuf::Descriptor* d,
482482
} break;
483483
} // switch
484484
} else {
485-
if (f->is_optional()) {
485+
if (!f->is_required() && !f->is_repeated()) {
486486
impl.Print("// optional $type$ $name$ = $number$;\n"
487487
, "type", field_to_string(f)
488488
, "name", f->name()
@@ -888,12 +888,12 @@ static bool generate_serializing(const google::protobuf::Descriptor* d,
888888
butil::string_printf(&comment_template,
889889
"// %s $type$ $name$ = $number$;\n",
890890
(f->is_repeated() ? "repeated" :
891-
(f->is_optional() ? "optional" : "required")));
891+
(f->is_required() ? "required" : "optional")));
892892
} else {
893893
butil::string_printf(&comment_template,
894894
"// %s $type$ $name$ = $number$ [(idl_type)=%s];\n",
895895
(f->is_repeated() ? "repeated" :
896-
(f->is_optional() ? "optional" : "required")),
896+
(f->is_required() ? "required" : "optional")),
897897
describe_idl_type(cit));
898898
}
899899
impl.Print(comment_template.c_str()

0 commit comments

Comments
 (0)