Method: Racket::Racket#pack

Defined in:
lib/racket/racket.rb

#packObject

Assemble all the pieces of this Racket as a string, ready for sending.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/racket/racket.rb', line 65

def pack
  last_payload = ""
  orig_payload = ""
  @layers.compact.reverse.each do |l|
    # save the original payload
    orig_payload = l.payload
    # tack on the last payload in
    # case fix needs it...
    l.payload += last_payload
    if (l.autofix?)
      l.fix!
    end

    if (l.payload == orig_payload + last_payload)
      # payload was not modified by fix, so reset it to what
      # it used to be
      l.payload = orig_payload
    else
      # payload was modified by fix.  chop off what we added.
      # XXX: this assumes that what we added is still at the end.  
      # XXX: this is not always true
      l.payload = l.payload.slice(0, l.payload.length - last_payload.length)
    end

    # save this layer for the next guy
    last_payload += l
    
  end
  
  payload = ""
  @layers.compact.each do |l|
    payload += l
  end
  payload
end