Class: RBus::Message::Writer
- Inherits:
-
Object
- Object
- RBus::Message::Writer
- Defined in:
- lib/rbus/message/writer.rb
Overview
Writes messages to the Bus via a Transport
Instance Method Summary collapse
-
#initialize(transport) ⇒ Writer
constructor
A new instance of Writer.
-
#send_message(message) ⇒ Object
Marshal and write message.
Constructor Details
#initialize(transport) ⇒ Writer
Returns a new instance of Writer.
29 30 31 |
# File 'lib/rbus/message/writer.rb', line 29 def initialize(transport) @transport = transport end |
Instance Method Details
#send_message(message) ⇒ Object
Marshal and write message
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rbus/message/writer.rb', line 34 def () # The marshaling always uses native encoding, so # let's find it. endian = ([1].pack('I') == "\1\0\0\0") ? ?l : ?B body = '' args = .arguments # Got arguments for the body? Marshal. unless args.nil? || args.empty? args.extend(MarshalMixin) body = args.dbus_marshal(.signature) end hf = .header_fields # Put together the header h_array = [endian, .type, .flags] + [VERSION::PROTOCOL, body.length, .serial, hf] # Marshal h_array.extend(MarshalMixin) header = h_array.dbus_marshal('yyyyuua(yv)') # Pad header += "\0" * (-header.length & 7) Log.debug(header + body) # Send @transport.send(header + body) end |