Class: Baykit::BayServer::Docker::Ajp::Command::CmdSendBodyChunk

Inherits:
AjpCommand
  • Object
show all
Includes:
Baykit::BayServer::Docker::Ajp, Util
Defined in:
lib/baykit/bayserver/docker/ajp/command/cmd_send_body_chunk.rb

Constant Summary collapse

MAX_CHUNKLEN =
AjpPacket::MAX_DATA_LEN - 4

Instance Attribute Summary collapse

Attributes inherited from AjpCommand

#to_server

Instance Method Summary collapse

Methods inherited from AjpCommand

#pack_header

Constructor Details

#initialize(buf, ofs, len) ⇒ CmdSendBodyChunk

Returns a new instance of CmdSendBodyChunk.



28
29
30
31
32
33
# File 'lib/baykit/bayserver/docker/ajp/command/cmd_send_body_chunk.rb', line 28

def initialize(buf, ofs, len)
  super(AjpType::SEND_BODY_CHUNK, false)
  @chunk = buf
  @offset = ofs
  @length = len
end

Instance Attribute Details

#chunkObject (readonly)

Returns the value of attribute chunk.



22
23
24
# File 'lib/baykit/bayserver/docker/ajp/command/cmd_send_body_chunk.rb', line 22

def chunk
  @chunk
end

#lengthObject (readonly)

Returns the value of attribute length.



24
25
26
# File 'lib/baykit/bayserver/docker/ajp/command/cmd_send_body_chunk.rb', line 24

def length
  @length
end

#offsetObject (readonly)

Returns the value of attribute offset.



23
24
25
# File 'lib/baykit/bayserver/docker/ajp/command/cmd_send_body_chunk.rb', line 23

def offset
  @offset
end

Instance Method Details

#handle(handler) ⇒ Object



61
62
63
# File 'lib/baykit/bayserver/docker/ajp/command/cmd_send_body_chunk.rb', line 61

def handle(handler)
  return handler.handle_send_body_chunk(self)
end

#pack(pkt) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/baykit/bayserver/docker/ajp/command/cmd_send_body_chunk.rb', line 35

def pack(pkt) 
  if @length > MAX_CHUNKLEN
    raise RuntimeError.new("IllegalArgument")
  end 
  
  acc = pkt.new_ajp_data_accessor
  acc.put_byte(@type)
  acc.put_short(@length)
  acc.put_bytes(@chunk, @offset, @length)
  acc.put_byte(0)   # maybe document bug

  #  must be called from last line
  super
end

#unpack(pkt) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/baykit/bayserver/docker/ajp/command/cmd_send_body_chunk.rb', line 50

def unpack(pkt)
  acc = pkt.new_ajp_data_accessor
  acc.get_byte   # code
  @length = acc.get_short
  if @chunk == nil || @length > @chunk.length
    @chunk = StringUtil.alloc(@length)
  end

  acc.get_bytes(@chunk, 0, @length)
end