Class: LLM::Transport::StreamDecoder Private

Inherits:
Object
  • Object
show all
Defined in:
lib/llm/transport/stream_decoder.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

LLM::Transport::StreamDecoder incrementally decodes streamed HTTP response bodies into parser events.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parser) ⇒ LLM::Transport::StreamDecoder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • parser (#parse!, #body)


18
19
20
21
22
23
# File 'lib/llm/transport/stream_decoder.rb', line 18

def initialize(parser)
  @buffer = +""
  @cursor = 0
  @data = []
  @parser = parser
end

Instance Attribute Details

#parserObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



13
14
15
# File 'lib/llm/transport/stream_decoder.rb', line 13

def parser
  @parser
end

Instance Method Details

#<<(chunk) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:

  • chunk (String)


28
29
30
31
# File 'lib/llm/transport/stream_decoder.rb', line 28

def <<(chunk)
  @buffer << chunk
  each_line { handle_line(_1) }
end

#bodyObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



35
36
37
# File 'lib/llm/transport/stream_decoder.rb', line 35

def body
  parser.body
end

#freevoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.



41
42
43
44
45
46
# File 'lib/llm/transport/stream_decoder.rb', line 41

def free
  @buffer.clear
  @cursor = 0
  @data.clear
  parser.free if parser.respond_to?(:free)
end