Class: Baykit::BayServer::Docker::Fcgi::Command::CmdParams

Inherits:
FcgCommand
  • Object
show all
Includes:
Util
Defined in:
lib/baykit/bayserver/docker/fcgi/command/cmd_params.rb

Instance Attribute Summary collapse

Attributes inherited from FcgCommand

#req_id

Instance Method Summary collapse

Methods inherited from FcgCommand

#pack_header

Constructor Details

#initialize(req_id) ⇒ CmdParams

Returns a new instance of CmdParams.



67
68
69
70
# File 'lib/baykit/bayserver/docker/fcgi/command/cmd_params.rb', line 67

def initialize(req_id)
  super(FcgType::PARAMS, req_id)
  @params = []
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



65
66
67
# File 'lib/baykit/bayserver/docker/fcgi/command/cmd_params.rb', line 65

def params
  @params
end

Instance Method Details

#add_param(name, value) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
# File 'lib/baykit/bayserver/docker/fcgi/command/cmd_params.rb', line 140

def add_param(name, value)
  if name == nil
    raise RuntimeError.new("nil argument")
  end

  if value == nil
    value = ""
  end

  @params.append([name, value])
end

#handle(cmd_handler) ⇒ Object



109
110
111
# File 'lib/baykit/bayserver/docker/fcgi/command/cmd_params.rb', line 109

def handle(cmd_handler)
  return cmd_handler.handle_params(self)
end

#pack(pkt) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/baykit/bayserver/docker/fcgi/command/cmd_params.rb', line 90

def pack(pkt)
  acc = pkt.new_data_accessor
  @params.each do |nv|
    name = nv[0]
    value = nv[1]
    name_len = name.length
    value_len = value.length

    write_length(name_len, acc)
    write_length(value_len, acc)

    acc.put_string(name)
    acc.put_string(value)
  end

  # must be called from last line
  super
end

#read_length(acc) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
# File 'lib/baykit/bayserver/docker/fcgi/command/cmd_params.rb', line 114

def read_length(acc)
  len = acc.get_byte
  if len >> 7 == 0
    return len
  else
    len2 = acc.get_byte
    len3 = acc.get_byte
    len4 = acc.get_byte
    return ((len & 0x7f) << 24) | (len2 << 16) | (len3 << 8) | len4
  end
end

#to_sObject



152
153
154
# File 'lib/baykit/bayserver/docker/fcgi/command/cmd_params.rb', line 152

def to_s()
  "FcgCmdParams#{@params}"
end

#unpack(pkt) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/baykit/bayserver/docker/fcgi/command/cmd_params.rb', line 72

def unpack(pkt)
  super
  acc = pkt.new_data_accessor
  while acc.pos < pkt.data_len
    name_len = read_length(acc)
    value_len = read_length(acc)

    name = StringUtil.alloc(name_len)
    acc.get_bytes(name, 0, name_len)

    value = StringUtil.alloc(value_len)
    acc.get_bytes(value, 0, value_len)

    BayLog.trace("Params: %s=%s", name, value)
    add_param(name, value)
  end
end

#write_length(len, acc) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/baykit/bayserver/docker/fcgi/command/cmd_params.rb', line 126

def write_length(len, acc)
  if len >> 7 == 0
    acc.put_byte(len)
  else
    len1 = (len >> 24 & 0xFF) | 0x80
    len2 = len >> 16 & 0xFF
    len3 = len >> 8 & 0xFF
    len4 = len & 0xFF
    buf = StringUtil.alloc(4)
    buf << len1 << len2 << len3 << len4
    acc.put_bytes(buf)
  end
end