【发布时间】:2018-10-14 09:30:46
【问题描述】:
我有一个像这样编译的 Ruby protobuf 消息:
require 'google/protobuf'
Google::Protobuf::DescriptorPool.generated_pool.build do
add_message "PingPacket" do
optional :message_counter, :int32, 1
optional :message_type, :enum, 2, "PingPacket.MessageType"
end
add_enum "PingPacket.MessageType" do
value :REPORT, 0
value :LOW_BATTERY, 1
value :LOCATE_REQUEST, 2
value :CHECK_IN, 3
value :SOS, 4
value :RESTING, 5
value :MOVING, 6
value :EVENT, 7
value :SYSTEM_TEST, 8
end
end
PingPacket = Google::Protobuf::DescriptorPool.generated_pool.lookup("PingPacket").msgclass
PingPacket::MessageType = Google::Protobuf::DescriptorPool.generated_pool.lookup("PingPacket.MessageType").enummodule
我试图获取一个包含所有 MessageType 值的数组。我已经尝试了明显的:
PingPacket::MessageType.enums
PingPacket::MessageType.values
PingPacket::MessageType.to_s
但是没有任何效果。我怎样才能得到这些值?
【问题讨论】:
标签: ruby protocol-buffers