title: Reassemble PDUs in lua wireshark dissector
body: <p>In a system I have a custom protocol and I would like to implement a Wireshark dissector so that I can use Wireshark to analyze the communication.</p>
  
  <ul>
  <li><p>Objects are sent over the protocol, let us call them "Messages". Each message can be large, maybe up to 100 MB, they can also be very small for example 50 byte.</p></li>
  <li><p>Each Message is split up in chunks of around 1 kB and tagged with a sequence number and a guid message id and those can be used at the other end to reassemble the messages.</p></li>
  </ul>
  
  <p>So far I have successfully made a dissector that will individually log all chunks to Wireshark but I want to take this further and also log all messages (chunks assembled into messages) in Wireshark. Can this be done and how? Is it maybe possible to implement a dissector on top of the dissector I have developed below?</p>
  
  <p>If it is possible to implement a dissector on top of the one below, how can I make sure it will only analyze myproto PDUs? The dissector below triggers on a specific tcp port, but that is not going to work for the second phase dissector...</p>
  
  <pre><code>myproto_proto = Proto("myproto", "My Protocol")
  
  function myproto_proto.dissector(buffer, pinfo, tree)
      pinfo.cols.protocol = "myproto"
  
      local message_length = buffer(0, 4):le_uint()+4
  
      if message_length&gt;pinfo.len then
          pinfo.desegment_len = message_length
          pinfo.desegment_offset = 0
          return;
      end
  
      local subtree = tree:add(myproto_proto, buffer(), "My Protocol Data")
      local packet = subtree:add(buffer(0, message_length), "Chunk")
      packet:add(buffer(0, 4), "Packet length: " .. buffer(0, 4):le_uint())
      packet:add(buffer(32, 16), "Message ID")
      packet:add(buffer(48, 4), "Block ID: " .. buffer(48, 4):le_uint())
      packet:add(buffer(52, 4), "Max Block ID: " .. buffer(52, 4):le_uint())
      packet:add(buffer(68, message_length-68-20), "Data")
  
      pinfo.desegment_len = 0
      pinfo.desegment_offset = message_length
      return
  
  end
  
  tcp_table = DissectorTable.get("tcp.port")
  tcp_table:add(1234, myproto_proto)
  </code></pre>