From 4474ed198a2de1e7abb7c26ffc41d10956fed111 Mon Sep 17 00:00:00 2001 From: Vesa Laakso <482561+valscion@users.noreply.github.com> Date: Wed, 13 Mar 2024 15:27:23 +0200 Subject: [PATCH] Re-generate protobuf files to be compatible with google-protobuf v4.x https://github.com/protocolbuffers/protobuf/releases/tag/v26.0-rc3 The compiled Ruby files will no longer work with google-protobuf v4.26.0 that has been released March 12, 2024. --- lib/google/type/date_pb.rb | 34 ++++++++++++--- lib/protobuf_nested_struct/struct_pb.rb | 58 ++++++++++++++----------- 2 files changed, 59 insertions(+), 33 deletions(-) diff --git a/lib/google/type/date_pb.rb b/lib/google/type/date_pb.rb index fc64dda..cc21100 100644 --- a/lib/google/type/date_pb.rb +++ b/lib/google/type/date_pb.rb @@ -1,18 +1,38 @@ +# frozen_string_literal: true # Generated by the protocol buffer compiler. DO NOT EDIT! -# source: date.proto +# source: google/type/date.proto require 'google/protobuf' -Google::Protobuf::DescriptorPool.generated_pool.build do - add_message "google.type.Date" do - optional :year, :int32, 1 - optional :month, :int32, 2 - optional :day, :int32, 3 + +descriptor_data = "\n\x16google/type/date.proto\x12\x0bgoogle.type\"0\n\x04\x44\x61te\x12\x0c\n\x04year\x18\x01 \x01(\x05\x12\r\n\x05month\x18\x02 \x01(\x05\x12\x0b\n\x03\x64\x61y\x18\x03 \x01(\x05\x42]\n\x0f\x63om.google.typeB\tDateProtoP\x01Z4google.golang.org/genproto/googleapis/type/date;date\xf8\x01\x01\xa2\x02\x03GTPb\x06proto3" + +pool = Google::Protobuf::DescriptorPool.generated_pool + +begin + pool.add_serialized_file(descriptor_data) +rescue TypeError + # Compatibility code: will be removed in the next major version. + require 'google/protobuf/descriptor_pb' + parsed = Google::Protobuf::FileDescriptorProto.decode(descriptor_data) + parsed.clear_dependency + serialized = parsed.class.encode(parsed) + file = pool.add_serialized_file(serialized) + warn "Warning: Protobuf detected an import path issue while loading generated file #{__FILE__}" + imports = [ + ] + imports.each do |type_name, expected_filename| + import_file = pool.lookup(type_name).file_descriptor + if import_file.name != expected_filename + warn "- #{file.name} imports #{expected_filename}, but that import was loaded as #{import_file.name}" + end end + warn "Each proto file must use a consistent fully-qualified name." + warn "This will become an error in the next major version." end module Google module Type - Date = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.type.Date").msgclass + Date = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.type.Date").msgclass end end diff --git a/lib/protobuf_nested_struct/struct_pb.rb b/lib/protobuf_nested_struct/struct_pb.rb index 1d91e9c..0eaa102 100644 --- a/lib/protobuf_nested_struct/struct_pb.rb +++ b/lib/protobuf_nested_struct/struct_pb.rb @@ -1,38 +1,44 @@ +# frozen_string_literal: true # Generated by the protocol buffer compiler. DO NOT EDIT! -# source: struct.proto +# source: protobuf_nested_struct/struct.proto require 'google/protobuf' require 'google/protobuf/timestamp_pb' require 'google/type/date_pb' -Google::Protobuf::DescriptorPool.generated_pool.build do - add_message "protobuf_nested_struct.HashMapStringValue" do - map :fields, :string, :message, 1, "protobuf_nested_struct.Value" - end - add_message "protobuf_nested_struct.Value" do - oneof :kind do - optional :null_value, :enum, 1, "protobuf_nested_struct.NullValue" - optional :double_value, :double, 2 - optional :int_value, :int64, 3 - optional :string_value, :string, 4 - optional :bool_value, :bool, 5 - optional :date_value, :message, 6, "google.type.Date" - optional :timestamp_value, :message, 7, "google.protobuf.Timestamp" - optional :string_map_value, :message, 20, "protobuf_nested_struct.HashMapStringValue" - optional :list_value, :message, 21, "protobuf_nested_struct.ListValue" + + +descriptor_data = "\n#protobuf_nested_struct/struct.proto\x12\x16protobuf_nested_struct\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x16google/type/date.proto\"\xaa\x01\n\x12HashMapStringValue\x12\x46\n\x06\x66ields\x18\x01 \x03(\x0b\x32\x36.protobuf_nested_struct.HashMapStringValue.FieldsEntry\x1aL\n\x0b\x46ieldsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12,\n\x05value\x18\x02 \x01(\x0b\x32\x1d.protobuf_nested_struct.Value:\x02\x38\x01\"\x84\x03\n\x05Value\x12\x37\n\nnull_value\x18\x01 \x01(\x0e\x32!.protobuf_nested_struct.NullValueH\x00\x12\x16\n\x0c\x64ouble_value\x18\x02 \x01(\x01H\x00\x12\x13\n\tint_value\x18\x03 \x01(\x03H\x00\x12\x16\n\x0cstring_value\x18\x04 \x01(\tH\x00\x12\x14\n\nbool_value\x18\x05 \x01(\x08H\x00\x12\'\n\ndate_value\x18\x06 \x01(\x0b\x32\x11.google.type.DateH\x00\x12\x35\n\x0ftimestamp_value\x18\x07 \x01(\x0b\x32\x1a.google.protobuf.TimestampH\x00\x12\x46\n\x10string_map_value\x18\x14 \x01(\x0b\x32*.protobuf_nested_struct.HashMapStringValueH\x00\x12\x37\n\nlist_value\x18\x15 \x01(\x0b\x32!.protobuf_nested_struct.ListValueH\x00\x42\x06\n\x04kind\":\n\tListValue\x12-\n\x06values\x18\x01 \x03(\x0b\x32\x1d.protobuf_nested_struct.Value*\x1b\n\tNullValue\x12\x0e\n\nNULL_VALUE\x10\x00\x62\x06proto3" + +pool = Google::Protobuf::DescriptorPool.generated_pool + +begin + pool.add_serialized_file(descriptor_data) +rescue TypeError + # Compatibility code: will be removed in the next major version. + require 'google/protobuf/descriptor_pb' + parsed = Google::Protobuf::FileDescriptorProto.decode(descriptor_data) + parsed.clear_dependency + serialized = parsed.class.encode(parsed) + file = pool.add_serialized_file(serialized) + warn "Warning: Protobuf detected an import path issue while loading generated file #{__FILE__}" + imports = [ + ["google.type.Date", "google/type/date.proto"], + ["google.protobuf.Timestamp", "google/protobuf/timestamp.proto"], + ] + imports.each do |type_name, expected_filename| + import_file = pool.lookup(type_name).file_descriptor + if import_file.name != expected_filename + warn "- #{file.name} imports #{expected_filename}, but that import was loaded as #{import_file.name}" end end - add_message "protobuf_nested_struct.ListValue" do - repeated :values, :message, 1, "protobuf_nested_struct.Value" - end - add_enum "protobuf_nested_struct.NullValue" do - value :NULL_VALUE, 0 - end + warn "Each proto file must use a consistent fully-qualified name." + warn "This will become an error in the next major version." end module ProtobufNestedStruct - HashMapStringValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("protobuf_nested_struct.HashMapStringValue").msgclass - Value = Google::Protobuf::DescriptorPool.generated_pool.lookup("protobuf_nested_struct.Value").msgclass - ListValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("protobuf_nested_struct.ListValue").msgclass - NullValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("protobuf_nested_struct.NullValue").enummodule + HashMapStringValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("protobuf_nested_struct.HashMapStringValue").msgclass + Value = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("protobuf_nested_struct.Value").msgclass + ListValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("protobuf_nested_struct.ListValue").msgclass + NullValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("protobuf_nested_struct.NullValue").enummodule end