proto3を使用してgrpcサーバーを作成しています。それをRuby関数にコンパイルします。ActiveRecord-Protobuf gemを使用してActive Record Messageをprotobuf-message( "activerecord" .to_protoメソッドを呼び出して得たもの)に変換しました。しかし、rubyサーバを作成するためにprotobufメッセージを作成している間は、 "activerecord" .to_protoメッセージを渡すことができませんが、入力値の型を定義する一方、proto3ではメッセージとして定義することはできません。ハッシュ値のみを受け入れます。私たちの.to_protoオブジェクトを "activerecord" .to_proto.to_hashに変換する必要があります。これは無駄であり、grpcの最適性を低下させます。皮肉なことに、私たちはその最適性についてgrpcに移行しています。 .to_protoメッセージがproto3入力値定義と互換性があることを確認するために、proto3を使用してprotobufメッセージを定義する方法を提案できますか?protobufメッセージを定義して、protomsgをコンパイルして、アクティブなレコードのprotobufメッセージを入力パラメータとしてruby grpcコードに直接渡す方法はありますか?
これはアクティブレコードオブジェクトです。
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
これはクラスによっているProtobufメッセージであるAppPreference.last.to_protoに変換されます。
ruby入力パラメータの私のprotobuf定義は以下の通りです。
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;
}
このパラメータ「Index_Outputは」のみAppPreference.last.to_proto.to_hashを受け付けますが、私はそれは、入力としてAppPreference.last.to_protoを受け入れるようにしたいが。どのように私のprotobufコードを変更するのですか?