You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What version of protobuf and what language are you using?
Version: v3.11.4
Language: Ruby (v2.6.5)
What operating system (Linux, Windows, ...) and version?
MacOS 10.15
What runtime / compiler are you using (e.g., python version or gcc version)
What did you do?
Steps to reproduce the behavior:
Load IRB and require protobuf value wrappers: require "google/protobuf/wrappers_pb"
Create new Int64Value object with value set to 0: v = Google::Protobuf::Int64Value.new(value: 0)
Convert v to serialized string and back to object: new_v = Google::Protobuf::Int64Value.decode(v.to_proto)
Observer that new_v is nil instead of Int64Value: v == new_v # => false
What did you expect to see
I expected new_v to be Int64Value with value set to 0
What did you see instead? new_v is nil
Bigger problem
My issue actually is more complicated but the root cause boils down to this issue above. To see how this issue is actually causing weird exceptions within the protobuf gem itself, consider a new message type:
message Value {
oneof types {
google.protobuf.StringValue id = 1;
google.protobuf.Int64Value integer = 2;
}
}
When compiled into ruby code, we will get code similar to one below:
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: value.proto
require 'google/protobuf'
require 'google/protobuf/wrappers_pb'
Google::Protobuf::DescriptorPool.generated_pool.build do
add_file("value.proto", :syntax => :proto3) do
add_message "Value" do
oneof :types do
optional :id, :message, 1, "google.protobuf.StringValue"
optional :integer, :message, 2, "google.protobuf.Int64Value"
end
end
end
end
Value = Google::Protobuf::DescriptorPool.generated_pool.lookup("Value").msgclass
Now if you try to create new Value with integer set to 0, you will not be able to decode proto version of it:
v = Value.new(integer: Google::Protobuf::Int64Value.new(value: 0))
Value.decode(v.to_proto) # => Google::Protobuf::TypeError (Expected number type for integral field 'value' (given FalseClass).)
The text was updated successfully, but these errors were encountered:
What version of protobuf and what language are you using?
Version: v3.11.4
Language: Ruby (v2.6.5)
What operating system (Linux, Windows, ...) and version?
MacOS 10.15
What runtime / compiler are you using (e.g., python version or gcc version)
What did you do?
Steps to reproduce the behavior:
require "google/protobuf/wrappers_pb"
v = Google::Protobuf::Int64Value.new(value: 0)
v
to serialized string and back to object:new_v = Google::Protobuf::Int64Value.decode(v.to_proto)
new_v
is nil instead of Int64Value:v == new_v # => false
What did you expect to see
I expected
new_v
to beInt64Value
withvalue
set to0
What did you see instead?
new_v
isnil
Bigger problem
My issue actually is more complicated but the root cause boils down to this issue above. To see how this issue is actually causing weird exceptions within the protobuf gem itself, consider a new message type:
When compiled into ruby code, we will get code similar to one below:
Now if you try to create new
Value
with integer set to 0, you will not be able to decode proto version of it:The text was updated successfully, but these errors were encountered: