Module: RailwayIpc::MessageDecoders
- Defined in:
- lib/railway_ipc/message_decoders.rb
Constant Summary collapse
- ProtobufBinaryDecoder =
lambda do |type, | protobuf_msg = Base64.decode64() protobuf_klass = Kernel.const_get(type) protobuf_klass.decode(protobuf_msg) rescue Google::Protobuf::ParseError => e raise RailwayIpc::IncomingMessage::ParserError.new(e) rescue NameError RailwayIpc::Messages::Unknown.decode(protobuf_msg) end
- ProtobufJsonDecoder =
lambda do |type, | protobuf_klass = Kernel.const_get(type) protobuf_klass.new() rescue ArgumentError => e raise RailwayIpc::IncomingMessage::ParserError.new(e) rescue NameError # NOTE: I didn't realize this until I made this ProtobufJsonDecoder, but # the ProtobufBinaryDecoder will ignore any unknown keys -- which is # probably not what we want. I'm coding this the same way as the binary # protobuf version for consistency, but we should re-think how we want to # handle this situation. -BN RailwayIpc::Messages::Unknown.new( user_uuid: .fetch(:user_uuid, ''), correlation_id: .fetch(:correlation_id, ''), uuid: .fetch(:uuid, ''), context: .fetch(:context, {}) ) end