Class: WinRM::PSRP::MessageFragmenter

Inherits:
Object
  • Object
show all
Defined in:
lib/winrm/psrp/message_fragmenter.rb

Overview

PowerShell Remoting Protocol message fragmenter.

Constant Summary collapse

DEFAULT_BLOB_LENGTH =
32_768

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max_blob_length = DEFAULT_BLOB_LENGTH) ⇒ MessageFragmenter

Returns a new instance of MessageFragmenter.



24
25
26
27
# File 'lib/winrm/psrp/message_fragmenter.rb', line 24

def initialize(max_blob_length = DEFAULT_BLOB_LENGTH)
  @object_id = 0
  @max_blob_length = max_blob_length || DEFAULT_BLOB_LENGTH
end

Instance Attribute Details

#max_blob_lengthObject

Returns the value of attribute max_blob_length.



30
31
32
# File 'lib/winrm/psrp/message_fragmenter.rb', line 30

def max_blob_length
  @max_blob_length
end

#object_idObject (readonly)

Returns the value of attribute object_id.



29
30
31
# File 'lib/winrm/psrp/message_fragmenter.rb', line 29

def object_id
  @object_id
end

Instance Method Details

#fragment(message) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/winrm/psrp/message_fragmenter.rb', line 32

def fragment(message)
  @object_id += 1
  message_bytes = message.bytes
  bytes_fragmented = 0
  fragment_id = 0
  fragment = nil

  while bytes_fragmented < message_bytes.length
    last_byte = bytes_fragmented + max_blob_length
    last_byte = message_bytes.length if last_byte > message_bytes.length
    fragment = Fragment.new(
      object_id,
      message.bytes[bytes_fragmented..last_byte - 1],
      fragment_id,
      bytes_fragmented.zero?,
      last_byte == message_bytes.length
    )
    fragment_id += 1
    bytes_fragmented = last_byte
    yield fragment if block_given?
  end

  fragment
end