Sha256: 7118ed525e3228167708a5bb1ff069314e66466beaf6f98988d3289cb238b9da

Contents?: true

Size: 1.2 KB

Versions: 36

Compression:

Stored size: 1.2 KB

Contents

# This class represents all the messages either received by chunks from attach
class Docker::Messages

  attr_accessor :buffer, :stdout_messages, :stderr_messages

  def initialize(stdout_messages = [], stderr_messages = [], buffer = "")
    @stdout_messages = stdout_messages
    @stderr_messages = stderr_messages
    @buffer = buffer
  end

  def add_message(source, message)
    case source
    when 1
      stdout_messages << message
    when 2
      stderr_messages << message
    end
  end

  def get_message(raw_text)
    header = raw_text.slice!(0,8)
    if header.length < 8
      @buffer = header
      return
    end
    type, length = header.unpack("CxxxN")

    message = raw_text.slice!(0,length)
    if message.length < length
      @buffer = header + message
    else
      add_message(type, message)
    end
  end

  def append(messages)
    @stdout_messages += messages.stdout_messages
    @stderr_messages += messages.stderr_messages
  end

  # Method to break apart application/vnd.docker.raw-stream headers
  def decipher_messages(body)
    raw_text = buffer + body.dup
    messages = Docker::Messages.new
    while !raw_text.empty?
      messages.get_message(raw_text)
    end

    messages
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
docker-api-1.13.7 lib/docker/messages.rb
docker-api-1.13.6 lib/docker/messages.rb
docker-api-1.13.5 lib/docker/messages.rb
docker-api-1.13.4 lib/docker/messages.rb
docker-api-1.13.3 lib/docker/messages.rb
docker-api-1.13.2 lib/docker/messages.rb
docker-api-1.13.1 lib/docker/messages.rb
docker-api-1.13.0 lib/docker/messages.rb
docker-api-1.12.0 lib/docker/messages.rb
docker-api-1.11.2 lib/docker/messages.rb
docker-api-1.11.1 lib/docker/messages.rb
docker-api-1.11.0 lib/docker/messages.rb
docker-api-1.10.11 lib/docker/messages.rb
docker-api-1.10.10 lib/docker/messages.rb
docker-api-1.10.9 lib/docker/messages.rb
docker-api-1.10.8 lib/docker/messages.rb
docker-api-1.10.7 lib/docker/messages.rb
docker-api-1.10.6 lib/docker/messages.rb
docker-api-1.10.5 lib/docker/messages.rb
docker-api-1.10.4 lib/docker/messages.rb