0

We are creating a grpc server using proto3. and compiling it into a ruby function.We have converted the Active Record Message into a protobuf-message (got by calling the "activerecord".to_proto method) using ActiveRecord-Protobuf gem. However while creating the protobuf message to create the ruby server we are not able to pass the "activerecord".to_proto message as while defining the type of the input value we have no other go but to define it as a message in proto3 and hence it only accepts a hash value. inorder for which we have to convert our .to_proto object to "activerecord".to_proto.to_hash. This is futile and reduces the optimality of grpc. Ironically we are shifting to grpc for its optimality. Could you suggest how to define the protobuf message (using proto3) to ensure the "activerecord".to_proto message is compatible with the proto3 input value definition.

This is the active record object.

class AppPreferenceMessage < ::Protobuf::Message
optional ::Protobuf::Field::Int64Field, :id, 1
optional ::Protobuf::Field::StringField, :preference_key, 2
optional ::Protobuf::Field::StringField, :value, 3
optional ::Protobuf::Field::StringField, :value_type, 4
optional ::Protobuf::Field::Int64Field, :vaccount_id, 5  
end

This is converted to AppPreference.last.to_proto which is a protobuf message by class.

my protobuf definition of the ruby input parameters is as follows.

syntax="proto3";
service App_Preferences{
rpc Index(Empty) returns (Index_Output){}
}
message Index_Output{
int64 id=1;
string preference_key=2;
string value=3;
string value_type=4;
int64 vaccount_id = 5;  
}

This parameter "Index_Output" only accepts AppPreference.last.to_proto.to_hash but however I want it to accept AppPreference.last.to_proto as an input. How do i change my protobuf code.

susheel
  • 36
  • 6

1 Answers1

0

I think you would like to convert this AppPreferenceMessage object to a protobuf message, and then pass that to an rpc method which has been created from a separate proto file? Also I'm unfamiliar with what AppPreferenceMessage.to_proto returns, is it serialized bytes?

I'm not sure that I'm completely clear, but it sounds like you might not want to use the grpc-protobuf stub and service code generators, as these are designed with passing of ruby protobuf objects in mind.

There are some examples in https://github.com/grpc/grpc/tree/master/examples/ruby/without_protobuf that might be useful if skipping the grpc-protobuf code gen is what you need.

apolcyn
  • 124
  • 3