Module: LogCourier::Protocol

Defined in:
lib/log-courier/protocol.rb

Overview

Protocol

Class Method Summary collapse

Class Method Details

.parse_helo_vers(data) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/log-courier/protocol.rb', line 24

def self.parse_helo_vers(data)
  data = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" if data.length < 8

  flags, major_version, minor_version, patch_version, client = data.unpack('NNNNA4')
  client = case client
           when 'LCOR'
             'Log Courier'
           when 'LCVR'
             'Log Carver'
           when 'RYLC'
             'Ruby Log Courier'
           else
             'Unknown'
           end

  if major_version != 0 || minor_version != 0 || patch_version != 0
    version = "#{major_version}.#{minor_version}.#{patch_version}"
    client_version = "#{client} v#{version}"
  else
    version = ''
    client_version = client
  end

  {
    flags: flags,
    major_version: major_version,
    minor_version: minor_version,
    patch_version: patch_version,
    client: client,
    version: version,
    client_version: client_version,
  }
end