Class: Docker::Messages

Inherits:
Object
  • Object
show all
Defined in:
lib/docker/messages.rb

Overview

This class represents all the messages either received by chunks from attach

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stdout_messages = [], stderr_messages = [], all_messages = [], buffer = "") ⇒ Messages

Returns a new instance of Messages.



6
7
8
9
10
11
12
13
14
# File 'lib/docker/messages.rb', line 6

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

Instance Attribute Details

#all_messagesObject

Returns the value of attribute all_messages.



4
5
6
# File 'lib/docker/messages.rb', line 4

def all_messages
  @all_messages
end

#bufferObject

Returns the value of attribute buffer.



4
5
6
# File 'lib/docker/messages.rb', line 4

def buffer
  @buffer
end

#stderr_messagesObject

Returns the value of attribute stderr_messages.



4
5
6
# File 'lib/docker/messages.rb', line 4

def stderr_messages
  @stderr_messages
end

#stdout_messagesObject

Returns the value of attribute stdout_messages.



4
5
6
# File 'lib/docker/messages.rb', line 4

def stdout_messages
  @stdout_messages
end

Instance Method Details

#add_message(source, message) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/docker/messages.rb', line 16

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

#append(messages) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/docker/messages.rb', line 42

def append(messages)
  @stdout_messages += messages.stdout_messages
  @stderr_messages += messages.stderr_messages
  @all_messages += messages.all_messages
  messages.clear

  @all_messages
end

#clearObject



51
52
53
54
55
# File 'lib/docker/messages.rb', line 51

def clear
  stdout_messages.clear
  stderr_messages.clear
  all_messages.clear
end

#decipher_messages(body) ⇒ Object

Method to break apart application/vnd.docker.raw-stream headers



58
59
60
61
62
63
64
65
66
# File 'lib/docker/messages.rb', line 58

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

#get_message(raw_text) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/docker/messages.rb', line 26

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