Ruby on rails 如何定义protobuf消息,通过编译protomsg将活动记录protobuf消息作为输入参数直接传递到ruby grpc代码中?

Ruby on rails 如何定义protobuf消息,通过编译protomsg将活动记录protobuf消息作为输入参数直接传递到ruby grpc代码中?,ruby-on-rails,ruby,protocol-buffers,grpc,proto3,Ruby On Rails,Ruby,Protocol Buffers,Grpc,Proto3,我们正在使用proto3创建grpc服务器。并将其编译成ruby函数。我们使用activerecord protobuf gem将activerecord消息转换为protobuf消息(通过调用“activerecord”.to_proto方法获得)。但是,在创建protobuf消息以创建ruby服务器时,我们无法传递“activerecord”。在定义输入值类型时,我们除了将其定义为proto3中的消息外,别无选择,因此它只接受散列值。我们必须将.to\u proto对象转换为“activer

我们正在使用proto3创建grpc服务器。并将其编译成ruby函数。我们使用activerecord protobuf gem将activerecord消息转换为protobuf消息(通过调用“activerecord”.to_proto方法获得)。但是,在创建protobuf消息以创建ruby服务器时,我们无法传递“activerecord”。在定义输入值类型时,我们除了将其定义为proto3中的消息外,别无选择,因此它只接受散列值。我们必须将.to\u proto对象转换为“activerecord”.to\u proto.to\u散列。这是徒劳的,降低了grpc的最优性。具有讽刺意味的是,我们正转向grpc以获得其最佳性。您能否建议如何定义protobuf消息(使用proto3)以确保“activerecord”。to_proto消息与proto3输入值定义兼容

这是活动记录对象

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

此参数“Index_Output”仅接受AppPreference.last.to_proto.to_散列,但我希望它接受AppPreference.last.to_proto作为输入。如何更改protobuf代码

我认为您希望将此AppPreferenceMessage对象转换为protobuf消息,然后将其传递给从单独的proto文件创建的rpc方法?另外,我不知道AppPreferenceMessage.to_proto返回什么,它是序列化字节吗

我不确定我是否完全清楚,但听起来您可能不想使用grpc protobuf存根和服务代码生成器,因为它们的设计考虑了ruby protobuf对象的传递

如果您需要跳过grpc 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;  
}