        # File lib/protocols/linetext2.rb, line 49
    49:                         def receive_data data
    50:                                 return unless (data and data.length > 0)
    51:
    52:                                 # Do this stuff in lieu of a constructor.
    53:                                 @lt2_mode ||= :lines
    54:                                 @lt2_delimiter ||= "\n"
    55:                                 @lt2_linebuffer ||= []
    56:
    57:                                 if @lt2_mode == :lines
    58:                                         if ix = data.index( @lt2_delimiter )
    59:                                                 @lt2_linebuffer << data[0...ix]
    60:                                                 ln = @lt2_linebuffer.join
    61:                                                 @lt2_linebuffer.clear
    62:                                                 if @lt2_delimiter == "\n"
    63:                                                         ln.chomp!
    64:                                                 end
    65:                                                 receive_line ln
    66:                                                 receive_data data[(ix+@lt2_delimiter.length)..-1]
    67:                                         else
    68:                                                 @lt2_linebuffer << data
    69:                                         end
    70:                                 elsif @lt2_mode == :text
    71:                                         if @lt2_textsize
    72:                                                 needed = @lt2_textsize - @lt2_textpos
    73:                                                 will_take = if data.length > needed
    74:                                                         needed
    75:                                                 else
    76:                                                         data.length
    77:                                                 end
    78:
    79:                                                 @lt2_textbuffer << data[0...will_take]
    80:                                                 tail = data[will_take..-1]
    81:
    82:                                                 @lt2_textpos += will_take
    83:                                                 if @lt2_textpos >= @lt2_textsize
    84:                                                         # Reset line mode (the default behavior) BEFORE calling the
    85:                                                         # receive_binary_data. This makes it possible for user code
    86:                                                         # to call set_text_mode, enabling chains of text blocks
    87:                                                         # (which can possibly be of different sizes).
    88:                                                         set_line_mode
    89:                                                         receive_binary_data @lt2_textbuffer.join
    90:                                                         receive_end_of_binary_data
    91:                                                 end
    92:
    93:                                                 receive_data tail
    94:                                         else
    95:                                                 receive_binary_data data
    96:                                         end
    97:                                 end
    98:                         end