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.



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

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.



6
7
8
# File 'lib/docker/messages.rb', line 6

def all_messages
  @all_messages
end

#bufferObject

Returns the value of attribute buffer.



6
7
8
# File 'lib/docker/messages.rb', line 6

def buffer
  @buffer
end

#stderr_messagesObject

Returns the value of attribute stderr_messages.



6
7
8
# File 'lib/docker/messages.rb', line 6

def stderr_messages
  @stderr_messages
end

#stdout_messagesObject

Returns the value of attribute stdout_messages.



6
7
8
# File 'lib/docker/messages.rb', line 6

def stdout_messages
  @stdout_messages
end

Instance Method Details

#add_message(source, message) ⇒ Object



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

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



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

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

  @all_messages
end

#clearObject



53
54
55
56
57
# File 'lib/docker/messages.rb', line 53

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



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

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



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

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