Class: RailwayIpc::Rabbitmq::Payload
- Inherits:
-
Object
- Object
- RailwayIpc::Rabbitmq::Payload
- Defined in:
- lib/railway_ipc/rabbitmq/payload.rb
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(type, message) ⇒ Payload
constructor
A new instance of Payload.
-
#to_json ⇒ Object
rubocop:disable Lint/ToJSON.
Constructor Details
#initialize(type, message) ⇒ Payload
Returns a new instance of Payload.
26 27 28 29 |
# File 'lib/railway_ipc/rabbitmq/payload.rb', line 26 def initialize(type, ) @type = type @message = end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
6 7 8 |
# File 'lib/railway_ipc/rabbitmq/payload.rb', line 6 def @message end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/railway_ipc/rabbitmq/payload.rb', line 6 def type @type end |
Class Method Details
.decode(message) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/railway_ipc/rabbitmq/payload.rb', line 19 def self.decode() = JSON.parse() type = ['type'] = Base64.decode64(['encoded_message']) new(type, ) end |
.encode(message) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/railway_ipc/rabbitmq/payload.rb', line 8 def self.encode() type = .class.to_s begin = Base64.encode64(.class.encode()) # TODO: also need to rescue Google::Protobuf::TypeError rescue NoMethodError raise RailwayIpc::InvalidProtobuf.new("Message #{} is not a valid protobuf") end new(type, ).to_json end |
Instance Method Details
#to_json ⇒ Object
rubocop:disable Lint/ToJSON
32 33 34 35 36 37 |
# File 'lib/railway_ipc/rabbitmq/payload.rb', line 32 def to_json { type: type, encoded_message: }.to_json end |