I have a pcap file where each frame describes a read() or write() system call to a serial device. I'm trying to write a dissector for the serial protocol. Because a read() call might happen before there is a fully-formed message in the buffer, or perhaps there might be more than one, I need to implement re-assembly of fragmented messages.
My data is not encapsulated in TCP, so I have not used dissect_tcp_pdus().
My broken approach is to start with a global reassembly_buffer = ByteArray.new(), and then each time my proto.dissector() implementation is called, append the incoming data to the buffer, and then try to consume any full messages in the buffer.
For debugging, I output the buffer contents before appending the current frame. Surprisingly, when I look at the first frame in the file, expecting the buffer to be empty, it is not. I think this may be because my dissector is called multiple times per frame, so when the frame is revisited, the buffer already has contents.
tree:add(proto, tvb(), "Buffer before append: " .. reassembly_buffer:tohex())
reassembly_buffer:append(tvb:bytes())
Put another way: I'm not sure how to track state properly so that the start state of one dissection pass is not affected by the end state of the previous pass. (I'm sure this also dovetails with the Conversation API but I couldn't readily find an example of how to properly use it.)
There is documentation on reassembling split UDP packets but it's for the C API, I'll attempt to port it to Lua.