From 413c614a942ed60e862565d6f774bac3ad2b0a3e Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Tue, 5 Feb 2019 13:10:44 -0500 Subject: [PATCH 01/17] Document why no enum_extensibility is needed for Swift. (#5680) Document why no enum_extensibility is needed for Swift. --- .../compiler/objectivec/objectivec_enum.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/google/protobuf/compiler/objectivec/objectivec_enum.cc b/src/google/protobuf/compiler/objectivec/objectivec_enum.cc index 3b2ca55368..f1330a58f6 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_enum.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_enum.cc @@ -92,6 +92,20 @@ void EnumGenerator::GenerateHeader(io::Printer* printer) { "\n", "name", name_); + // Swift 5 included SE0192 "Handling Future Enum Cases" + // https://github.com/apple/swift-evolution/blob/master/proposals/0192-non-exhaustive-enums.md + // Since a .proto file can get new values added to an enum at any time, they + // are effectively "non-frozen". Even in a proto3 syntax file where there is + // support for the unknown value, an edit to the file can always add a new + // value moving something from unknown to known. Since Swift is now ABI + // stable, it also means a binary could contain Swift compiled against one + // version of the .pbobjc.h file, but finally linked against an enum with + // more cases. So the Swift code will always have to treat ObjC Proto Enums + // as "non-frozen". The default behavior in SE0192 is for all objc enums to + // be "non-frozen" unless marked as otherwise, so this means this generation + // doesn't have to bother with the `enum_extensibility` attribute, as the + // default will be what is needed. + printer->Print("$comments$typedef$deprecated_attribute$ GPB_ENUM($name$) {\n", "comments", enum_comments, "deprecated_attribute", GetOptionalDeprecatedAttribute(descriptor_, descriptor_->file()), From 64eb9b6e858c8efeebc18439890927ab38d37402 Mon Sep 17 00:00:00 2001 From: Joe Bolinger Date: Wed, 6 Feb 2019 07:57:13 -0800 Subject: [PATCH 02/17] Add more descriptive error messages to init methods in Ruby (#5659) * add more descriptive error messages to init methods * add type errors test to Makefile.am --- Makefile.am | 1 + ruby/ext/google/protobuf_c/map.c | 4 +- ruby/ext/google/protobuf_c/message.c | 6 +- ruby/ext/google/protobuf_c/protobuf.h | 8 +- ruby/ext/google/protobuf_c/repeated_field.c | 4 +- ruby/ext/google/protobuf_c/storage.c | 57 ++++--- ruby/tests/basic.rb | 4 +- ruby/tests/basic_proto2.rb | 2 +- ruby/tests/type_errors.rb | 173 ++++++++++++++++++++ 9 files changed, 225 insertions(+), 34 deletions(-) create mode 100644 ruby/tests/type_errors.rb diff --git a/Makefile.am b/Makefile.am index 5af3f31301..aee14109a1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -950,6 +950,7 @@ ruby_EXTRA_DIST= \ ruby/tests/test_ruby_package.proto \ ruby/tests/generated_code_test.rb \ ruby/tests/well_known_types_test.rb \ + ruby/tests/type_errors.rb \ ruby/travis-test.sh js_EXTRA_DIST= \ diff --git a/ruby/ext/google/protobuf_c/map.c b/ruby/ext/google/protobuf_c/map.c index 8c2f6424c3..59d64fcb79 100644 --- a/ruby/ext/google/protobuf_c/map.c +++ b/ruby/ext/google/protobuf_c/map.c @@ -82,7 +82,7 @@ static VALUE table_key(Map* self, VALUE key, case UPB_TYPE_INT64: case UPB_TYPE_UINT32: case UPB_TYPE_UINT64: - native_slot_set(self->key_type, Qnil, buf, key); + native_slot_set("", self->key_type, Qnil, buf, key); *out_key = buf; *out_length = native_slot_size(self->key_type); break; @@ -396,7 +396,7 @@ VALUE Map_index_set(VALUE _self, VALUE key, VALUE value) { key = table_key(self, key, keybuf, &keyval, &length); mem = value_memory(&v); - native_slot_set(self->value_type, self->value_type_class, mem, value); + native_slot_set("", self->value_type, self->value_type_class, mem, value); // Replace any existing value by issuing a 'remove' operation first. upb_strtable_remove2(&self->table, keyval, length, NULL); diff --git a/ruby/ext/google/protobuf_c/message.c b/ruby/ext/google/protobuf_c/message.c index fd123aebd0..7c3079a4c4 100644 --- a/ruby/ext/google/protobuf_c/message.c +++ b/ruby/ext/google/protobuf_c/message.c @@ -315,7 +315,8 @@ int Message_initialize_kwarg(VALUE key, VALUE val, VALUE _self) { if (TYPE(val) != T_HASH) { rb_raise(rb_eArgError, - "Expected Hash object as initializer value for map field '%s'.", name); + "Expected Hash object as initializer value for map field '%s' (given %s).", + name, rb_class2name(CLASS_OF(val))); } map = layout_get(self->descriptor->layout, Message_data(self), f); Map_merge_into_self(map, val); @@ -324,7 +325,8 @@ int Message_initialize_kwarg(VALUE key, VALUE val, VALUE _self) { if (TYPE(val) != T_ARRAY) { rb_raise(rb_eArgError, - "Expected array as initializer value for repeated field '%s'.", name); + "Expected array as initializer value for repeated field '%s' (given %s).", + name, rb_class2name(CLASS_OF(val))); } ary = layout_get(self->descriptor->layout, Message_data(self), f); for (int i = 0; i < RARRAY_LEN(val); i++) { diff --git a/ruby/ext/google/protobuf_c/protobuf.h b/ruby/ext/google/protobuf_c/protobuf.h index eff212e1a7..8731eeb47b 100644 --- a/ruby/ext/google/protobuf_c/protobuf.h +++ b/ruby/ext/google/protobuf_c/protobuf.h @@ -337,14 +337,16 @@ VALUE Builder_finalize_to_pool(VALUE _self, VALUE pool_rb); #define NATIVE_SLOT_MAX_SIZE sizeof(uint64_t) size_t native_slot_size(upb_fieldtype_t type); -void native_slot_set(upb_fieldtype_t type, +void native_slot_set(const char* name, + upb_fieldtype_t type, VALUE type_class, void* memory, VALUE value); // Atomically (with respect to Ruby VM calls) either update the value and set a // oneof case, or do neither. If |case_memory| is null, then no case value is // set. -void native_slot_set_value_and_case(upb_fieldtype_t type, +void native_slot_set_value_and_case(const char* name, + upb_fieldtype_t type, VALUE type_class, void* memory, VALUE value, @@ -360,7 +362,7 @@ void native_slot_deep_copy(upb_fieldtype_t type, void* to, void* from); bool native_slot_eq(upb_fieldtype_t type, void* mem1, void* mem2); VALUE native_slot_encode_and_freeze_string(upb_fieldtype_t type, VALUE value); -void native_slot_check_int_range_precision(upb_fieldtype_t type, VALUE value); +void native_slot_check_int_range_precision(const char* name, upb_fieldtype_t type, VALUE value); extern rb_encoding* kRubyStringUtf8Encoding; extern rb_encoding* kRubyStringASCIIEncoding; diff --git a/ruby/ext/google/protobuf_c/repeated_field.c b/ruby/ext/google/protobuf_c/repeated_field.c index c6620ee611..8f4c4212bd 100644 --- a/ruby/ext/google/protobuf_c/repeated_field.c +++ b/ruby/ext/google/protobuf_c/repeated_field.c @@ -178,7 +178,7 @@ VALUE RepeatedField_index_set(VALUE _self, VALUE _index, VALUE val) { } memory = RepeatedField_memoryat(self, index, element_size); - native_slot_set(field_type, field_type_class, memory, val); + native_slot_set("", field_type, field_type_class, memory, val); return Qnil; } @@ -217,7 +217,7 @@ VALUE RepeatedField_push(VALUE _self, VALUE val) { RepeatedField_reserve(self, self->size + 1); memory = (void *) (((uint8_t *)self->elements) + self->size * element_size); - native_slot_set(field_type, self->field_type_class, memory, val); + native_slot_set("", field_type, self->field_type_class, memory, val); // native_slot_set may raise an error; bump size only after set. self->size++; return _self; diff --git a/ruby/ext/google/protobuf_c/storage.c b/ruby/ext/google/protobuf_c/storage.c index 6cf4158b01..407342ef5a 100644 --- a/ruby/ext/google/protobuf_c/storage.c +++ b/ruby/ext/google/protobuf_c/storage.c @@ -65,9 +65,10 @@ static bool is_ruby_num(VALUE value) { TYPE(value) == T_BIGNUM); } -void native_slot_check_int_range_precision(upb_fieldtype_t type, VALUE val) { +void native_slot_check_int_range_precision(const char* name, upb_fieldtype_t type, VALUE val) { if (!is_ruby_num(val)) { - rb_raise(cTypeError, "Expected number type for integral field."); + rb_raise(cTypeError, "Expected number type for integral field '%s' (given %s).", + name, rb_class2name(CLASS_OF(val))); } // NUM2{INT,UINT,LL,ULL} macros do the appropriate range checks on upper @@ -77,13 +78,15 @@ void native_slot_check_int_range_precision(upb_fieldtype_t type, VALUE val) { double dbl_val = NUM2DBL(val); if (floor(dbl_val) != dbl_val) { rb_raise(rb_eRangeError, - "Non-integral floating point value assigned to integer field."); + "Non-integral floating point value assigned to integer field '%s' (given %s).", + name, rb_class2name(CLASS_OF(val))); } } if (type == UPB_TYPE_UINT32 || type == UPB_TYPE_UINT64) { if (NUM2DBL(val) < 0) { rb_raise(rb_eRangeError, - "Assigning negative value to unsigned integer field."); + "Assigning negative value to unsigned integer field '%s' (given %s).", + name, rb_class2name(CLASS_OF(val))); } } } @@ -108,12 +111,14 @@ VALUE native_slot_encode_and_freeze_string(upb_fieldtype_t type, VALUE value) { return value; } -void native_slot_set(upb_fieldtype_t type, VALUE type_class, +void native_slot_set(const char* name, + upb_fieldtype_t type, VALUE type_class, void* memory, VALUE value) { - native_slot_set_value_and_case(type, type_class, memory, value, NULL, 0); + native_slot_set_value_and_case(name, type, type_class, memory, value, NULL, 0); } -void native_slot_set_value_and_case(upb_fieldtype_t type, VALUE type_class, +void native_slot_set_value_and_case(const char* name, + upb_fieldtype_t type, VALUE type_class, void* memory, VALUE value, uint32_t* case_memory, uint32_t case_number) { @@ -124,13 +129,15 @@ void native_slot_set_value_and_case(upb_fieldtype_t type, VALUE type_class, switch (type) { case UPB_TYPE_FLOAT: if (!is_ruby_num(value)) { - rb_raise(cTypeError, "Expected number type for float field."); + rb_raise(cTypeError, "Expected number type for float field '%s' (given %s).", + name, rb_class2name(CLASS_OF(value))); } DEREF(memory, float) = NUM2DBL(value); break; case UPB_TYPE_DOUBLE: if (!is_ruby_num(value)) { - rb_raise(cTypeError, "Expected number type for double field."); + rb_raise(cTypeError, "Expected number type for double field '%s' (given %s).", + name, rb_class2name(CLASS_OF(value))); } DEREF(memory, double) = NUM2DBL(value); break; @@ -141,7 +148,8 @@ void native_slot_set_value_and_case(upb_fieldtype_t type, VALUE type_class, } else if (value == Qfalse) { val = 0; } else { - rb_raise(cTypeError, "Invalid argument for boolean field."); + rb_raise(cTypeError, "Invalid argument for boolean field '%s' (given %s).", + name, rb_class2name(CLASS_OF(value))); } DEREF(memory, int8_t) = val; break; @@ -150,7 +158,8 @@ void native_slot_set_value_and_case(upb_fieldtype_t type, VALUE type_class, if (CLASS_OF(value) == rb_cSymbol) { value = rb_funcall(value, rb_intern("to_s"), 0); } else if (CLASS_OF(value) != rb_cString) { - rb_raise(cTypeError, "Invalid argument for string field."); + rb_raise(cTypeError, "Invalid argument for string field '%s' (given %s).", + name, rb_class2name(CLASS_OF(value))); } DEREF(memory, VALUE) = native_slot_encode_and_freeze_string(type, value); @@ -158,7 +167,8 @@ void native_slot_set_value_and_case(upb_fieldtype_t type, VALUE type_class, case UPB_TYPE_BYTES: { if (CLASS_OF(value) != rb_cString) { - rb_raise(cTypeError, "Invalid argument for string field."); + rb_raise(cTypeError, "Invalid argument for bytes field '%s' (given %s).", + name, rb_class2name(CLASS_OF(value))); } DEREF(memory, VALUE) = native_slot_encode_and_freeze_string(type, value); @@ -169,8 +179,8 @@ void native_slot_set_value_and_case(upb_fieldtype_t type, VALUE type_class, value = Qnil; } else if (CLASS_OF(value) != type_class) { rb_raise(cTypeError, - "Invalid type %s to assign to submessage field.", - rb_class2name(CLASS_OF(value))); + "Invalid type %s to assign to submessage field '%s'.", + rb_class2name(CLASS_OF(value)), name); } DEREF(memory, VALUE) = value; break; @@ -181,18 +191,18 @@ void native_slot_set_value_and_case(upb_fieldtype_t type, VALUE type_class, value = rb_funcall(value, rb_intern("to_sym"), 0); } else if (!is_ruby_num(value) && TYPE(value) != T_SYMBOL) { rb_raise(cTypeError, - "Expected number or symbol type for enum field."); + "Expected number or symbol type for enum field '%s'.", name); } if (TYPE(value) == T_SYMBOL) { // Ensure that the given symbol exists in the enum module. VALUE lookup = rb_funcall(type_class, rb_intern("resolve"), 1, value); if (lookup == Qnil) { - rb_raise(rb_eRangeError, "Unknown symbol value for enum field."); + rb_raise(rb_eRangeError, "Unknown symbol value for enum field '%s'.", name); } else { int_val = NUM2INT(lookup); } } else { - native_slot_check_int_range_precision(UPB_TYPE_INT32, value); + native_slot_check_int_range_precision(name, UPB_TYPE_INT32, value); int_val = NUM2INT(value); } DEREF(memory, int32_t) = int_val; @@ -202,7 +212,7 @@ void native_slot_set_value_and_case(upb_fieldtype_t type, VALUE type_class, case UPB_TYPE_INT64: case UPB_TYPE_UINT32: case UPB_TYPE_UINT64: - native_slot_check_int_range_precision(type, value); + native_slot_check_int_range_precision(name, type, value); switch (type) { case UPB_TYPE_INT32: DEREF(memory, int32_t) = NUM2INT(value); @@ -658,8 +668,9 @@ void layout_clear(MessageLayout* layout, DEREF(memory, VALUE) = ary; } else { - native_slot_set(upb_fielddef_type(field), field_type_class(field), - memory, layout_get_default(field)); + native_slot_set(upb_fielddef_name(field), + upb_fielddef_type(field), field_type_class(field), + memory, layout_get_default(field)); } } @@ -816,6 +827,7 @@ void layout_set(MessageLayout* layout, // use native_slot_set_value_and_case(), which ensures that both the value // and case number are altered atomically (w.r.t. the Ruby VM). native_slot_set_value_and_case( + upb_fielddef_name(field), upb_fielddef_type(field), field_type_class(field), memory, val, oneof_case, upb_fielddef_number(field)); @@ -827,8 +839,9 @@ void layout_set(MessageLayout* layout, check_repeated_field_type(val, field); DEREF(memory, VALUE) = val; } else { - native_slot_set(upb_fielddef_type(field), field_type_class(field), memory, - val); + native_slot_set(upb_fielddef_name(field), + upb_fielddef_type(field), field_type_class(field), + memory, val); } if (layout->fields[upb_fielddef_index(field)].hasbit != diff --git a/ruby/tests/basic.rb b/ruby/tests/basic.rb index 5e17bef65b..269c9ee27d 100644 --- a/ruby/tests/basic.rb +++ b/ruby/tests/basic.rb @@ -154,12 +154,12 @@ module BasicTest e = assert_raise ArgumentError do MapMessage.new(:map_string_int32 => "hello") end - assert_equal e.message, "Expected Hash object as initializer value for map field 'map_string_int32'." + assert_equal e.message, "Expected Hash object as initializer value for map field 'map_string_int32' (given String)." e = assert_raise ArgumentError do TestMessage.new(:repeated_uint32 => "hello") end - assert_equal e.message, "Expected array as initializer value for repeated field 'repeated_uint32'." + assert_equal e.message, "Expected array as initializer value for repeated field 'repeated_uint32' (given String)." end def test_map_field diff --git a/ruby/tests/basic_proto2.rb b/ruby/tests/basic_proto2.rb index a59e808de8..53d6a70d2d 100644 --- a/ruby/tests/basic_proto2.rb +++ b/ruby/tests/basic_proto2.rb @@ -207,7 +207,7 @@ module BasicTestProto2 e = assert_raise ArgumentError do TestMessage.new(:repeated_uint32 => "hello") end - assert_equal e.message, "Expected array as initializer value for repeated field 'repeated_uint32'." + assert_equal e.message, "Expected array as initializer value for repeated field 'repeated_uint32' (given String)." end diff --git a/ruby/tests/type_errors.rb b/ruby/tests/type_errors.rb new file mode 100644 index 0000000000..76c591c0a5 --- /dev/null +++ b/ruby/tests/type_errors.rb @@ -0,0 +1,173 @@ +#!/usr/bin/ruby + +# generated_code.rb is in the same directory as this test. +$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) + +require 'test/unit' +require 'google/protobuf/well_known_types' +require 'generated_code_pb' + +class TestTypeErrors < Test::Unit::TestCase + def test_bad_string + check_error Google::Protobuf::TypeError, + "Invalid argument for string field 'optional_string' (given Integer)." do + A::B::C::TestMessage.new(optional_string: 4) + end + check_error Google::Protobuf::TypeError, + "Invalid argument for string field 'oneof_string' (given Integer)." do + A::B::C::TestMessage.new(oneof_string: 4) + end + check_error ArgumentError, + "Expected array as initializer value for repeated field 'repeated_string' (given String)." do + A::B::C::TestMessage.new(repeated_string: '4') + end + end + + def test_bad_float + check_error Google::Protobuf::TypeError, + "Expected number type for float field 'optional_float' (given TrueClass)." do + A::B::C::TestMessage.new(optional_float: true) + end + check_error Google::Protobuf::TypeError, + "Expected number type for float field 'oneof_float' (given TrueClass)." do + A::B::C::TestMessage.new(oneof_float: true) + end + check_error ArgumentError, + "Expected array as initializer value for repeated field 'repeated_float' (given String)." do + A::B::C::TestMessage.new(repeated_float: 'true') + end + end + + def test_bad_double + check_error Google::Protobuf::TypeError, + "Expected number type for double field 'optional_double' (given Symbol)." do + A::B::C::TestMessage.new(optional_double: :double) + end + check_error Google::Protobuf::TypeError, + "Expected number type for double field 'oneof_double' (given Symbol)." do + A::B::C::TestMessage.new(oneof_double: :double) + end + check_error ArgumentError, + "Expected array as initializer value for repeated field 'repeated_double' (given FalseClass)." do + A::B::C::TestMessage.new(repeated_double: false) + end + end + + def test_bad_bool + check_error Google::Protobuf::TypeError, + "Invalid argument for boolean field 'optional_bool' (given Float)." do + A::B::C::TestMessage.new(optional_bool: 4.4) + end + check_error Google::Protobuf::TypeError, + "Invalid argument for boolean field 'oneof_bool' (given Float)." do + A::B::C::TestMessage.new(oneof_bool: 4.4) + end + check_error ArgumentError, + "Expected array as initializer value for repeated field 'repeated_bool' (given String)." do + A::B::C::TestMessage.new(repeated_bool: 'hi') + end + end + + def test_bad_int + check_error Google::Protobuf::TypeError, + "Expected number type for integral field 'optional_int32' (given String)." do + A::B::C::TestMessage.new(optional_int32: 'hi') + end + check_error RangeError, + "Non-integral floating point value assigned to integer field 'optional_int64' (given Float)." do + A::B::C::TestMessage.new(optional_int64: 2.4) + end + check_error Google::Protobuf::TypeError, + "Expected number type for integral field 'optional_uint32' (given Symbol)." do + A::B::C::TestMessage.new(optional_uint32: :thing) + end + check_error Google::Protobuf::TypeError, + "Expected number type for integral field 'optional_uint64' (given FalseClass)." do + A::B::C::TestMessage.new(optional_uint64: false) + end + check_error Google::Protobuf::TypeError, + "Expected number type for integral field 'oneof_int32' (given Symbol)." do + A::B::C::TestMessage.new(oneof_int32: :hi) + end + check_error RangeError, + "Non-integral floating point value assigned to integer field 'oneof_int64' (given Float)." do + A::B::C::TestMessage.new(oneof_int64: 2.4) + end + check_error Google::Protobuf::TypeError, + "Expected number type for integral field 'oneof_uint32' (given String)." do + A::B::C::TestMessage.new(oneof_uint32: 'x') + end + check_error RangeError, + "Non-integral floating point value assigned to integer field 'oneof_uint64' (given Float)." do + A::B::C::TestMessage.new(oneof_uint64: 1.1) + end + check_error ArgumentError, + "Expected array as initializer value for repeated field 'repeated_int32' (given Symbol)." do + A::B::C::TestMessage.new(repeated_int32: :hi) + end + check_error ArgumentError, + "Expected array as initializer value for repeated field 'repeated_int64' (given Float)." do + A::B::C::TestMessage.new(repeated_int64: 2.4) + end + check_error ArgumentError, + "Expected array as initializer value for repeated field 'repeated_uint32' (given String)." do + A::B::C::TestMessage.new(repeated_uint32: 'x') + end + check_error ArgumentError, + "Expected array as initializer value for repeated field 'repeated_uint64' (given Float)." do + A::B::C::TestMessage.new(repeated_uint64: 1.1) + end + end + + def test_bad_enum + check_error RangeError, + "Unknown symbol value for enum field 'optional_enum'." do + A::B::C::TestMessage.new(optional_enum: 'enum') + end + check_error RangeError, + "Unknown symbol value for enum field 'oneof_enum'." do + A::B::C::TestMessage.new(oneof_enum: '') + end + check_error ArgumentError, + "Expected array as initializer value for repeated field 'repeated_enum' (given String)." do + A::B::C::TestMessage.new(repeated_enum: '') + end + end + + def test_bad_bytes + check_error Google::Protobuf::TypeError, + "Invalid argument for bytes field 'optional_bytes' (given Float)." do + A::B::C::TestMessage.new(optional_bytes: 22.22) + end + check_error Google::Protobuf::TypeError, + "Invalid argument for bytes field 'oneof_bytes' (given Symbol)." do + A::B::C::TestMessage.new(oneof_bytes: :T22) + end + check_error ArgumentError, + "Expected array as initializer value for repeated field 'repeated_bytes' (given Symbol)." do + A::B::C::TestMessage.new(repeated_bytes: :T22) + end + end + + def test_bad_msg + check_error Google::Protobuf::TypeError, + "Invalid type Integer to assign to submessage field 'optional_msg'." do + A::B::C::TestMessage.new(optional_msg: 2) + end + check_error Google::Protobuf::TypeError, + "Invalid type String to assign to submessage field 'oneof_msg'." do + A::B::C::TestMessage.new(oneof_msg: '2') + end + check_error ArgumentError, + "Expected array as initializer value for repeated field 'repeated_msg' (given String)." do + A::B::C::TestMessage.new(repeated_msg: '2') + end + end + + def check_error(type, message) + err = assert_raises type do + yield + end + assert_equal message, err.message + end +end From de3be6c225cdb92548648cb899391ef5368051fa Mon Sep 17 00:00:00 2001 From: Greg Engle Date: Wed, 6 Feb 2019 10:08:30 -0600 Subject: [PATCH 03/17] removed dead link to ProtoSharp (#5610) I tried finding an active repo on github with no success. The only ProtoSharp I found wasn't related to PB at all. --- docs/third_party.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/third_party.md b/docs/third_party.md index 94ce0ec066..49f3d54501 100644 --- a/docs/third_party.md +++ b/docs/third_party.md @@ -19,7 +19,6 @@ These are projects we know about implementing Protocol Buffers for other program * C++: https://github.com/google/protobuf (Google-official implementation) * C/C++: http://spbc.sf.net/ * C#: http://code.google.com/p/protobuf-csharp-port -* C#: http://code.google.com/p/protosharp/ * C#: https://silentorbit.com/protobuf/ * C#/.NET/WCF/VB: http://code.google.com/p/protobuf-net/ * Clojure: http://github.com/ninjudd/clojure-protobuf From 2a05691a537686211b1325c55f7e71ea58448003 Mon Sep 17 00:00:00 2001 From: Sydney Acksman Date: Mon, 11 Feb 2019 17:12:40 -0600 Subject: [PATCH 04/17] Refactor how group endings are detected in generated C# code (#5686) * Modify how end tags are encounted in merge code (compiler) * Modify how end tags are encounted in merge code (generated) * Modify how end tags are encounted in merge code (library) * Regenerate generated code through generate_descriptor_proto.sh --- csharp/src/AddressBook/Addressbook.cs | 12 +- .../Conformance.cs | 16 +- .../TestProtos/MapUnittestProto3.cs | 28 +--- .../TestProtos/TestMessagesProto3.cs | 12 +- .../TestProtos/UnittestCustomOptionsProto3.cs | 84 +++------- .../TestProtos/UnittestImportProto3.cs | 4 +- .../TestProtos/UnittestImportPublicProto3.cs | 4 +- .../TestProtos/UnittestIssues.cs | 52 ++---- .../TestProtos/UnittestProto3.cs | 156 +++++------------- .../TestProtos/UnittestWellKnownTypes.cs | 16 +- .../Google.Protobuf/Reflection/Descriptor.cs | 76 +++------ csharp/src/Google.Protobuf/UnknownFieldSet.cs | 23 --- .../src/Google.Protobuf/WellKnownTypes/Any.cs | 4 +- .../src/Google.Protobuf/WellKnownTypes/Api.cs | 12 +- .../WellKnownTypes/Duration.cs | 4 +- .../Google.Protobuf/WellKnownTypes/Empty.cs | 4 +- .../WellKnownTypes/FieldMask.cs | 4 +- .../WellKnownTypes/SourceContext.cs | 4 +- .../Google.Protobuf/WellKnownTypes/Struct.cs | 12 +- .../WellKnownTypes/Timestamp.cs | 4 +- .../Google.Protobuf/WellKnownTypes/Type.cs | 20 +-- .../WellKnownTypes/Wrappers.cs | 36 +--- .../compiler/csharp/csharp_helpers.cc | 13 ++ .../protobuf/compiler/csharp/csharp_helpers.h | 3 + .../compiler/csharp/csharp_message.cc | 13 +- .../protobuf/compiler/csharp/csharp_message.h | 1 + 26 files changed, 167 insertions(+), 450 deletions(-) diff --git a/csharp/src/AddressBook/Addressbook.cs b/csharp/src/AddressBook/Addressbook.cs index c05125c629..d3e1ea9534 100644 --- a/csharp/src/AddressBook/Addressbook.cs +++ b/csharp/src/AddressBook/Addressbook.cs @@ -260,9 +260,7 @@ namespace Google.Protobuf.Examples.AddressBook { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { Name = input.ReadString(); @@ -442,9 +440,7 @@ namespace Google.Protobuf.Examples.AddressBook { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { Number = input.ReadString(); @@ -577,9 +573,7 @@ namespace Google.Protobuf.Examples.AddressBook { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { people_.AddEntriesFrom(input, _repeated_people_codec); diff --git a/csharp/src/Google.Protobuf.Conformance/Conformance.cs b/csharp/src/Google.Protobuf.Conformance/Conformance.cs index 73a140d3d1..0a5106280e 100644 --- a/csharp/src/Google.Protobuf.Conformance/Conformance.cs +++ b/csharp/src/Google.Protobuf.Conformance/Conformance.cs @@ -216,9 +216,7 @@ namespace Conformance { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { failure_.AddEntriesFrom(input, _repeated_failure_codec); @@ -581,9 +579,7 @@ namespace Conformance { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { ProtobufPayload = input.ReadBytes(); @@ -1001,9 +997,7 @@ namespace Conformance { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { ParseError = input.ReadString(); @@ -1166,9 +1160,7 @@ namespace Conformance { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { UseJspbArrayAnyFormat = input.ReadBool(); diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/MapUnittestProto3.cs b/csharp/src/Google.Protobuf.Test/TestProtos/MapUnittestProto3.cs index 2844ca62ce..6d3cd026d1 100644 --- a/csharp/src/Google.Protobuf.Test/TestProtos/MapUnittestProto3.cs +++ b/csharp/src/Google.Protobuf.Test/TestProtos/MapUnittestProto3.cs @@ -541,9 +541,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { mapInt32Int32_.AddEntriesFrom(input, _map_mapInt32Int32_codec); @@ -739,9 +737,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { if (testMap_ == null) { @@ -865,9 +861,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { mapInt32Message_.AddEntriesFrom(input, _map_mapInt32Message_codec); @@ -1007,9 +1001,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { map1_.AddEntriesFrom(input, _map_map1_codec); @@ -1358,9 +1350,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { mapInt32Int32_.AddEntriesFrom(input, _map_mapInt32Int32_codec); @@ -1541,9 +1531,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { type_.AddEntriesFrom(input, _map_type_codec); @@ -1678,9 +1666,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { entry_.AddEntriesFrom(input, _map_entry_codec); diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto3.cs b/csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto3.cs index b59075bc10..b14ee6caee 100644 --- a/csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto3.cs +++ b/csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto3.cs @@ -2895,9 +2895,7 @@ namespace ProtobufTestMessages.Proto3 { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { OptionalInt32 = input.ReadInt32(); @@ -3625,9 +3623,7 @@ namespace ProtobufTestMessages.Proto3 { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { A = input.ReadInt32(); @@ -3768,9 +3764,7 @@ namespace ProtobufTestMessages.Proto3 { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { C = input.ReadInt32(); diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestCustomOptionsProto3.cs b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestCustomOptionsProto3.cs index 9b9ffe2560..2a9efe55ff 100644 --- a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestCustomOptionsProto3.cs +++ b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestCustomOptionsProto3.cs @@ -352,9 +352,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { Field1 = input.ReadString(); @@ -480,9 +478,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; } } @@ -583,9 +579,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; } } @@ -686,9 +680,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; } } @@ -789,9 +781,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; } } @@ -892,9 +882,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; } } @@ -1008,9 +996,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; } } @@ -1111,9 +1097,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; } } @@ -1214,9 +1198,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; } } @@ -1317,9 +1299,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; } } @@ -1420,9 +1400,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; } } @@ -1523,9 +1501,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; } } @@ -1714,9 +1690,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { Foo = input.ReadInt32(); @@ -1928,9 +1902,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { if (bar_ == null) { @@ -2079,9 +2051,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { Waldo = input.ReadInt32(); @@ -2215,9 +2185,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { Qux = input.ReadInt32(); @@ -2325,9 +2293,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; } } @@ -2509,9 +2475,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { I = input.ReadInt32(); @@ -2651,9 +2615,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { Fieldname = input.ReadInt32(); @@ -2761,9 +2723,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; } } @@ -2895,9 +2855,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { NestedField = input.ReadInt32(); diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportProto3.cs b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportProto3.cs index 931dc2eb03..6bf9715171 100644 --- a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportProto3.cs +++ b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportProto3.cs @@ -167,9 +167,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { D = input.ReadInt32(); diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportPublicProto3.cs b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportPublicProto3.cs index fee0120b42..97d181aff4 100644 --- a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportPublicProto3.cs +++ b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportPublicProto3.cs @@ -155,9 +155,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { E = input.ReadInt32(); diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestIssues.cs b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestIssues.cs index f8296b0fab..f27ab64074 100644 --- a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestIssues.cs +++ b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestIssues.cs @@ -181,9 +181,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; } } @@ -286,9 +284,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; } } @@ -391,9 +387,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; } } @@ -560,9 +554,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { Value = (global::UnitTest.Issues.TestProtos.NegativeEnum) input.ReadEnum(); @@ -677,9 +669,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; } } @@ -909,9 +899,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { PrimitiveValue = input.ReadInt32(); @@ -1068,9 +1056,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { Item = input.ReadInt32(); @@ -1223,9 +1209,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { Types_ = input.ReadInt32(); @@ -1339,9 +1323,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; } } @@ -1665,9 +1647,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { PlainString = input.ReadString(); @@ -1867,9 +1847,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { Name = input.ReadString(); @@ -2069,9 +2047,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { Text = input.ReadString(); @@ -2235,9 +2211,7 @@ namespace UnitTest.Issues.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { X = input.ReadInt32(); diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestProto3.cs b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestProto3.cs index 1d4367b781..bbbee22c7b 100644 --- a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestProto3.cs +++ b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestProto3.cs @@ -1387,9 +1387,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { SingleInt32 = input.ReadInt32(); @@ -1757,9 +1755,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { Bb = input.ReadInt32(); @@ -1942,9 +1938,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { if (child_ == null) { @@ -2088,9 +2082,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { DeprecatedInt32 = input.ReadInt32(); @@ -2223,9 +2215,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { C = input.ReadInt32(); @@ -2330,9 +2320,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; } } @@ -2463,9 +2451,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { if (foreignNested_ == null) { @@ -2628,9 +2614,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { A = input.ReadInt32(); @@ -2790,9 +2774,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { if (a_ == null) { @@ -2934,9 +2916,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { if (bb_ == null) { @@ -3095,9 +3075,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { if (a_ == null) { @@ -3233,9 +3211,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { Value = (global::Google.Protobuf.TestProtos.TestEnumWithDupValue) input.ReadEnum(); @@ -3507,9 +3483,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { PrimitiveField = input.ReadInt32(); @@ -3750,9 +3724,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { MyInt = input.ReadInt64(); @@ -3927,9 +3899,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { Bb = input.ReadInt32(); @@ -4067,9 +4037,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { SparseEnum = (global::Google.Protobuf.TestProtos.TestSparseEnum) input.ReadEnum(); @@ -4201,9 +4169,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { Data = input.ReadString(); @@ -4324,9 +4290,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { data_.AddEntriesFrom(input, _repeated_data_codec); @@ -4455,9 +4419,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { Data = input.ReadBytes(); @@ -4586,9 +4548,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { Data = input.ReadBytes(); @@ -4720,9 +4680,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { Data = input.ReadInt32(); @@ -4851,9 +4809,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { Data = input.ReadUInt32(); @@ -4982,9 +4938,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { Data = input.ReadInt64(); @@ -5113,9 +5067,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { Data = input.ReadUInt64(); @@ -5244,9 +5196,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { Data = input.ReadBool(); @@ -5463,9 +5413,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { FooInt = input.ReadInt32(); @@ -5807,9 +5755,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 722: case 720: { @@ -6208,9 +6154,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 722: case 720: { @@ -6491,9 +6435,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 98: case 101: { @@ -6651,9 +6593,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { A = input.ReadString(); @@ -6761,9 +6701,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; } } @@ -6864,9 +6802,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; } } @@ -6967,9 +6903,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; } } @@ -7070,9 +7004,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; } } @@ -7173,9 +7105,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; } } @@ -7276,9 +7206,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; } } @@ -7379,9 +7307,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; } } @@ -7512,9 +7438,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { Text = input.ReadString(); @@ -7661,9 +7585,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { NestedText = input.ReadString(); diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestWellKnownTypes.cs b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestWellKnownTypes.cs index a36825dc32..45f8ece646 100644 --- a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestWellKnownTypes.cs +++ b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestWellKnownTypes.cs @@ -788,9 +788,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { if (anyField_ == null) { @@ -1318,9 +1316,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { anyField_.AddEntriesFrom(input, _repeated_anyField_codec); @@ -2031,9 +2027,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { global::Google.Protobuf.WellKnownTypes.Any subBuilder = new global::Google.Protobuf.WellKnownTypes.Any(); @@ -2544,9 +2538,7 @@ namespace Google.Protobuf.TestProtos { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { anyField_.AddEntriesFrom(input, _map_anyField_codec); diff --git a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs index f101cd3526..0c33e63df4 100644 --- a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs @@ -302,9 +302,7 @@ namespace Google.Protobuf.Reflection { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { file_.AddEntriesFrom(input, _repeated_file_codec); @@ -735,9 +733,7 @@ namespace Google.Protobuf.Reflection { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { Name = input.ReadString(); @@ -1102,9 +1098,7 @@ namespace Google.Protobuf.Reflection { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { Name = input.ReadString(); @@ -1363,9 +1357,7 @@ namespace Google.Protobuf.Reflection { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { Start = input.ReadInt32(); @@ -1568,9 +1560,7 @@ namespace Google.Protobuf.Reflection { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { Start = input.ReadInt32(); @@ -1703,9 +1693,7 @@ namespace Google.Protobuf.Reflection { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 7994: { uninterpretedOption_.AddEntriesFrom(input, _repeated_uninterpretedOption_codec); @@ -2212,9 +2200,7 @@ namespace Google.Protobuf.Reflection { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { Name = input.ReadString(); @@ -2501,9 +2487,7 @@ namespace Google.Protobuf.Reflection { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { Name = input.ReadString(); @@ -2748,9 +2732,7 @@ namespace Google.Protobuf.Reflection { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { Name = input.ReadString(); @@ -2966,9 +2948,7 @@ namespace Google.Protobuf.Reflection { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { Start = input.ReadInt32(); @@ -3197,9 +3177,7 @@ namespace Google.Protobuf.Reflection { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { Name = input.ReadString(); @@ -3407,9 +3385,7 @@ namespace Google.Protobuf.Reflection { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { Name = input.ReadString(); @@ -3759,9 +3735,7 @@ namespace Google.Protobuf.Reflection { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { Name = input.ReadString(); @@ -6949,9 +6923,7 @@ namespace Google.Protobuf.Reflection { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 18: { name_.AddEntriesFrom(input, _repeated_name_codec); @@ -7164,9 +7136,7 @@ namespace Google.Protobuf.Reflection { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { NamePart_ = input.ReadString(); @@ -7345,9 +7315,7 @@ namespace Google.Protobuf.Reflection { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { location_.AddEntriesFrom(input, _repeated_location_codec); @@ -7655,9 +7623,7 @@ namespace Google.Protobuf.Reflection { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: case 8: { @@ -7810,9 +7776,7 @@ namespace Google.Protobuf.Reflection { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { annotation_.AddEntriesFrom(input, _repeated_annotation_codec); @@ -8063,9 +8027,7 @@ namespace Google.Protobuf.Reflection { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: case 8: { diff --git a/csharp/src/Google.Protobuf/UnknownFieldSet.cs b/csharp/src/Google.Protobuf/UnknownFieldSet.cs index 9121567621..21ec13bf84 100644 --- a/csharp/src/Google.Protobuf/UnknownFieldSet.cs +++ b/csharp/src/Google.Protobuf/UnknownFieldSet.cs @@ -260,29 +260,6 @@ namespace Google.Protobuf } return unknownFields; } - - /// - /// Create a new UnknownFieldSet if unknownFields is null. - /// Parse a single field from and merge it - /// into unknownFields. If is configured to discard unknown fields, - /// will be returned as-is and the field will be skipped. - /// - /// The UnknownFieldSet which need to be merged - /// The coded input stream containing the field - /// The merged UnknownFieldSet - public static bool MergeFieldFrom(ref UnknownFieldSet unknownFields, CodedInputStream input) - { - if (input.DiscardUnknownFields) - { - input.SkipLastField(); - return true; - } - if (unknownFields == null) - { - unknownFields = new UnknownFieldSet(); - } - return unknownFields.MergeFieldFrom(input); - } /// /// Merges the fields from into this set. diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs index b1ed0bc307..dd9911067e 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs @@ -292,9 +292,7 @@ namespace Google.Protobuf.WellKnownTypes { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { TypeUrl = input.ReadString(); diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs index a566e40640..438e1db8da 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs @@ -345,9 +345,7 @@ namespace Google.Protobuf.WellKnownTypes { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { Name = input.ReadString(); @@ -663,9 +661,7 @@ namespace Google.Protobuf.WellKnownTypes { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { Name = input.ReadString(); @@ -929,9 +925,7 @@ namespace Google.Protobuf.WellKnownTypes { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { Name = input.ReadString(); diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs index 691ca334ea..2858b532b6 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs @@ -254,9 +254,7 @@ namespace Google.Protobuf.WellKnownTypes { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { Seconds = input.ReadInt64(); diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs index 03ffc4a057..2113add9bc 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs @@ -143,9 +143,7 @@ namespace Google.Protobuf.WellKnownTypes { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; } } diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs b/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs index 8114aa3924..6ad31a50ea 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs @@ -352,9 +352,7 @@ namespace Google.Protobuf.WellKnownTypes { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { paths_.AddEntriesFrom(input, _repeated_paths_codec); diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs b/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs index 2cae68631d..124ddaa712 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs @@ -165,9 +165,7 @@ namespace Google.Protobuf.WellKnownTypes { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { FileName = input.ReadString(); diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs index 9667472522..194b81e965 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs @@ -189,9 +189,7 @@ namespace Google.Protobuf.WellKnownTypes { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { fields_.AddEntriesFrom(input, _map_fields_codec); @@ -515,9 +513,7 @@ namespace Google.Protobuf.WellKnownTypes { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { kind_ = input.ReadEnum(); @@ -677,9 +673,7 @@ namespace Google.Protobuf.WellKnownTypes { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { values_.AddEntriesFrom(input, _repeated_values_codec); diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs index 524ac06e3d..2e5809f2fa 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs @@ -273,9 +273,7 @@ namespace Google.Protobuf.WellKnownTypes { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { Seconds = input.ReadInt64(); diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs index adea910634..52bd343ba8 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs @@ -328,9 +328,7 @@ namespace Google.Protobuf.WellKnownTypes { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { Name = input.ReadString(); @@ -725,9 +723,7 @@ namespace Google.Protobuf.WellKnownTypes { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { Kind = (global::Google.Protobuf.WellKnownTypes.Field.Types.Kind) input.ReadEnum(); @@ -1104,9 +1100,7 @@ namespace Google.Protobuf.WellKnownTypes { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { Name = input.ReadString(); @@ -1306,9 +1300,7 @@ namespace Google.Protobuf.WellKnownTypes { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { Name = input.ReadString(); @@ -1488,9 +1480,7 @@ namespace Google.Protobuf.WellKnownTypes { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { Name = input.ReadString(); diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs index 679eb0f234..25a65aa72c 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs @@ -177,9 +177,7 @@ namespace Google.Protobuf.WellKnownTypes { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 9: { Value = input.ReadDouble(); @@ -316,9 +314,7 @@ namespace Google.Protobuf.WellKnownTypes { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 13: { Value = input.ReadFloat(); @@ -455,9 +451,7 @@ namespace Google.Protobuf.WellKnownTypes { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { Value = input.ReadInt64(); @@ -594,9 +588,7 @@ namespace Google.Protobuf.WellKnownTypes { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { Value = input.ReadUInt64(); @@ -733,9 +725,7 @@ namespace Google.Protobuf.WellKnownTypes { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { Value = input.ReadInt32(); @@ -872,9 +862,7 @@ namespace Google.Protobuf.WellKnownTypes { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { Value = input.ReadUInt32(); @@ -1011,9 +999,7 @@ namespace Google.Protobuf.WellKnownTypes { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { Value = input.ReadBool(); @@ -1150,9 +1136,7 @@ namespace Google.Protobuf.WellKnownTypes { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { Value = input.ReadString(); @@ -1289,9 +1273,7 @@ namespace Google.Protobuf.WellKnownTypes { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) { - return; - } + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { Value = input.ReadBytes(); diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.cc b/src/google/protobuf/compiler/csharp/csharp_helpers.cc index dace41006a..b11e40da5c 100644 --- a/src/google/protobuf/compiler/csharp/csharp_helpers.cc +++ b/src/google/protobuf/compiler/csharp/csharp_helpers.cc @@ -278,6 +278,19 @@ std::string GetEnumValueName(const std::string& enum_name, const std::string& en return result; } +uint GetGroupEndTag(const Descriptor* descriptor) { + const Descriptor* containing_type = descriptor->containing_type(); + if (containing_type == NULL) { + return 0; + } + const FieldDescriptor* field = containing_type->FindFieldByName(descriptor->name()); + if (field != NULL && field->type() == FieldDescriptor::Type::TYPE_GROUP) { + return internal::WireFormatLite::MakeTag(field->number(), internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED); + } else { + return 0; + } +} + std::string ToCSharpName(const std::string& name, const FileDescriptor* file) { std::string result = GetFileNamespace(file); if (result != "") { diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.h b/src/google/protobuf/compiler/csharp/csharp_helpers.h index 5b9f90e0ef..d351a1c9b7 100644 --- a/src/google/protobuf/compiler/csharp/csharp_helpers.h +++ b/src/google/protobuf/compiler/csharp/csharp_helpers.h @@ -118,6 +118,9 @@ inline bool IsMapEntryMessage(const Descriptor* descriptor) { return descriptor->options().map_entry(); } +// Checks if this descriptor is for a group and gets its end tag or 0 if it's not a group +uint GetGroupEndTag(const Descriptor* descriptor); + // Determines whether we're generating code for the proto representation of // descriptors etc, for use in the runtime. This is the only type which is // allowed to use proto2 syntax, and it generates internal classes. diff --git a/src/google/protobuf/compiler/csharp/csharp_message.cc b/src/google/protobuf/compiler/csharp/csharp_message.cc index be1cd115a5..6a79979f77 100644 --- a/src/google/protobuf/compiler/csharp/csharp_message.cc +++ b/src/google/protobuf/compiler/csharp/csharp_message.cc @@ -63,7 +63,8 @@ MessageGenerator::MessageGenerator(const Descriptor* descriptor, const Options* options) : SourceGeneratorBase(descriptor->file(), options), descriptor_(descriptor), - has_bit_field_count_(0) { + has_bit_field_count_(0), + end_tag_(GetGroupEndTag(descriptor)) { // fields by number for (int i = 0; i < descriptor_->field_count(); i++) { fields_by_number_.push_back(descriptor_->field(i)); @@ -539,10 +540,14 @@ void MessageGenerator::GenerateMergingMethods(io::Printer* printer) { } else { printer->Print( "default:\n" - " if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {\n" - " return;\n" - " }\n" + " _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);\n" " break;\n"); + if (end_tag_ != 0) { + printer->Print( + "$end_tag$:\n" + " return;\n", + "end_tag", SimpleItoa(end_tag_)); + } } for (int i = 0; i < fields_by_number().size(); i++) { const FieldDescriptor* field = fields_by_number()[i]; diff --git a/src/google/protobuf/compiler/csharp/csharp_message.h b/src/google/protobuf/compiler/csharp/csharp_message.h index 5e0ac960d8..d2ffe66a4e 100644 --- a/src/google/protobuf/compiler/csharp/csharp_message.h +++ b/src/google/protobuf/compiler/csharp/csharp_message.h @@ -59,6 +59,7 @@ class MessageGenerator : public SourceGeneratorBase { const Descriptor* descriptor_; std::vector fields_by_number_; int has_bit_field_count_; + uint end_tag_; void GenerateMessageSerializationMethods(io::Printer* printer); void GenerateMergingMethods(io::Printer* printer); From 9c1c94f770b85a5c4684f397e24fb5d0bd9ef9ee Mon Sep 17 00:00:00 2001 From: Cy Date: Mon, 11 Feb 2019 18:08:08 -0800 Subject: [PATCH 05/17] Update third party implementation links (#5702) --- docs/third_party.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/third_party.md b/docs/third_party.md index 49f3d54501..ac0162ea65 100644 --- a/docs/third_party.md +++ b/docs/third_party.md @@ -38,6 +38,7 @@ These are projects we know about implementing Protocol Buffers for other program * Erlang: https://github.com/tomas-abrahamsson/gpb * Erlang: http://piqi.org/ * Erlang: https://github.com/basho/erlang_protobuffs (no longer maintained, use gpb instead) +* Hacklang/HHVM: https://github.com/y3llowcake/proto-hack * GDScript: https://github.com/oniksan/godobuf (Godot v3 engine plugin) * Go: https://github.com/golang/protobuf (Google-official implementation) * Go: https://github.com/akunspy/gopbuf @@ -91,6 +92,7 @@ These are projects we know about implementing Protocol Buffers for other program * Solidity: https://github.com/celer-network/pb3-gen-sol * Swift: https://github.com/alexeyxo/protobuf-swift * Swift: https://github.com/apple/swift-protobuf/ +* Typescript: https://github.com/y3llowcake/protoc-gen-ts * Vala: https://launchpad.net/protobuf-vala * Visual Basic: http://code.google.com/p/protobuf-net/ From 7fdc45a854a9e177559ad99e991c06ed1777e480 Mon Sep 17 00:00:00 2001 From: Yuri Vanin Date: Mon, 11 Feb 2019 18:35:29 -0800 Subject: [PATCH 06/17] Use cached value for type safety check during unpacking of Any message (#5698) This performance optimization allows to skip reflection (in the is() method) when the message has been already unpacked once --- src/google/protobuf/compiler/java/java_message.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/google/protobuf/compiler/java/java_message.cc b/src/google/protobuf/compiler/java/java_message.cc index 9aabd62a47..22ff5cdf85 100644 --- a/src/google/protobuf/compiler/java/java_message.cc +++ b/src/google/protobuf/compiler/java/java_message.cc @@ -1446,13 +1446,17 @@ void ImmutableMessageGenerator::GenerateAnyMethods(io::Printer* printer) { "public T unpack(\n" " java.lang.Class clazz)\n" " throws com.google.protobuf.InvalidProtocolBufferException {\n" - " if (!is(clazz)) {\n" + " boolean invalidClazz = false;\n" + " if (cachedUnpackValue != null) {\n" + " if (cachedUnpackValue.getClass() == clazz) {\n" + " return (T) cachedUnpackValue;\n" + " }\n" + " invalidClazz = true;\n" + " }\n" + " if (invalidClazz || !is(clazz)) {\n" " throw new com.google.protobuf.InvalidProtocolBufferException(\n" " \"Type of the Any message does not match the given class.\");\n" " }\n" - " if (cachedUnpackValue != null) {\n" - " return (T) cachedUnpackValue;\n" - " }\n" " T defaultInstance =\n" " com.google.protobuf.Internal.getDefaultInstance(clazz);\n" " T result = (T) defaultInstance.getParserForType()\n" From 39c0947893a31123b705e17ef11bd62f262cea68 Mon Sep 17 00:00:00 2001 From: Joe Bolinger Date: Tue, 12 Feb 2019 09:50:57 -0800 Subject: [PATCH 07/17] implement to_s for message types (#5710) --- ruby/ext/google/protobuf_c/message.c | 1 + ruby/tests/common_tests.rb | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ruby/ext/google/protobuf_c/message.c b/ruby/ext/google/protobuf_c/message.c index 7c3079a4c4..40111e06cb 100644 --- a/ruby/ext/google/protobuf_c/message.c +++ b/ruby/ext/google/protobuf_c/message.c @@ -626,6 +626,7 @@ VALUE build_class_from_descriptor(Descriptor* desc) { rb_define_method(klass, "to_h", Message_to_h, 0); rb_define_method(klass, "to_hash", Message_to_h, 0); rb_define_method(klass, "inspect", Message_inspect, 0); + rb_define_method(klass, "to_s", Message_inspect, 0); rb_define_method(klass, "[]", Message_index, 1); rb_define_method(klass, "[]=", Message_index_set, 2); rb_define_singleton_method(klass, "decode", Message_decode, 1); diff --git a/ruby/tests/common_tests.rb b/ruby/tests/common_tests.rb index 60897b672c..6e25b4db52 100644 --- a/ruby/tests/common_tests.rb +++ b/ruby/tests/common_tests.rb @@ -103,7 +103,7 @@ module CommonTests assert_equal 3, m.repeated_msg.first.sub_child.optional_int32 end - def test_inspect + def test_inspect_eq_to_s m = proto_module::TestMessage.new( :optional_int32 => -42, :optional_enum => :A, @@ -111,10 +111,12 @@ module CommonTests :repeated_string => ["hello", "there", "world"]) expected = "<#{proto_module}::TestMessage: optional_int32: -42, optional_int64: 0, optional_uint32: 0, optional_uint64: 0, optional_bool: false, optional_float: 0.0, optional_double: 0.0, optional_string: \"\", optional_bytes: \"\", optional_msg: <#{proto_module}::TestMessage2: foo: 0>, optional_enum: :A, repeated_int32: [], repeated_int64: [], repeated_uint32: [], repeated_uint64: [], repeated_bool: [], repeated_float: [], repeated_double: [], repeated_string: [\"hello\", \"there\", \"world\"], repeated_bytes: [], repeated_msg: [], repeated_enum: []>" assert_equal expected, m.inspect + assert_equal expected, m.to_s m = proto_module::OneofMessage.new(:b => -42) expected = "<#{proto_module}::OneofMessage: a: \"\", b: -42, c: nil, d: :Default>" assert_equal expected, m.inspect + assert_equal expected, m.to_s end def test_hash From e7283254d6eb01ddfdb63cc3c89cd312e2d354d5 Mon Sep 17 00:00:00 2001 From: Sydney Acksman Date: Thu, 14 Feb 2019 13:34:15 -0600 Subject: [PATCH 08/17] Change MessageType != null in IsInitialized to FieldType == Message || Group (#5688) --- csharp/src/Google.Protobuf/MessageExtensions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/csharp/src/Google.Protobuf/MessageExtensions.cs b/csharp/src/Google.Protobuf/MessageExtensions.cs index e1c57dc43f..ffe6ae6fe0 100644 --- a/csharp/src/Google.Protobuf/MessageExtensions.cs +++ b/csharp/src/Google.Protobuf/MessageExtensions.cs @@ -163,12 +163,12 @@ namespace Google.Protobuf var map = (IDictionary)f.Accessor.GetValue(message); return map.Values.OfType().All(IsInitialized); } - else if (f.IsRepeated && f.MessageType != null) + else if (f.IsRepeated && f.FieldType == FieldType.Message || f.FieldType == FieldType.Group) { var enumerable = (IEnumerable)f.Accessor.GetValue(message); return enumerable.Cast().All(IsInitialized); } - else if (f.MessageType != null) + else if (f.FieldType == FieldType.Message || f.FieldType == FieldType.Group) { if (f.Accessor.HasValue(message)) { From f66c981051217ca2e0c8f1676cb869031e218b08 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Fri, 15 Feb 2019 10:03:39 -0800 Subject: [PATCH 09/17] Revert "Add stack overflow protection for text format" This reverts commit 6dcd81093c151553082a8d6495df95f5d00b5c3c. --- src/google/protobuf/text_format.cc | 8 -------- src/google/protobuf/text_format_unittest.cc | 14 -------------- third_party/googletest | 2 +- 3 files changed, 1 insertion(+), 23 deletions(-) diff --git a/src/google/protobuf/text_format.cc b/src/google/protobuf/text_format.cc index 133944997c..a72361e127 100644 --- a/src/google/protobuf/text_format.cc +++ b/src/google/protobuf/text_format.cc @@ -262,7 +262,6 @@ class TextFormat::Parser::ParserImpl { allow_unknown_enum_(allow_unknown_enum), allow_field_number_(allow_field_number), allow_partial_(allow_partial), - recursion_budget_(io::CodedInputStream::GetDefaultRecursionLimit()), had_errors_(false) { // For backwards-compatibility with proto1, we need to allow the 'f' suffix // for floats. @@ -632,10 +631,6 @@ label_skip_parsing: bool ConsumeFieldMessage(Message* message, const Reflection* reflection, const FieldDescriptor* field) { - if (--recursion_budget_ < 0) { - ReportError("Message is too deep"); - return false; - } // If the parse information tree is not NULL, create a nested one // for the nested message. @@ -653,8 +648,6 @@ label_skip_parsing: delimiter)); } - ++recursion_budget_; - // Reset the parse information tree. parse_info_tree_ = parent; return true; @@ -1186,7 +1179,6 @@ label_skip_parsing: const bool allow_unknown_enum_; const bool allow_field_number_; const bool allow_partial_; - int recursion_budget_; bool had_errors_; }; diff --git a/src/google/protobuf/text_format_unittest.cc b/src/google/protobuf/text_format_unittest.cc index 89bb164377..82a969ee1c 100644 --- a/src/google/protobuf/text_format_unittest.cc +++ b/src/google/protobuf/text_format_unittest.cc @@ -1810,20 +1810,6 @@ TEST_F(TextFormatParserTest, ParseDeprecatedField) { "\"deprecated_int32\"", 1, 21, &message, true); } -TEST_F(TextFormatParserTest, DeepRecursion) { - const char* format = "child: { $0 }"; - std::string input; - for (int i = 0; i < 100; ++i) - input = strings::Substitute(format, input); - - unittest::NestedTestAllTypes message; - ExpectSuccessAndTree(input, &message, nullptr); - - input = strings::Substitute(format, input); - ExpectMessage(input, - "Message is too deep", 1, 908, &message, false); -} - class TextFormatMessageSetTest : public testing::Test { protected: static const char proto_debug_string_[]; diff --git a/third_party/googletest b/third_party/googletest index c3bb0ee2a6..5ec7f0c4a1 160000 --- a/third_party/googletest +++ b/third_party/googletest @@ -1 +1 @@ -Subproject commit c3bb0ee2a63279a803aaad956b9b26d74bf9e6e2 +Subproject commit 5ec7f0c4a113e2f18ac2c6cc7df51ad6afc24081 From 3bf05b88eaf938526f7daee85ab6fb1efb0e809c Mon Sep 17 00:00:00 2001 From: michaelbausor Date: Fri, 15 Feb 2019 16:16:42 -0800 Subject: [PATCH 10/17] PHP: Exclude repeated and map fields from normalization in constructor (#5723) * Exclude repeated and map fields from normalization * Remove erroneous comments * Remove unnecessary check for map type * Add support for repeated/map fields, add tests * Fix wrapper message in repeated/map fields in array constructor * Address PR comments * Removed unused code * Update docs --- php/ext/google/protobuf/message.c | 110 +++++++++++++++++- php/src/Google/Protobuf/Internal/Message.php | 55 +++++++-- .../proto/test_wrapper_type_setters.proto | 4 + php/tests/wrapper_type_setters_test.php | 84 +++++++++++++ 4 files changed, 240 insertions(+), 13 deletions(-) diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c index 079bd1dd45..7cc3032c09 100644 --- a/php/ext/google/protobuf/message.c +++ b/php/ext/google/protobuf/message.c @@ -294,6 +294,57 @@ void build_class_from_descriptor( // PHP Methods // ----------------------------------------------------------------------------- +static bool is_wrapper_msg(const upb_msgdef* m) { + upb_wellknowntype_t type = upb_msgdef_wellknowntype(m); + return type >= UPB_WELLKNOWN_DOUBLEVALUE && + type <= UPB_WELLKNOWN_BOOLVALUE; +} + +static void append_wrapper_message( + zend_class_entry* subklass, RepeatedField* intern, zval* value TSRMLS_DC) { + MessageHeader* submsg; + const upb_fielddef* field; +#if PHP_MAJOR_VERSION < 7 + zval* val = NULL; + MAKE_STD_ZVAL(val); + ZVAL_OBJ(val, subklass->create_object(subklass TSRMLS_CC)); + repeated_field_push_native(intern, &val); + submsg = UNBOX(MessageHeader, val); +#else + zend_object* obj = subklass->create_object(subklass TSRMLS_CC); + repeated_field_push_native(intern, &obj); + submsg = (MessageHeader*)((char*)obj - XtOffsetOf(MessageHeader, std)); +#endif + custom_data_init(subklass, submsg PHP_PROTO_TSRMLS_CC); + + field = upb_msgdef_itof(submsg->descriptor->msgdef, 1); + layout_set(submsg->descriptor->layout, submsg, field, value TSRMLS_CC); +} + +static void set_wrapper_message_as_map_value( + zend_class_entry* subklass, zval* map, zval* key, zval* value TSRMLS_DC) { + MessageHeader* submsg; + const upb_fielddef* field; +#if PHP_MAJOR_VERSION < 7 + zval* val = NULL; + MAKE_STD_ZVAL(val); + ZVAL_OBJ(val, subklass->create_object(subklass TSRMLS_CC)); + map_field_handlers->write_dimension( + map, key, val TSRMLS_CC); + submsg = UNBOX(MessageHeader, val); +#else + zval val; + zend_object* obj = subklass->create_object(subklass TSRMLS_CC); + ZVAL_OBJ(&val, obj); + map_field_handlers->write_dimension(map, key, &val TSRMLS_CC); + submsg = (MessageHeader*)((char*)obj - XtOffsetOf(MessageHeader, std)); +#endif + custom_data_init(subklass, submsg PHP_PROTO_TSRMLS_CC); + + field = upb_msgdef_itof(submsg->descriptor->msgdef, 1); + layout_set(submsg->descriptor->layout, submsg, field, value TSRMLS_CC); +} + void Message_construct(zval* msg, zval* array_wrapper) { TSRMLS_FETCH(); zend_class_entry* ce = Z_OBJCE_P(msg); @@ -336,14 +387,38 @@ void Message_construct(zval* msg, zval* array_wrapper) { HashPosition subpointer; zval subkey; void* memory; + bool is_wrapper = false; + zend_class_entry* subklass = NULL; + const upb_msgdef* mapentry = upb_fielddef_msgsubdef(field); + const upb_fielddef *value_field = upb_msgdef_itof(mapentry, 2); + + if (upb_fielddef_issubmsg(value_field)) { + const upb_msgdef* submsgdef = upb_fielddef_msgsubdef(value_field); + upb_wellknowntype_t type = upb_msgdef_wellknowntype(submsgdef); + is_wrapper = is_wrapper_msg(submsgdef); + + if (is_wrapper) { + PHP_PROTO_HASHTABLE_VALUE subdesc_php = get_def_obj(submsgdef); + Descriptor* subdesc = UNBOX_HASHTABLE_VALUE(Descriptor, subdesc_php); + subklass = subdesc->klass; + } + } + for (zend_hash_internal_pointer_reset_ex(subtable, &subpointer); php_proto_zend_hash_get_current_data_ex(subtable, (void**)&memory, &subpointer) == SUCCESS; zend_hash_move_forward_ex(subtable, &subpointer)) { zend_hash_get_current_key_zval_ex(subtable, &subkey, &subpointer); - map_field_handlers->write_dimension( - submap, &subkey, - CACHED_PTR_TO_ZVAL_PTR((CACHED_VALUE*)memory) TSRMLS_CC); + if (is_wrapper && + Z_TYPE_P(CACHED_PTR_TO_ZVAL_PTR((CACHED_VALUE*)memory)) != IS_OBJECT) { + set_wrapper_message_as_map_value( + subklass, submap, &subkey, + CACHED_PTR_TO_ZVAL_PTR((CACHED_VALUE*)memory) TSRMLS_CC); + } else { + map_field_handlers->write_dimension( + submap, &subkey, + CACHED_PTR_TO_ZVAL_PTR((CACHED_VALUE*)memory) TSRMLS_CC); + } zval_dtor(&subkey); } } else if (upb_fielddef_isseq(field)) { @@ -354,13 +429,36 @@ void Message_construct(zval* msg, zval* array_wrapper) { CACHED_PTR_TO_ZVAL_PTR((CACHED_VALUE*)value)); HashPosition subpointer; void* memory; + bool is_wrapper = false; + zend_class_entry* subklass = NULL; + + if (upb_fielddef_issubmsg(field)) { + const upb_msgdef* submsgdef = upb_fielddef_msgsubdef(field); + upb_wellknowntype_t type = upb_msgdef_wellknowntype(submsgdef); + is_wrapper = is_wrapper_msg(submsgdef); + + if (is_wrapper) { + PHP_PROTO_HASHTABLE_VALUE subdesc_php = get_def_obj(submsgdef); + Descriptor* subdesc = UNBOX_HASHTABLE_VALUE(Descriptor, subdesc_php); + subklass = subdesc->klass; + } + } + for (zend_hash_internal_pointer_reset_ex(subtable, &subpointer); php_proto_zend_hash_get_current_data_ex(subtable, (void**)&memory, &subpointer) == SUCCESS; zend_hash_move_forward_ex(subtable, &subpointer)) { - repeated_field_handlers->write_dimension( - subarray, NULL, - CACHED_PTR_TO_ZVAL_PTR((CACHED_VALUE*)memory) TSRMLS_CC); + if (is_wrapper && + Z_TYPE_P(CACHED_PTR_TO_ZVAL_PTR((CACHED_VALUE*)memory)) != IS_OBJECT) { + RepeatedField* intern = UNBOX(RepeatedField, subarray); + append_wrapper_message( + subklass, intern, + CACHED_PTR_TO_ZVAL_PTR((CACHED_VALUE*)memory) TSRMLS_CC); + } else { + repeated_field_handlers->write_dimension( + subarray, NULL, + CACHED_PTR_TO_ZVAL_PTR((CACHED_VALUE*)memory) TSRMLS_CC); + } } } else if (upb_fielddef_issubmsg(field)) { const upb_msgdef* submsgdef = upb_fielddef_msgsubdef(field); diff --git a/php/src/Google/Protobuf/Internal/Message.php b/php/src/Google/Protobuf/Internal/Message.php index d304a12b47..9765e09b50 100644 --- a/php/src/Google/Protobuf/Internal/Message.php +++ b/php/src/Google/Protobuf/Internal/Message.php @@ -973,9 +973,12 @@ class Message * ]); * ``` * + * This method will trigger an error if it is passed data that cannot + * be converted to the correct type. For example, a StringValue field + * must receive data that is either a string or a StringValue object. + * * @param array $array An array containing message properties and values. * @return null. - * @throws \Exception Invalid data. */ protected function mergeFromArray(array $array) { @@ -987,22 +990,61 @@ class Message 'Invalid message property: ' . $key); } $setter = $field->getSetter(); - if ($field->isWrapperType()) { - self::normalizeToMessageType($value, $field->getMessageType()->getClass()); + if ($field->isMap()) { + $valueField = $field->getMessageType()->getFieldByName('value'); + if (!is_null($valueField) && $valueField->isWrapperType()) { + self::normalizeArrayElementsToMessageType($value, $valueField->getMessageType()->getClass()); + } + } elseif ($field->isWrapperType()) { + $class = $field->getMessageType()->getClass(); + if ($field->isRepeated()) { + self::normalizeArrayElementsToMessageType($value, $class); + } else { + self::normalizeToMessageType($value, $class); + } } $this->$setter($value); } } + /** + * Tries to normalize the elements in $value into a provided protobuf + * wrapper type $class. If $value is any type other than array, we do + * not do any conversion, and instead rely on the existing protobuf + * type checking. If $value is an array, we process each element and + * try to convert it to an instance of $class. + * + * @param mixed $value The array of values to normalize. + * @param string $class The expected wrapper class name + */ + private static function normalizeArrayElementsToMessageType(&$value, $class) + { + if (!is_array($value)) { + // In the case that $value is not an array, we do not want to + // attempt any conversion. Note that this includes the cases + // when $value is a RepeatedField of MapField. In those cases, + // we do not need to convert the elements, as they should + // already be the correct types. + return; + } else { + // Normalize each element in the array. + foreach ($value as $key => &$elementValue) { + self::normalizeToMessageType($elementValue, $class); + } + } + } + /** * Tries to normalize $value into a provided protobuf wrapper type $class. * If $value is any type other than an object, we attempt to construct an * instance of $class and assign $value to it using the setValue method * shared by all wrapper types. * + * This method will raise an error if it receives a type that cannot be + * assigned to the wrapper type via setValue. + * * @param mixed $value The value to normalize. * @param string $class The expected wrapper class name - * @throws \Exception If $value cannot be converted to a wrapper type */ private static function normalizeToMessageType(&$value, $class) { @@ -1019,10 +1061,9 @@ class Message $value = $msg; return; } catch (\Exception $exception) { - throw new \Exception( + trigger_error( "Error normalizing value to type '$class': " . $exception->getMessage(), - $exception->getCode(), - $exception + E_USER_ERROR ); } } diff --git a/php/tests/proto/test_wrapper_type_setters.proto b/php/tests/proto/test_wrapper_type_setters.proto index e1e3309c54..41ca7f3f31 100644 --- a/php/tests/proto/test_wrapper_type_setters.proto +++ b/php/tests/proto/test_wrapper_type_setters.proto @@ -19,4 +19,8 @@ message TestWrapperSetters { google.protobuf.DoubleValue double_value_oneof = 10; google.protobuf.StringValue string_value_oneof = 11; } + + repeated google.protobuf.StringValue repeated_string_value = 12; + + map map_string_value = 13; } diff --git a/php/tests/wrapper_type_setters_test.php b/php/tests/wrapper_type_setters_test.php index 3d09c9a8c2..5509a175a1 100644 --- a/php/tests/wrapper_type_setters_test.php +++ b/php/tests/wrapper_type_setters_test.php @@ -225,4 +225,88 @@ class WrapperTypeSettersTest extends TestBase [TestWrapperSetters::class, BytesValue::class, 'bytes_value', 'getBytesValue', "nine"], ]; } + + /** + * @dataProvider constructorWithRepeatedWrapperTypeDataProvider + */ + public function testConstructorWithRepeatedWrapperType($wrapperField, $getter, $value) + { + $actualInstance = new TestWrapperSetters([$wrapperField => $value]); + foreach ($actualInstance->$getter() as $key => $actualWrapperValue) { + $actualInnerValue = $actualWrapperValue->getValue(); + $expectedElement = $value[$key]; + if (is_object($expectedElement) && is_a($expectedElement, '\Google\Protobuf\StringValue')) { + $expectedInnerValue = $expectedElement->getValue(); + } else { + $expectedInnerValue = $expectedElement; + } + $this->assertEquals($expectedInnerValue, $actualInnerValue); + } + } + + public function constructorWithRepeatedWrapperTypeDataProvider() + { + $sv7 = new StringValue(['value' => 'seven']); + $sv8 = new StringValue(['value' => 'eight']); + + $testWrapperSetters = new TestWrapperSetters(); + $testWrapperSetters->setRepeatedStringValue([$sv7, $sv8]); + $repeatedField = $testWrapperSetters->getRepeatedStringValue(); + + return [ + ['repeated_string_value', 'getRepeatedStringValue', []], + ['repeated_string_value', 'getRepeatedStringValue', [$sv7]], + ['repeated_string_value', 'getRepeatedStringValue', [$sv7, $sv8]], + ['repeated_string_value', 'getRepeatedStringValue', ['seven']], + ['repeated_string_value', 'getRepeatedStringValue', [7]], + ['repeated_string_value', 'getRepeatedStringValue', [7.7]], + ['repeated_string_value', 'getRepeatedStringValue', ['seven', 'eight']], + ['repeated_string_value', 'getRepeatedStringValue', [$sv7, 'eight']], + ['repeated_string_value', 'getRepeatedStringValue', ['seven', $sv8]], + ['repeated_string_value', 'getRepeatedStringValue', $repeatedField], + ]; + } + + /** + * @dataProvider constructorWithMapWrapperTypeDataProvider + */ + public function testConstructorWithMapWrapperType($wrapperField, $getter, $value) + { + $actualInstance = new TestWrapperSetters([$wrapperField => $value]); + foreach ($actualInstance->$getter() as $key => $actualWrapperValue) { + $actualInnerValue = $actualWrapperValue->getValue(); + $expectedElement = $value[$key]; + if (is_object($expectedElement) && is_a($expectedElement, '\Google\Protobuf\StringValue')) { + $expectedInnerValue = $expectedElement->getValue(); + } elseif (is_object($expectedElement) && is_a($expectedElement, '\Google\Protobuf\Internal\MapEntry')) { + $expectedInnerValue = $expectedElement->getValue()->getValue(); + } else { + $expectedInnerValue = $expectedElement; + } + $this->assertEquals($expectedInnerValue, $actualInnerValue); + } + } + + public function constructorWithMapWrapperTypeDataProvider() + { + $sv7 = new StringValue(['value' => 'seven']); + $sv8 = new StringValue(['value' => 'eight']); + + $testWrapperSetters = new TestWrapperSetters(); + $testWrapperSetters->setMapStringValue(['key' => $sv7, 'key2' => $sv8]); + $mapField = $testWrapperSetters->getMapStringValue(); + + return [ + ['map_string_value', 'getMapStringValue', []], + ['map_string_value', 'getMapStringValue', ['key' => $sv7]], + ['map_string_value', 'getMapStringValue', ['key' => $sv7, 'key2' => $sv8]], + ['map_string_value', 'getMapStringValue', ['key' => 'seven']], + ['map_string_value', 'getMapStringValue', ['key' => 7]], + ['map_string_value', 'getMapStringValue', ['key' => 7.7]], + ['map_string_value', 'getMapStringValue', ['key' => 'seven', 'key2' => 'eight']], + ['map_string_value', 'getMapStringValue', ['key' => $sv7, 'key2' => 'eight']], + ['map_string_value', 'getMapStringValue', ['key' => 'seven', 'key2' => $sv8]], + ['map_string_value', 'getMapStringValue', $mapField], + ]; + } } From e22907f364ee00926a2b6a1fd1c005ffcc69a0e8 Mon Sep 17 00:00:00 2001 From: Hao Nguyen <45579440+haon4@users.noreply.github.com> Date: Wed, 20 Feb 2019 11:25:39 -0800 Subject: [PATCH 11/17] Support rc version in update_version.py (#5750) * Support rc version in update_version.py --- update_version.py | 63 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/update_version.py b/update_version.py index 7a961ae139..7d279410e1 100755 --- a/update_version.py +++ b/update_version.py @@ -1,16 +1,25 @@ #!/usr/bin/env python +# Usage: ./update_version.py .. [] +# +# Example: +# ./update_version.py 3.7.1 2 +# => Version will become 3.7.1-rc-2 (beta) +# ./update_version.py 3.7.1 +# => Version will become 3.7.1 (stable) import datetime import re import sys from xml.dom import minidom -if len(sys.argv) < 2: +if len(sys.argv) < 2 or len(sys.argv) > 3: print """ [ERROR] Please specify a version. +./update_version.py .. [] + Example: -./update_version.py 2.1.3 +./update_version.py 3.7.1 2 """ exit(1) @@ -21,10 +30,14 @@ if len(NEW_VERSION_INFO) != 3: [ERROR] Version must be in the format .. Example: -./update_version.py 2.1.3 +./update_version.py 3.7.3 """ exit(1) +RC_VERSION = 0 +if len(sys.argv) > 2: + RC_VERSION = int(sys.argv[2]) + def Find(elem, tagname): for child in elem.childNodes: @@ -41,6 +54,13 @@ def ReplaceText(elem, text): elem.firstChild.replaceWholeText(text) +def GetFullVersion(rc_suffix = '-rc-'): + if RC_VERSION == 0: + return NEW_VERSION + else: + return '%s%s%s' % (NEW_VERSION, rc_suffix, RC_VERSION) + + def RewriteXml(filename, rewriter, add_xml_prefix=True): document = minidom.parse(filename) rewriter(document) @@ -74,7 +94,7 @@ def UpdateConfigure(): lambda line : re.sub( r'^AC_INIT\(\[Protocol Buffers\],\[.*\],\[protobuf@googlegroups.com\],\[protobuf\]\)$', ('AC_INIT([Protocol Buffers],[%s],[protobuf@googlegroups.com],[protobuf])' - % NEW_VERSION), + % GetFullVersion()), line)) @@ -120,44 +140,44 @@ def UpdateCsharp(): RewriteXml('csharp/src/Google.Protobuf/Google.Protobuf.csproj', lambda document : ReplaceText( Find(Find(document.documentElement, 'PropertyGroup'), 'VersionPrefix'), - NEW_VERSION), + GetFullVersion(rc_suffix = '-rc.')), add_xml_prefix=False) RewriteXml('csharp/Google.Protobuf.Tools.nuspec', lambda document : ReplaceText( Find(Find(document.documentElement, 'metadata'), 'version'), - NEW_VERSION)) + GetFullVersion(rc_suffix = '-rc.'))) def UpdateJava(): RewriteXml('java/pom.xml', lambda document : ReplaceText( - Find(document.documentElement, 'version'), NEW_VERSION)) + Find(document.documentElement, 'version'), GetFullVersion())) RewriteXml('java/bom/pom.xml', lambda document : ReplaceText( - Find(document.documentElement, 'version'), NEW_VERSION)) + Find(document.documentElement, 'version'), GetFullVersion())) RewriteXml('java/core/pom.xml', lambda document : ReplaceText( Find(Find(document.documentElement, 'parent'), 'version'), - NEW_VERSION)) + GetFullVersion())) RewriteXml('java/util/pom.xml', lambda document : ReplaceText( Find(Find(document.documentElement, 'parent'), 'version'), - NEW_VERSION)) + GetFullVersion())) RewriteXml('protoc-artifacts/pom.xml', lambda document : ReplaceText( - Find(document.documentElement, 'version'), NEW_VERSION)) + Find(document.documentElement, 'version'), GetFullVersion())) def UpdateJavaScript(): RewriteTextFile('js/package.json', lambda line : re.sub( r'^ "version": ".*",$', - ' "version": "%s",' % NEW_VERSION, + ' "version": "%s",' % GetFullVersion(rc_suffix = '-rc.'), line)) @@ -185,7 +205,7 @@ def UpdateObjectiveC(): RewriteTextFile('Protobuf.podspec', lambda line : re.sub( r"^ s.version = '.*'$", - " s.version = '%s'" % NEW_VERSION, + " s.version = '%s'" % GetFullVersion(rc_suffix = '-rc.'), line)) @@ -203,8 +223,12 @@ def UpdatePhp(): root = document.documentElement version = Find(root, 'version') - ReplaceText(Find(version, 'release'), NEW_VERSION) + ReplaceText(Find(version, 'release'), GetFullVersion(rc_suffix = 'RC')) ReplaceText(Find(version, 'api'), NEW_VERSION) + stability = Find(root, 'stability') + ReplaceText(Find(version, 'release'), + 'stable' if RC_VERSION == 0 else 'beta') + ReplaceText(Find(version, 'api'), 'stable' if RC_VERSION == 0 else 'beta') now = datetime.datetime.now() ReplaceText(Find(root, 'date'), now.strftime('%Y-%m-%d')) ReplaceText(Find(root, 'time'), now.strftime('%H:%M:%S')) @@ -215,7 +239,6 @@ def UpdatePhp(): % NEW_VERSION) return changelog.appendChild(document.createTextNode(' ')) - stability = Find(root, 'stability') release = CreateNode('release', 2, [ CreateNode('version', 3, [ FindAndClone(version, 'release'), @@ -234,18 +257,24 @@ def UpdatePhp(): changelog.appendChild(document.createTextNode('\n ')) RewriteXml('php/ext/google/protobuf/package.xml', Callback) + RewriteTextFile('php/ext/google/protobuf/protobuf.h', + lambda line : re.sub( + r"^#define PHP_PROTOBUF_VERSION .*$", + "#define PHP_PROTOBUF_VERSION \"%s\"" % GetFullVersion(rc_suffix = 'RC'), + line)) + def UpdatePython(): RewriteTextFile('python/google/protobuf/__init__.py', lambda line : re.sub( r"^__version__ = '.*'$", - "__version__ = '%s'" % NEW_VERSION, + "__version__ = '%s'" % GetFullVersion(rc_suffix = 'rc'), line)) def UpdateRuby(): RewriteTextFile('ruby/google-protobuf.gemspec', lambda line : re.sub( r'^ s.version = ".*"$', - ' s.version = "%s"' % NEW_VERSION, + ' s.version = "%s"' % GetFullVersion(rc_suffix = '.rc.'), line)) From c691c4cbfa9a44f320f037a81894970e61dbac2b Mon Sep 17 00:00:00 2001 From: Dalvin Date: Wed, 20 Feb 2019 19:24:37 -0800 Subject: [PATCH 12/17] Enhance java-lite documentation (#5743) --- java/lite.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/java/lite.md b/java/lite.md index 84a45ec5ab..403d44f2c7 100644 --- a/java/lite.md +++ b/java/lite.md @@ -21,7 +21,9 @@ download it from maven: Choose the version that works on your platform (e.g., on windows you can download `protoc-gen-javalite-3.0.0-windows-x86_32.exe`), rename it to protoc-gen-javalite (or protoc-gen-javalite.exe on windows) and place it -in a directory where it can be find in PATH. +in a directory where it can be find in PATH. If you are using unix like OS +then make sure to convert `protoc-gen-javalite` to unix executable. For example +`chmod +x protoc-gen-javalite` Once you have the protoc and protoc plugin, you can generate Java Lite code for your .proto files: From e479410564727d8954e0704254f4345f97e3d844 Mon Sep 17 00:00:00 2001 From: Xiang Dai <764524258@qq.com> Date: Thu, 21 Feb 2019 11:28:50 +0800 Subject: [PATCH 13/17] delete all duplicate empty blanks (#5758) Signed-off-by: Xiang Dai <764524258@qq.com> --- benchmarks/Makefile.am | 32 +- benchmarks/README.md | 8 +- .../protobuf/ProtoCaliperBenchmark.java | 26 +- benchmarks/js/benchmark_suite.js | 6 +- benchmarks/js/js_benchmark.js | 12 +- benchmarks/php/PhpBenchmark.php | 14 +- .../protobuf.js/protobufjs_benchmark.js | 10 +- benchmarks/python/py_benchmark.py | 8 +- benchmarks/util/result_parser.py | 2 +- benchmarks/util/result_uploader.py | 4 +- cmake/README.md | 14 +- cmake/protobuf-config.cmake.in | 2 +- cmake/version.rc.in | 2 +- conformance/ConformanceJava.java | 12 +- conformance/conformance_ruby.rb | 2 +- conformance/third_party/jsoncpp/json.h | 20 +- conformance/third_party/jsoncpp/jsoncpp.cpp | 20 +- csharp/CHANGES.txt | 18 +- csharp/README.md | 26 +- .../csharp/protos/unittest_issues.proto | 10 +- .../Collections/MapFieldTest.cs | 4 +- .../Compatibility/TypeExtensionsTest.cs | 2 +- .../Google.Protobuf.Test.csproj | 4 +- .../Google.Protobuf.Test/JsonTokenizerTest.cs | 10 +- .../Reflection/DescriptorsTest.cs | 4 +- .../Reflection/FieldAccessTest.cs | 2 +- .../src/Google.Protobuf.Test/SampleEnum.cs | 2 +- .../WellKnownTypes/TimestampTest.cs | 2 +- .../WellKnownTypes/WrappersTest.cs | 4 +- csharp/protos/unittest_issues.proto | 10 +- csharp/protos/unittest_proto3.proto | 4 +- .../Google.Protobuf.Conformance/Program.cs | 8 +- .../Collections/MapFieldTest.cs | 4 +- .../ProtobufEqualityComparersTest.cs | 2 +- .../Compatibility/TypeExtensionsTest.cs | 2 +- .../Google.Protobuf.Test/FieldMaskTreeTest.cs | 4 +- .../Google.Protobuf.Test.csproj | 2 +- .../Google.Protobuf.Test/JsonFormatterTest.cs | 2 +- .../Google.Protobuf.Test/JsonTokenizerTest.cs | 10 +- .../Reflection/DescriptorsTest.cs | 4 +- .../Reflection/FieldAccessTest.cs | 2 +- csharp/src/Google.Protobuf.Test/SampleEnum.cs | 2 +- csharp/src/Google.Protobuf.Test/SampleNaNs.cs | 2 +- .../WellKnownTypes/TimestampTest.cs | 4 +- .../WellKnownTypes/WrappersTest.cs | 4 +- csharp/src/Google.Protobuf.Test/testprotos.pb | Bin 204996 -> 204752 bytes csharp/src/Google.Protobuf/FieldCodec.cs | 4 +- csharp/src/Google.Protobuf/FieldMaskTree.cs | 6 +- .../Google.Protobuf/Google.Protobuf.csproj | 4 +- csharp/src/Google.Protobuf/JsonFormatter.cs | 8 +- csharp/src/Google.Protobuf/JsonParser.cs | 4 +- csharp/src/Google.Protobuf/JsonTokenizer.cs | 4 +- .../src/Google.Protobuf/LimitedInputStream.cs | 2 +- .../src/Google.Protobuf/MessageExtensions.cs | 2 +- csharp/src/Google.Protobuf/MessageParser.cs | 4 +- .../Reflection/CustomOptions.cs | 6 +- .../Reflection/DescriptorBase.cs | 2 +- .../Reflection/EnumValueDescriptor.cs | 2 +- .../Reflection/FieldDescriptor.cs | 4 +- .../Google.Protobuf/Reflection/IDescriptor.cs | 2 +- .../Reflection/MessageDescriptor.cs | 2 +- .../Reflection/OneofAccessor.cs | 2 +- .../Reflection/OriginalNameAttribute.cs | 2 +- .../Reflection/SingleFieldAccessor.cs | 2 +- csharp/src/Google.Protobuf/UnknownField.cs | 4 +- .../WellKnownTypes/AnyPartial.cs | 2 +- .../WellKnownTypes/DurationPartial.cs | 2 +- .../WellKnownTypes/FieldMaskPartial.cs | 2 +- docs/options.md | 2 +- docs/performance.md | 8 +- docs/third_party.md | 2 +- examples/list_people_test.go | 2 +- .../protobuf/unittest_optimize_for.proto | 2 +- .../protobuf/unittest_optimize_for.proto | 2 +- .../google/protobuf/test/ByteStringTest.java | 6 +- .../protobuf/test/DeprecatedFieldTest.java | 12 +- .../google/protobuf/test/DescriptorsTest.java | 8 +- .../protobuf/test/GeneratedMessageTest.java | 2 +- .../protobuf/test/LiteralByteStringTest.java | 4 +- .../com/google/protobuf/test/MessageTest.java | 4 +- .../test/RopeByteStringSubstringTest.java | 2 +- .../protobuf/test/RopeByteStringTest.java | 2 +- .../com/google/protobuf/GeneratedMessage.java | 8 +- .../google/protobuf/GeneratedMessageV3.java | 2 +- .../protobuf/util/FieldMaskTreeTest.java | 2 +- js/README.md | 4 +- kokoro/linux/benchmark/continuous.cfg | 2 +- kokoro/linux/benchmark/run.sh | 2 +- .../ruby/macos/ruby/ruby_build_environment.sh | 2 +- objectivec/DevTools/full_mac_build.sh | 2 +- objectivec/GPBRuntimeTypes.h | 2 +- php/ext/google/protobuf/encode_decode.c | 8 +- php/ext/google/protobuf/type_check.c | 4 +- php/ext/google/protobuf/upb.c | 408 +++++++++--------- php/ext/google/protobuf/upb.h | 2 +- php/src/Google/Protobuf/Internal/GPBWire.php | 4 +- .../internal/service_reflection_test.py | 2 +- .../protobuf/internal/_parameterized.py | 2 +- python/tox.ini | 2 +- ruby/README.md | 2 +- ruby/ext/google/protobuf_c/defs.c | 14 +- ruby/ext/google/protobuf_c/storage.c | 8 +- ruby/ext/google/protobuf_c/upb.c | 408 +++++++++--------- ruby/ext/google/protobuf_c/upb.h | 2 +- .../protobuf/jruby/SentinelOuterClass.java | 44 +- src/google/protobuf/any.pb.cc | 2 +- src/google/protobuf/any.pb.h | 32 +- src/google/protobuf/api.pb.cc | 2 +- src/google/protobuf/api.pb.h | 128 +++--- .../compiler/csharp/csharp_field_base.cc | 2 +- .../compiler/csharp/csharp_generator.cc | 6 +- .../compiler/csharp/csharp_helpers.cc | 4 +- .../compiler/csharp/csharp_map_field.cc | 2 +- .../compiler/csharp/csharp_message.cc | 2 +- .../protobuf/compiler/csharp/csharp_message.h | 2 +- .../compiler/csharp/csharp_message_field.cc | 6 +- .../compiler/csharp/csharp_primitive_field.cc | 4 +- .../csharp/csharp_reflection_class.cc | 4 +- .../csharp/csharp_repeated_enum_field.cc | 2 +- src/google/protobuf/compiler/plugin.pb.cc | 2 +- .../protobuf/compiler/ruby/ruby_generator.cc | 8 +- src/google/protobuf/descriptor.pb.cc | 2 +- src/google/protobuf/duration.pb.cc | 2 +- src/google/protobuf/duration.pb.h | 4 +- src/google/protobuf/empty.pb.cc | 2 +- src/google/protobuf/field_mask.pb.cc | 2 +- src/google/protobuf/repeated_field.h | 2 +- src/google/protobuf/source_context.pb.cc | 2 +- src/google/protobuf/source_context.pb.h | 16 +- src/google/protobuf/struct.pb.cc | 2 +- src/google/protobuf/struct.pb.h | 4 +- src/google/protobuf/stubs/stringpiece.h | 2 +- .../protobuf/stubs/structurally_valid.cc | 2 +- src/google/protobuf/stubs/time_test.cc | 2 +- .../protobuf/testdata/golden_message_maps | Bin 13619 -> 13606 bytes src/google/protobuf/timestamp.pb.cc | 2 +- src/google/protobuf/timestamp.pb.h | 4 +- src/google/protobuf/type.pb.cc | 14 +- src/google/protobuf/type.pb.h | 222 +++++----- src/google/protobuf/wrappers.pb.cc | 2 +- src/google/protobuf/wrappers.pb.h | 58 +-- 141 files changed, 984 insertions(+), 984 deletions(-) diff --git a/benchmarks/Makefile.am b/benchmarks/Makefile.am index 6f63a4cc22..81183657e1 100644 --- a/benchmarks/Makefile.am +++ b/benchmarks/Makefile.am @@ -126,7 +126,7 @@ java_benchmark_testing_files = \ java/src/main/java/com/google/protobuf/ProtoCaliperBenchmark.java javac_middleman: $(java_benchmark_testing_files) protoc_middleman protoc_middleman2 - cp -r $(srcdir)/java tmp + cp -r $(srcdir)/java tmp mkdir -p tmp/java/lib cp $(top_srcdir)/java/core/target/*.jar tmp/java/lib/protobuf-java.jar cd tmp/java && mvn clean compile assembly:single -Dprotobuf.version=$(PACKAGE_VERSION) && cd ../.. @@ -253,7 +253,7 @@ go_protoc_middleman: make_tmp_dir $(top_srcdir)/src/protoc$(EXEEXT) $(benchmarks oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --go_out=$$oldpwd/tmp $(benchmarks_protoc_inputs_proto2_message4) ) touch go_protoc_middleman -go-benchmark: go_protoc_middleman +go-benchmark: go_protoc_middleman @echo "Writing shortcut script go-benchmark..." @echo '#! /bin/bash' > go-benchmark @echo 'cd $(srcdir)/go' >> go-benchmark @@ -265,7 +265,7 @@ go-benchmark: go_protoc_middleman @echo 'cd ..' >> go-benchmark @chmod +x go-benchmark -go: go_protoc_middleman go-benchmark +go: go_protoc_middleman go-benchmark ./go-benchmark $(all_data) ############# GO RULES END ############## @@ -322,9 +322,9 @@ $(cpp_no_group_benchmarks_protoc_outputs_proto2_header): cpp_no_group_protoc_mid generate_cpp_no_group_benchmark_code: cp $(srcdir)/cpp/cpp_benchmark.cc gogo/cpp_no_group/cpp_benchmark.cc sed -i -e "s/\#include \"datasets/\#include \"gogo\/cpp_no_group\/datasets/g" gogo/cpp_no_group/cpp_benchmark.cc - sed -i -e "s/\#include \"benchmarks.pb.h/\#include \"gogo\/cpp_no_group\/benchmarks.pb.h/g" gogo/cpp_no_group/cpp_benchmark.cc + sed -i -e "s/\#include \"benchmarks.pb.h/\#include \"gogo\/cpp_no_group\/benchmarks.pb.h/g" gogo/cpp_no_group/cpp_benchmark.cc touch generate_cpp_no_group_benchmark_code - + bin_PROGRAMS += cpp-no-group-benchmark cpp_no_group_benchmark_LDADD = $(top_srcdir)/src/libprotobuf.la $(top_srcdir)/third_party/benchmark/src/libbenchmark.a cpp_no_group_benchmark_SOURCES = gogo/cpp_no_group/cpp_benchmark.cc @@ -343,7 +343,7 @@ nodist_cpp_no_group_benchmark_SOURCES = \ cpp_no_group: cpp_no_group_protoc_middleman generate_gogo_data cpp-no-group-benchmark ./cpp-no-group-benchmark $(gogo_data) - + gogo_proto_middleman: protoc-gen-gogoproto mkdir -p "tmp/gogo_proto" oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I$(srcdir) -I$(top_srcdir) --plugin=protoc-gen-gogoproto --gogoproto_out=$$oldpwd/tmp/gogo_proto $(benchmarks_protoc_inputs) $(benchmarks_protoc_inputs_benchmark_wrapper) $(benchmarks_protoc_inputs_proto2) ) @@ -355,7 +355,7 @@ generate_gogo_data: protoc_middleman protoc_middleman2 gogo-data-scrubber mkdir -p `dirname $(gogo_data)` ./gogo-data-scrubber $(all_data) $(gogo_data) touch generate_gogo_data - + make_tmp_dir_gogo: mkdir -p tmp/go_no_group/benchmark_code mkdir -p tmp/gogofast/benchmark_code @@ -435,10 +435,10 @@ gogo-benchmark: go_no_group: go_no_group_protoc_middleman generate_gogo_data generate_all_gogo_benchmark_code gogo-benchmark ./gogo-benchmark go_no_group $(gogo_data) - -gogofast: gogofast_protoc_middleman generate_gogo_data gogo-benchmark generate_all_gogo_benchmark_code + +gogofast: gogofast_protoc_middleman generate_gogo_data gogo-benchmark generate_all_gogo_benchmark_code ./gogo-benchmark gogofast $(gogo_data) - + gogofaster: gogofaster_protoc_middleman generate_gogo_data gogo-benchmark generate_all_gogo_benchmark_code ./gogo-benchmark gogofaster $(gogo_data) @@ -448,7 +448,7 @@ gogoslick: gogoslick_protoc_middleman generate_gogo_data gogo-benchmark generat ############# GOGO RULES END ############ - + ############ UTIL RULES BEGIN ############ bin_PROGRAMS += protoc-gen-gogoproto gogo-data-scrubber protoc-gen-proto2_to_proto3 proto3-data-stripper @@ -481,7 +481,7 @@ nodist_proto3_data_stripper_SOURCES = \ $(benchmarks_protoc_outputs_proto2_header) \ $(benchmarks_protoc_outputs_header) - + ############ UTIL RULES END ############ ############ PROTO3 PREPARATION BEGIN ############# @@ -510,7 +510,7 @@ proto3_middleman_php: proto3_proto_middleman php-benchmark: proto3_middleman_php generate_proto3_data mkdir -p "tmp/php/Google/Protobuf/Benchmark" && cp php/PhpBenchmark.php "tmp/php/Google/Protobuf/Benchmark" - cp php/autoload.php "tmp/php" + cp php/autoload.php "tmp/php" @echo "Writing shortcut script php-benchmark..." @echo '#! /bin/bash' > php-benchmark @echo 'export PROTOBUF_PHP_SRCDIR="$$(cd $(top_srcdir) && pwd)/php/src"' >> php-benchmark @@ -527,8 +527,8 @@ php_c_extension: cd $(top_srcdir)/php/ext/google/protobuf && phpize && ./configure CFLAGS='-O3' && make -j8 php-c-benchmark: proto3_middleman_php generate_proto3_data php_c_extension php_c_extension - mkdir -p "tmp/php/Google/Protobuf/Benchmark" && cp php/PhpBenchmark.php "tmp/php/Google/Protobuf/Benchmark" - cp php/autoload.php "tmp/php" + mkdir -p "tmp/php/Google/Protobuf/Benchmark" && cp php/PhpBenchmark.php "tmp/php/Google/Protobuf/Benchmark" + cp php/autoload.php "tmp/php" @echo "Writing shortcut script php-c-benchmark..." @echo '#! /bin/bash' > php-c-benchmark @echo 'export PROTOBUF_PHP_SRCDIR="$$(cd $(top_srcdir) && pwd)/php/src"' >> php-c-benchmark @@ -654,4 +654,4 @@ CLEANFILES = \ clean-local: -rm -rf tmp/* - + diff --git a/benchmarks/README.md b/benchmarks/README.md index 72885886a7..486b2f954b 100644 --- a/benchmarks/README.md +++ b/benchmarks/README.md @@ -3,7 +3,7 @@ This directory contains benchmarking schemas and data sets that you can use to test a variety of performance scenarios against your -protobuf language runtime. If you are looking for performance +protobuf language runtime. If you are looking for performance numbers of officially support languages, see [here]( https://github.com/protocolbuffers/protobuf/blob/master/docs/performance.md) @@ -45,8 +45,8 @@ And you also need to make sure `pkg-config` is installed. ### Go Go protobufs are maintained at [github.com/golang/protobuf]( -http://github.com/golang/protobuf). If not done already, you need to install the -toolchain and the Go protoc-gen-go plugin for protoc. +http://github.com/golang/protobuf). If not done already, you need to install the +toolchain and the Go protoc-gen-go plugin for protoc. To install protoc-gen-go, run: @@ -59,7 +59,7 @@ The first command installs `protoc-gen-go` into the `bin` directory in your loca The second command adds the `bin` directory to your `PATH` so that `protoc` can locate the plugin later. ### PHP -PHP benchmark's requirement is the same as PHP protobuf's requirements. The benchmark will automaticly +PHP benchmark's requirement is the same as PHP protobuf's requirements. The benchmark will automaticly include PHP protobuf's src and build the c extension if required. ### Node.js diff --git a/benchmarks/java/src/main/java/com/google/protobuf/ProtoCaliperBenchmark.java b/benchmarks/java/src/main/java/com/google/protobuf/ProtoCaliperBenchmark.java index c766d74ee4..a4402481b0 100644 --- a/benchmarks/java/src/main/java/com/google/protobuf/ProtoCaliperBenchmark.java +++ b/benchmarks/java/src/main/java/com/google/protobuf/ProtoCaliperBenchmark.java @@ -24,8 +24,8 @@ import java.util.ArrayList; import java.util.List; // Caliper set CICompilerCount to 1 for making sure compilation doesn't run in parallel with itself, -// This makes TieredCompilation not working. We just disable TieredCompilation by default. In master -// branch this has been disabled by default in caliper: +// This makes TieredCompilation not working. We just disable TieredCompilation by default. In master +// branch this has been disabled by default in caliper: // https://github.com/google/caliper/blob/master/caliper-runner/src/main/java/com/google/caliper/runner/target/Jvm.java#L38:14 // But this haven't been added into most recent release. @VmOptions("-XX:-TieredCompilation") @@ -89,7 +89,7 @@ public class ProtoCaliperBenchmark { return com.google.protobuf.benchmarks.BenchmarkMessage4.GoogleMessage4.getDefaultInstance(); } }; - + abstract ExtensionRegistry getExtensionRegistry(); abstract Message getDefaultInstance(); } @@ -97,7 +97,7 @@ public class ProtoCaliperBenchmark { private BenchmarkMessageType benchmarkMessageType; @Param("") private String dataFile; - + private byte[] inputData; private BenchmarkDataset benchmarkDataset; private Message defaultMessage; @@ -125,7 +125,7 @@ public class ProtoCaliperBenchmark { + benchmarkDataset.getMessageName()); } } - + @BeforeExperiment void setUp() throws IOException { if (!dataFile.equals("")) { @@ -145,7 +145,7 @@ public class ProtoCaliperBenchmark { inputStreamList = new ArrayList(); inputStringList = new ArrayList(); sampleMessageList = new ArrayList(); - + for (int i = 0; i < benchmarkDataset.getPayloadCount(); i++) { byte[] singleInputData = benchmarkDataset.getPayload(i).toByteArray(); inputDataList.add(benchmarkDataset.getPayload(i).toByteArray()); @@ -156,8 +156,8 @@ public class ProtoCaliperBenchmark { defaultMessage.newBuilderForType().mergeFrom(singleInputData, extensions).build()); } } - - + + @Benchmark void serializeToByteArray(int reps) throws IOException { if (sampleMessageList.size() == 0) { @@ -165,11 +165,11 @@ public class ProtoCaliperBenchmark { } for (int i = 0; i < reps; i++) { for (int j = 0; j < sampleMessageList.size(); j++) { - sampleMessageList.get(j).toByteArray(); + sampleMessageList.get(j).toByteArray(); } } } - + @Benchmark void serializeToMemoryStream(int reps) throws IOException { if (sampleMessageList.size() == 0) { @@ -178,11 +178,11 @@ public class ProtoCaliperBenchmark { for (int i = 0; i < reps; i++) { for (int j = 0; j < sampleMessageList.size(); j++) { ByteArrayOutputStream output = new ByteArrayOutputStream(); - sampleMessageList.get(j).writeTo(output); + sampleMessageList.get(j).writeTo(output); } } } - + @Benchmark void deserializeFromByteArray(int reps) throws IOException { if (inputDataList.size() == 0) { @@ -195,7 +195,7 @@ public class ProtoCaliperBenchmark { } } } - + @Benchmark void deserializeFromMemoryStream(int reps) throws IOException { if (inputStreamList.size() == 0) { diff --git a/benchmarks/js/benchmark_suite.js b/benchmarks/js/benchmark_suite.js index c95024b2e2..c5c3e5105a 100644 --- a/benchmarks/js/benchmark_suite.js +++ b/benchmarks/js/benchmark_suite.js @@ -9,8 +9,8 @@ function newBenchmark(messageName, filename, language) { }) .on("start", function() { process.stdout.write( - "benchmarking message " + messageName - + " of dataset file " + filename + "benchmarking message " + messageName + + " of dataset file " + filename + "'s performance ..." + "\n\n"); }) .on("cycle", function(event) { @@ -21,7 +21,7 @@ function newBenchmark(messageName, filename, language) { return 1 / (bench.stats.mean + bench.stats.moe); } benches.forEach(function(val, index) { - benches[index] = getHz(val); + benches[index] = getHz(val); }); }), benches: benches diff --git a/benchmarks/js/js_benchmark.js b/benchmarks/js/js_benchmark.js index 875be68139..c44fee01c3 100644 --- a/benchmarks/js/js_benchmark.js +++ b/benchmarks/js/js_benchmark.js @@ -30,7 +30,7 @@ process.argv.forEach(function(filename, index) { json_file = filename.replace(/^--json_output=/, ''); return; } - + var benchmarkDataset = proto.benchmarks.BenchmarkDataset.deserializeBinary(fs.readFileSync(filename)); var messageList = []; @@ -40,7 +40,7 @@ process.argv.forEach(function(filename, index) { messageList.push(message.deserializeBinary(onePayload)); totalBytes += onePayload.length; }); - + var senarios = benchmarkSuite.newBenchmark( benchmarkDataset.getMessageName(), filename, "js"); senarios.suite @@ -48,14 +48,14 @@ process.argv.forEach(function(filename, index) { benchmarkDataset.getPayloadList().forEach(function(onePayload) { var protoType = getNewPrototype(benchmarkDataset.getMessageName()); protoType.deserializeBinary(onePayload); - }); + }); }) .add("js serialize", function() { var protoType = getNewPrototype(benchmarkDataset.getMessageName()); messageList.forEach(function(message) { message.serializeBinary(); }); - }) + }) .run({"Async": false}); results.push({ @@ -66,9 +66,9 @@ process.argv.forEach(function(filename, index) { } }) - console.log("Throughput for deserialize: " + console.log("Throughput for deserialize: " + senarios.benches[0] * totalBytes / 1024 / 1024 + "MB/s" ); - console.log("Throughput for serialize: " + console.log("Throughput for serialize: " + senarios.benches[1] * totalBytes / 1024 / 1024 + "MB/s" ); console.log(""); }); diff --git a/benchmarks/php/PhpBenchmark.php b/benchmarks/php/PhpBenchmark.php index 2c5245d853..d3db61d248 100644 --- a/benchmarks/php/PhpBenchmark.php +++ b/benchmarks/php/PhpBenchmark.php @@ -33,7 +33,7 @@ class BenchmarkMethod (new $args[1]())->mergeFromString($payloads->offsetGet($i)); } } - + // $args: array of message static function serialize(&$args) { foreach ($args as &$temp_message) { @@ -49,7 +49,7 @@ class Benchmark private $benchmark_time; private $total_bytes; private $coefficient; - + public function __construct($benchmark_name, $args, $total_bytes, $benchmark_time = 5.0) { $this->args = $args; @@ -58,7 +58,7 @@ class Benchmark $this->total_bytes = $total_bytes; $this->coefficient = pow (10, 0) / pow(2, 20); } - + public function runBenchmark() { $t = $this->runBenchmarkWithTimes(1); $times = ceil($this->benchmark_time / $t); @@ -66,7 +66,7 @@ class Benchmark ($times == 1 ? $t : $this->runBenchmarkWithTimes($times)) * $this->coefficient; } - + private function runBenchmarkWithTimes($times) { $st = microtime(true); for ($i = 0; $i < $times; $i++) { @@ -109,14 +109,14 @@ function runBenchmark($file, $behavior_prefix) { array_push($message_list, $new_message); $total_bytes += strlen($payloads->offsetGet($i)); } - + $parse_benchmark = new Benchmark( "\Google\Protobuf\Benchmark\BenchmarkMethod::parse", array($dataset, $message_name), $total_bytes); $serialize_benchmark = new Benchmark( "\Google\Protobuf\Benchmark\BenchmarkMethod::serialize", $message_list, $total_bytes); - + return array( "filename" => $file, "benchmarks" => array( @@ -139,7 +139,7 @@ foreach ($argv as $index => $arg) { if ($arg == "--json") { $json_output = true; } else if (strpos($arg, "--behavior_prefix") == 0) { - $behavior_prefix = str_replace("--behavior_prefix=", "", $arg); + $behavior_prefix = str_replace("--behavior_prefix=", "", $arg); } } diff --git a/benchmarks/protobuf.js/protobufjs_benchmark.js b/benchmarks/protobuf.js/protobufjs_benchmark.js index 2629e9f46f..19e54972b8 100644 --- a/benchmarks/protobuf.js/protobufjs_benchmark.js +++ b/benchmarks/protobuf.js/protobufjs_benchmark.js @@ -30,7 +30,7 @@ process.argv.forEach(function(filename, index) { messageList.push(message.decode(onePayload)); totalBytes += onePayload.length; }); - + var senarios = benchmarkSuite.newBenchmark( benchmarkDataset.messageName, filename, "protobufjs"); senarios.suite @@ -38,14 +38,14 @@ process.argv.forEach(function(filename, index) { benchmarkDataset.payload.forEach(function(onePayload) { var protoType = getNewPrototype(benchmarkDataset.messageName); protoType.decode(onePayload); - }); + }); }) .add("protobuf.js static encoding", function() { var protoType = getNewPrototype(benchmarkDataset.messageName); messageList.forEach(function(message) { protoType.encode(message).finish(); }); - }) + }) .run({"Async": false}); results.push({ @@ -56,9 +56,9 @@ process.argv.forEach(function(filename, index) { } }) - console.log("Throughput for decoding: " + console.log("Throughput for decoding: " + senarios.benches[0] * totalBytes / 1024 / 1024 + "MB/s" ); - console.log("Throughput for encoding: " + console.log("Throughput for encoding: " + senarios.benches[1] * totalBytes / 1024 / 1024 + "MB/s" ); console.log(""); }); diff --git a/benchmarks/python/py_benchmark.py b/benchmarks/python/py_benchmark.py index d29175e2bc..f2c7bccbe8 100755 --- a/benchmarks/python/py_benchmark.py +++ b/benchmarks/python/py_benchmark.py @@ -8,7 +8,7 @@ import fnmatch import json parser = argparse.ArgumentParser(description="Python protobuf benchmark") -parser.add_argument("data_files", metavar="dataFile", nargs="+", +parser.add_argument("data_files", metavar="dataFile", nargs="+", help="testing data files.") parser.add_argument("--json", action="store_const", dest="json", const="yes", default="no", @@ -138,14 +138,14 @@ class Benchmark: t = timeit.timeit(stmt="%s(%s)" % (self.test_method, test_method_args), setup=self.full_setup_code(setup_method_args), number=reps); - return self.total_bytes * 1.0 / 2 ** 20 / (1.0 * t / reps * self.full_iteration) - + return self.total_bytes * 1.0 / 2 ** 20 / (1.0 * t / reps * self.full_iteration) + if __name__ == "__main__": results = [] for file in args.data_files: results.append(run_one_test(file)) - + if args.json != "no": print(json.dumps(results)) else: diff --git a/benchmarks/util/result_parser.py b/benchmarks/util/result_parser.py index 8f26dd2888..e3d8e423d3 100755 --- a/benchmarks/util/result_parser.py +++ b/benchmarks/util/result_parser.py @@ -295,6 +295,6 @@ def get_result_from_file(cpp_file="", if php_file != "": __parse_php_result(php_file, "php") if php_c_file != "": - __parse_php_result(php_c_file, "php") + __parse_php_result(php_c_file, "php") return __results diff --git a/benchmarks/util/result_uploader.py b/benchmarks/util/result_uploader.py index 021cc54622..2a35d9694d 100755 --- a/benchmarks/util/result_uploader.py +++ b/benchmarks/util/result_uploader.py @@ -60,7 +60,7 @@ def upload_result(result_list, metadata): new_result["labels"] = labels_string[1:] new_result["timestamp"] = _INITIAL_TIME print(labels_string) - + bq = big_query_utils.create_big_query() row = big_query_utils.make_row(str(uuid.uuid4()), new_result) if not big_query_utils.insert_rows(bq, _PROJECT_ID, _DATASET, @@ -91,7 +91,7 @@ if __name__ == "__main__": default="") parser.add_argument("-php_c", "--php_c_input_file", help="The php with c ext benchmark result file's name", - default="") + default="") args = parser.parse_args() metadata = get_metadata() diff --git a/cmake/README.md b/cmake/README.md index 29f7669517..96aaf4f97d 100644 --- a/cmake/README.md +++ b/cmake/README.md @@ -130,11 +130,11 @@ It will generate *Visual Studio* solution file *protobuf.sln* in current directo If the *gmock* directory does not exist, and you do not want to build protobuf unit tests, you need to add *cmake* command argument `-Dprotobuf_BUILD_TESTS=OFF` to disable testing. -To make a *Visual Studio* file for Visual Studio 15 2017, create the *Visual Studio* +To make a *Visual Studio* file for Visual Studio 15 2017, create the *Visual Studio* solution file above and edit the CmakeCache file. - + C:Path\to\protobuf\cmake\build\solution\CMakeCache - + Then create the *Visual Studio* solution file again Compiling @@ -177,9 +177,9 @@ You should see output similar to: Running main() from gmock_main.cc [==========] Running 1546 tests from 165 test cases. - + ... - + [==========] 1546 tests from 165 test cases ran. (2529 ms total) [ PASSED ] 1546 tests. @@ -198,7 +198,7 @@ To run specific tests: [ RUN ] AnyTest.TestIs [ OK ] AnyTest.TestIs (0 ms) [----------] 3 tests from AnyTest (1 ms total) - + [----------] Global test environment tear-down [==========] 3 tests from 1 test case ran. (2 ms total) [ PASSED ] 3 tests. @@ -310,7 +310,7 @@ If you already have ZLIB library and headers at some other location on your syst -DZLIB_INCLUDE_DIR= -DZLIB_LIB= - + Build and testing protobuf as usual. Notes on Compiler Warnings diff --git a/cmake/protobuf-config.cmake.in b/cmake/protobuf-config.cmake.in index 18054687b9..29e39d88af 100644 --- a/cmake/protobuf-config.cmake.in +++ b/cmake/protobuf-config.cmake.in @@ -37,7 +37,7 @@ function(protobuf_generate) if(NOT protobuf_generate_PROTOC_OUT_DIR) set(protobuf_generate_PROTOC_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}) endif() - + if(protobuf_generate_EXPORT_MACRO AND protobuf_generate_LANGUAGE STREQUAL cpp) set(_dll_export_decl "dllexport_decl=${protobuf_generate_EXPORT_MACRO}:") endif() diff --git a/cmake/version.rc.in b/cmake/version.rc.in index cbce1e5389..aeeaadf8c5 100644 --- a/cmake/version.rc.in +++ b/cmake/version.rc.in @@ -23,7 +23,7 @@ VS_VERSION_INFO VERSIONINFO FILETYPE VFT_DLL BEGIN BLOCK "VarFileInfo" - BEGIN + BEGIN // English language (0x409) and the Windows Unicode codepage (1200) VALUE "Translation", 0x409, 1200 END diff --git a/conformance/ConformanceJava.java b/conformance/ConformanceJava.java index 008f3bc7ae..e5e15943af 100644 --- a/conformance/ConformanceJava.java +++ b/conformance/ConformanceJava.java @@ -57,7 +57,7 @@ class ConformanceJava { buf[3] = (byte)(val >> 24); writeToStdout(buf); } - + private enum BinaryDecoderType { BTYE_STRING_DECODER, BYTE_ARRAY_DECODER, @@ -69,11 +69,11 @@ class ConformanceJava { } private static class BinaryDecoder { - public MessageType decode (ByteString bytes, BinaryDecoderType type, + public MessageType decode (ByteString bytes, BinaryDecoderType type, Parser parser, ExtensionRegistry extensions) throws InvalidProtocolBufferException { switch (type) { - case BTYE_STRING_DECODER: + case BTYE_STRING_DECODER: return parser.parseFrom(bytes, extensions); case BYTE_ARRAY_DECODER: return parser.parseFrom(bytes.toByteArray(), extensions); @@ -94,7 +94,7 @@ class ConformanceJava { } catch (InvalidProtocolBufferException e) { throw e; } - } + } case DIRECT_BYTE_BUFFER_DECODER: { ByteBuffer buffer = ByteBuffer.allocateDirect(bytes.size()); bytes.copyTo(buffer); @@ -135,7 +135,7 @@ class ConformanceJava { ArrayList messages = new ArrayList (); ArrayList exceptions = new ArrayList (); - + for (int i = 0; i < BinaryDecoderType.values().length; i++) { messages.add(null); exceptions.add(null); @@ -273,7 +273,7 @@ class ConformanceJava { throw new RuntimeException("Unspecified output format."); case PROTOBUF: { - ByteString MessageString = testMessage.toByteString(); + ByteString MessageString = testMessage.toByteString(); return Conformance.ConformanceResponse.newBuilder().setProtobufPayload(MessageString).build(); } diff --git a/conformance/conformance_ruby.rb b/conformance/conformance_ruby.rb index df63bf7ced..0e2126e018 100755 --- a/conformance/conformance_ruby.rb +++ b/conformance/conformance_ruby.rb @@ -54,7 +54,7 @@ def do_test(request) elsif request.message_type.eql?('protobuf_test_messages.proto2.TestAllTypesProto2') response.skipped = "Ruby doesn't support proto2" return response - else + else fail "Protobuf request doesn't have specific payload type" end diff --git a/conformance/third_party/jsoncpp/json.h b/conformance/third_party/jsoncpp/json.h index 42e7e7f4ad..32fd0720d4 100644 --- a/conformance/third_party/jsoncpp/json.h +++ b/conformance/third_party/jsoncpp/json.h @@ -6,28 +6,28 @@ // ////////////////////////////////////////////////////////////////////// /* -The JsonCpp library's source code, including accompanying documentation, +The JsonCpp library's source code, including accompanying documentation, tests and demonstration applications, are licensed under the following conditions... -The author (Baptiste Lepilleur) explicitly disclaims copyright in all -jurisdictions which recognize such a disclaimer. In such jurisdictions, +The author (Baptiste Lepilleur) explicitly disclaims copyright in all +jurisdictions which recognize such a disclaimer. In such jurisdictions, this software is released into the Public Domain. In jurisdictions which do not recognize Public Domain property (e.g. Germany as of 2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur, and is released under the terms of the MIT License (see below). -In jurisdictions which recognize Public Domain property, the user of this -software may choose to accept it either as 1) Public Domain, 2) under the -conditions of the MIT License (see below), or 3) under the terms of dual +In jurisdictions which recognize Public Domain property, the user of this +software may choose to accept it either as 1) Public Domain, 2) under the +conditions of the MIT License (see below), or 3) under the terms of dual Public Domain/MIT License conditions described here, as they choose. The MIT License is about as close to Public Domain as a license can get, and is described in clear, concise terms at: http://en.wikipedia.org/wiki/MIT_License - + The full text of the MIT License follows: ======================================================================== @@ -434,7 +434,7 @@ protected: /** Exceptions which the user cannot easily avoid. * * E.g. out-of-memory (when we use malloc), stack-overflow, malicious input - * + * * \remark derived from Json::Exception */ class JSON_API RuntimeError : public Exception { @@ -445,7 +445,7 @@ public: /** Exceptions thrown by JSON_ASSERT/JSON_FAIL macros. * * These are precondition-violations (user bugs) and internal errors (our bugs). - * + * * \remark derived from Json::Exception */ class JSON_API LogicError : public Exception { @@ -1570,7 +1570,7 @@ public: - `"rejectDupKeys": false or true` - If true, `parse()` returns false when a key is duplicated within an object. - `"allowSpecialFloats": false or true` - - If true, special float values (NaNs and infinities) are allowed + - If true, special float values (NaNs and infinities) are allowed and their values are lossfree restorable. You can examine 'settings_` yourself diff --git a/conformance/third_party/jsoncpp/jsoncpp.cpp b/conformance/third_party/jsoncpp/jsoncpp.cpp index f803962ade..4d3e0f2f31 100644 --- a/conformance/third_party/jsoncpp/jsoncpp.cpp +++ b/conformance/third_party/jsoncpp/jsoncpp.cpp @@ -6,28 +6,28 @@ // ////////////////////////////////////////////////////////////////////// /* -The JsonCpp library's source code, including accompanying documentation, +The JsonCpp library's source code, including accompanying documentation, tests and demonstration applications, are licensed under the following conditions... -The author (Baptiste Lepilleur) explicitly disclaims copyright in all -jurisdictions which recognize such a disclaimer. In such jurisdictions, +The author (Baptiste Lepilleur) explicitly disclaims copyright in all +jurisdictions which recognize such a disclaimer. In such jurisdictions, this software is released into the Public Domain. In jurisdictions which do not recognize Public Domain property (e.g. Germany as of 2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur, and is released under the terms of the MIT License (see below). -In jurisdictions which recognize Public Domain property, the user of this -software may choose to accept it either as 1) Public Domain, 2) under the -conditions of the MIT License (see below), or 3) under the terms of dual +In jurisdictions which recognize Public Domain property, the user of this +software may choose to accept it either as 1) Public Domain, 2) under the +conditions of the MIT License (see below), or 3) under the terms of dual Public Domain/MIT License conditions described here, as they choose. The MIT License is about as close to Public Domain as a license can get, and is described in clear, concise terms at: http://en.wikipedia.org/wiki/MIT_License - + The full text of the MIT License follows: ======================================================================== @@ -207,7 +207,7 @@ static inline void fixNumericLocale(char* begin, char* end) { #include #if defined(_MSC_VER) -#if !defined(WINCE) && defined(__STDC_SECURE_LIB__) && _MSC_VER >= 1500 // VC++ 9.0 and above +#if !defined(WINCE) && defined(__STDC_SECURE_LIB__) && _MSC_VER >= 1500 // VC++ 9.0 and above #define snprintf sprintf_s #elif _MSC_VER >= 1900 // VC++ 14.0 and above #define snprintf std::snprintf @@ -4029,7 +4029,7 @@ Value& Path::make(Value& root) const { #define snprintf std::snprintf #endif -#if defined(__BORLANDC__) +#if defined(__BORLANDC__) #include #define isfinite _finite #define snprintf _snprintf @@ -5096,7 +5096,7 @@ StreamWriter* StreamWriterBuilder::newStreamWriter() const std::string cs_str = settings_["commentStyle"].asString(); bool eyc = settings_["enableYAMLCompatibility"].asBool(); bool dnp = settings_["dropNullPlaceholders"].asBool(); - bool usf = settings_["useSpecialFloats"].asBool(); + bool usf = settings_["useSpecialFloats"].asBool(); unsigned int pre = settings_["precision"].asUInt(); CommentStyle::Enum cs = CommentStyle::All; if (cs_str == "All") { diff --git a/csharp/CHANGES.txt b/csharp/CHANGES.txt index a87cd4d5df..8574b7c4a3 100644 --- a/csharp/CHANGES.txt +++ b/csharp/CHANGES.txt @@ -26,7 +26,7 @@ Changes: - Optimized enum parsing. Fixes: -- Fix for bug in limited input stream's Position, Introduced Position on +- Fix for bug in limited input stream's Position, Introduced Position on output stream - Fix for writing a character to a JSON output overflows allocated buffer - Optimize FromBase64String to return Empty when presented with empty string. @@ -47,14 +47,14 @@ Changes: - Added 'Unsafe' static type in ByteString to allow direct buffer access Fixes: -- Issue 50: The XML serializer will fail to deserialize a message with empty +- Issue 50: The XML serializer will fail to deserialize a message with empty child message - Issue 45: Use of 'item' as a field name causes AmbiguousMatchException - Issue 49: Generated nested static Types class should be partial - Issue 38: Disable CLSCompliant warnings (3021) - Issue 40: proto_path does not work for command-line file names - Issue 54: should retire all bytes in buffer (bufferSize) -- Issue 43: Fix to correct identical 'umbrella_classname' options from trying +- Issue 43: Fix to correct identical 'umbrella_classname' options from trying to write to the same filename. =============================================================================== @@ -66,7 +66,7 @@ Features: NONE, GENERIC, INTERFACE, or IRPCDISPATCH - Added interfaces IRpcDispatch and IRpcServerStub to provide for blocking services and implementations. -- Added ProtoGen.exe command-line argument "--protoc_dir=" to specify the +- Added ProtoGen.exe command-line argument "--protoc_dir=" to specify the location of protoc.exe. - Extracted interfaces for ICodedInputStream and ICodedOutputStream to allow custom implementation of writers with both speed and size optimizations. @@ -86,9 +86,9 @@ Fixes: - Issue 16: Does not integrate well with other tooling - Issue 19: Support for negative enum values - Issue 26: AddRange in GeneratedBuilder iterates twice. -- Issue 27: Remove XML documentation output from test projects to clear +- Issue 27: Remove XML documentation output from test projects to clear warnings/errors. -- Issue 28: Circular message dependencies result in null default values for +- Issue 28: Circular message dependencies result in null default values for Message fields. - Issue 29: Message classes generated have a public default constructor. You can disable private ctor generation with the option generate_private_ctor. @@ -109,14 +109,14 @@ RELEASE NOTES - Version 2.3.0.277 =============================================================================== Features: -- Added cls_compliance option to generate attributes indicating +- Added cls_compliance option to generate attributes indicating non-CLS-compliance. - Added file_extension option to control the generated output file's extension. - Added umbrella_namespace option to place the umbrella class into a nested - namespace to address issues with proto files having the same name as a + namespace to address issues with proto files having the same name as a message it contains. - Added output_directory option to set the output path for the source file(s). -- Added ignore_google_protobuf option to avoid generating code for includes +- Added ignore_google_protobuf option to avoid generating code for includes from the google.protobuf package. - Added the LITE framework (Google.ProtoBuffersLite.dll) and the ability to generate code with "option optimize_for = LITE_RUNTIME;". diff --git a/csharp/README.md b/csharp/README.md index aafef16ada..9aab782da1 100644 --- a/csharp/README.md +++ b/csharp/README.md @@ -10,7 +10,7 @@ You will also want to install the `Google.Protobuf.Tools` NuGet package, which contains precompiled version of `protoc.exe` and a copy of well known `.proto` files under the package's `tools` directory. -To generate C# files from your `.proto` files, invoke `protoc` with the +To generate C# files from your `.proto` files, invoke `protoc` with the `--csharp_out` option. Supported platforms @@ -37,8 +37,8 @@ later. Although *users* of this project are only expected to have Visual Studio 2012 or later, *developers* of the library are required to have Visual Studio 2017 or later, as the library uses C# 6 features -in its implementation, as well as the new Visual Studio 2017 csproj -format. These features have no impact when using the compiled code - +in its implementation, as well as the new Visual Studio 2017 csproj +format. These features have no impact when using the compiled code - they're only relevant when building the `Google.Protobuf` assembly. In order to run and debug the AddressBook example in the IDE, you must @@ -56,19 +56,19 @@ run using the Visual Studio Test Explorer or `dotnet test`. .NET 3.5 ======== -We don't officially support .NET 3.5. However, there has been some effort -to make enabling .NET 3.5 support relatively painless in case you require it. -There's no guarantee that this will continue in the future, so rely on .NET +We don't officially support .NET 3.5. However, there has been some effort +to make enabling .NET 3.5 support relatively painless in case you require it. +There's no guarantee that this will continue in the future, so rely on .NET 3.5 support at your peril. -To enable .NET 3.5 support, you must edit the `TargetFrameworks` elements of -[src/Google.Protobuf/Google.Protobuf.csproj](src/Google.Protobuf/Google.Protobuf.csproj) -(and [src/Google.Protobuf.Test/Google.Protobuf.Test.csproj](src/Google.Protobuf.Test/Google.Protobuf.Test.csproj) -if you want to run the unit tests): +To enable .NET 3.5 support, you must edit the `TargetFrameworks` elements of +[src/Google.Protobuf/Google.Protobuf.csproj](src/Google.Protobuf/Google.Protobuf.csproj) +(and [src/Google.Protobuf.Test/Google.Protobuf.Test.csproj](src/Google.Protobuf.Test/Google.Protobuf.Test.csproj) +if you want to run the unit tests): -Open the .csproj file in a text editor and simply add `net35` to the list of -target frameworks, noting that the `TargetFrameworks` element appears twice in -the file (once in the first `PropertyGroup` element, and again in the second +Open the .csproj file in a text editor and simply add `net35` to the list of +target frameworks, noting that the `TargetFrameworks` element appears twice in +the file (once in the first `PropertyGroup` element, and again in the second `PropertyGroup` element, i.e., the one with the conditional). History of C# protobufs diff --git a/csharp/compatibility_tests/v3.0.0/protos/csharp/protos/unittest_issues.proto b/csharp/compatibility_tests/v3.0.0/protos/csharp/protos/unittest_issues.proto index 7bec1f8017..b6178bf1af 100644 --- a/csharp/compatibility_tests/v3.0.0/protos/csharp/protos/unittest_issues.proto +++ b/csharp/compatibility_tests/v3.0.0/protos/csharp/protos/unittest_issues.proto @@ -20,7 +20,7 @@ message Issue307 { // Old issue 13: http://code.google.com/p/protobuf-csharp-port/issues/detail?id=13 // New issue 309: https://github.com/protocolbuffers/protobuf/issues/309 - + // message A { // optional int32 _A = 1; // } @@ -101,21 +101,21 @@ message TestJsonFieldOrdering { // that will require fixing other tests in multiple platforms. // Alternatively, consider just adding this to // unittest_proto3.proto if multiple platforms want it. - + int32 plain_int32 = 4; oneof o1 { string o1_string = 2; int32 o1_int32 = 5; } - + string plain_string = 1; - + oneof o2 { int32 o2_int32 = 6; string o2_string = 3; } - + } message TestJsonName { diff --git a/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Collections/MapFieldTest.cs b/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Collections/MapFieldTest.cs index 9c8459073c..3b4e1d33b1 100644 --- a/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Collections/MapFieldTest.cs +++ b/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Collections/MapFieldTest.cs @@ -86,7 +86,7 @@ namespace Google.Protobuf.Collections var map = new MapField(); Assert.Throws(() => map[null] = new ForeignMessage()); } - + [Test] public void AddPreservesInsertionOrder() { @@ -471,7 +471,7 @@ namespace Google.Protobuf.Collections keys.CopyTo(array, 1); CollectionAssert.AreEqual(new[] { null, "foo", "x", null }, array); } - + // Just test keys - we know the implementation is the same for values [Test] public void NonGenericViewCopyTo() diff --git a/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Compatibility/TypeExtensionsTest.cs b/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Compatibility/TypeExtensionsTest.cs index f430b06bed..e8a3d360c2 100644 --- a/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Compatibility/TypeExtensionsTest.cs +++ b/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Compatibility/TypeExtensionsTest.cs @@ -59,7 +59,7 @@ namespace Google.Protobuf.Compatibility [TestCase(typeof(string), typeof(int), false)] [TestCase(typeof(int), typeof(int), true)] [TestCase(typeof(ValueType), typeof(int), true)] - [TestCase(typeof(long), typeof(int), false)] // + [TestCase(typeof(long), typeof(int), false)] // public void IsAssignableFrom(Type target, Type argument, bool expected) { Assert.AreEqual(expected, TypeExtensions.IsAssignableFrom(target, argument)); diff --git a/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj b/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj index 06d07b9f4a..6bc1e0ca4d 100644 --- a/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj +++ b/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj @@ -18,7 +18,7 @@ -