Module: HrrRbSsh::Message::Codable
- Included in:
- SSH_MSG_CHANNEL_CLOSE, SSH_MSG_CHANNEL_DATA, SSH_MSG_CHANNEL_EOF, SSH_MSG_CHANNEL_EXTENDED_DATA, SSH_MSG_CHANNEL_FAILURE, SSH_MSG_CHANNEL_OPEN, SSH_MSG_CHANNEL_OPEN_CONFIRMATION, SSH_MSG_CHANNEL_OPEN_FAILURE, SSH_MSG_CHANNEL_REQUEST, SSH_MSG_CHANNEL_SUCCESS, SSH_MSG_CHANNEL_WINDOW_ADJUST, SSH_MSG_DEBUG, SSH_MSG_DISCONNECT, SSH_MSG_GLOBAL_REQUEST, SSH_MSG_IGNORE, SSH_MSG_KEXDH_INIT, SSH_MSG_KEXDH_REPLY, SSH_MSG_KEXINIT, SSH_MSG_NEWKEYS, SSH_MSG_REQUEST_FAILURE, SSH_MSG_REQUEST_SUCCESS, SSH_MSG_SERVICE_ACCEPT, SSH_MSG_SERVICE_REQUEST, SSH_MSG_UNIMPLEMENTED, SSH_MSG_USERAUTH_FAILURE, SSH_MSG_USERAUTH_PK_OK, SSH_MSG_USERAUTH_REQUEST, SSH_MSG_USERAUTH_SUCCESS
- Defined in:
- lib/hrr_rb_ssh/message/codable.rb
Instance Method Summary collapse
- #common_definition ⇒ Object
- #conditional_definition(message) ⇒ Object
- #decode(payload, complementary_message = {}) ⇒ Object
- #decode_recursively(payload_io, message = nil) ⇒ Object
- #encode(message, complementary_message = {}) ⇒ Object
- #logger ⇒ Object
Instance Method Details
#common_definition ⇒ Object
14 15 16 |
# File 'lib/hrr_rb_ssh/message/codable.rb', line 14 def common_definition self::DEFINITION end |
#conditional_definition(message) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/hrr_rb_ssh/message/codable.rb', line 18 def conditional_definition .inject([]){ |a, (k,v)| field_name = k field_value = if v.instance_of? ::Proc then v.call else v end a + ((self::CONDITIONAL_DEFINITION rescue {}).fetch(field_name, {})[field_value] || []) } end |
#decode(payload, complementary_message = {}) ⇒ Object
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 |
# File 'lib/hrr_rb_ssh/message/codable.rb', line 35 def decode payload, ={} def decode_recursively payload_io, =nil if .class == Array and .size == 0 [] else definition = case when nil common_definition when Array conditional_definition() end = definition.map{ |data_type, field_name| [ field_name, HrrRbSsh::Transport::DataType[data_type].decode( payload_io ) ] } + decode_recursively(payload_io, ) end end payload_io = StringIO.new payload = decode_recursively(payload_io).to_h if .any? .merge! decode_recursively(payload_io, .to_a).to_h end logger.debug('decoded message: ' + .inspect) end |
#decode_recursively(payload_io, message = nil) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/hrr_rb_ssh/message/codable.rb', line 36 def decode_recursively payload_io, =nil if .class == Array and .size == 0 [] else definition = case when nil common_definition when Array conditional_definition() end = definition.map{ |data_type, field_name| [ field_name, HrrRbSsh::Transport::DataType[data_type].decode( payload_io ) ] } + decode_recursively(payload_io, ) end end |
#encode(message, complementary_message = {}) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/hrr_rb_ssh/message/codable.rb', line 26 def encode , ={} logger.debug('encoding message: ' + .inspect) definition = common_definition + conditional_definition(.merge ) definition.map{ |data_type, field_name| field_value = if [field_name].instance_of? ::Proc then [field_name].call else [field_name] end HrrRbSsh::Transport::DataType[data_type].encode( field_value ) }.join end |
#logger ⇒ Object
10 11 12 |
# File 'lib/hrr_rb_ssh/message/codable.rb', line 10 def logger @logger ||= HrrRbSsh::Logger.new self.name end |