function ftds_dissector(buffer, pinfo, tree, ftds_protocol, offset)

local f_control_field = ProtoField.uint8("ftds_protocol.control_field", "Control Field", base.DEC)
local f_session_id = ProtoField.uint8("ftds_protocol.session_id", "File Transfer Session ID", base.DEC)
local f_segment_type = ProtoField.uint8("ftds_protocol.segment_type", "Segment Type", base.DEC)
local f_sequence_num_size = ProtoField.uint8("ftds_protocol.sequence_num_size", "Sequence Number Size", base.DEC)
local f_data_length_size = ProtoField.uint8("ftds_protocol.data_length_size", "Data Length Size", base.DEC)
local f_sequence_num = ProtoField.uint32("ftds_protocol.sequence_num", "Sequence Number", base.DEC)
local f_data_length = ProtoField.uint16("ftds_protocol.data_length", "Data Segment Length", base.DEC)
local f_data_bytes = ProtoField.bytes("ftds_protocol.data_bytes", "Data Bytes", base.SPACE)

-- Add the fields to the protocol
ftds_protocol.fields = {
    f_control_field,
    f_session_id,
    f_segment_type,
    f_sequence_num_size,
    f_data_length_size,
    f_sequence_num,
    f_data_length,
    f_data_bytes
}

local subtree = tree:add(ftds_protocol, buffer(),"FTDS")

local control_field = buffer(offset, 1):le_uint()
    subtree:add(f_control_field, control_field)
    offset = offset + 1


    -- Extract bits from Control Field
    local session_id = (control_field & 0x07)  -- Bits 0-2
    local segment_type = ((control_field >> 3) & 0x03)  -- Bits 3-4
    local seq_num_size = ((control_field >> 5) & 0x03)  -- Bits 5-6
    local data_length_size = ((control_field >> 7) & 0x01)  -- Bit 7

    -- Add the extracted fields to the tree
    local subtree1 = subtree:add(ftds_protocol, buffer(), "CONTROL FIELD DATA")
    subtree1:add(f_session_id, session_id)
    subtree1:add(f_segment_type, segment_type)
    subtree1:add(f_sequence_num_size, seq_num_size)
    subtree1:add(f_data_length_size, data_length_size)

    -- Sequence Number (1 to 4 bytes)
    local seq_num_length
    if seq_num_size == 0 then
      seq_num_length = 1
    elseif seq_num_size == 1 then
      seq_num_length = 2
    elseif seq_num_size == 2 then
      seq_num_length = 4
    end
    
    local sequence_num = buffer(offset, seq_num_length):le_uint()
    subtree:add(f_sequence_num, sequence_num)
    offset = offset + seq_num_length

    -- Data Segment Length (1 or 2 bytes)
    local data_length_length 
    if data_length_size == 0 then
      data_length_length = 1
    elseif data_length_size == 1 then
      data_length_length = 2
    end
    local data_length = buffer(offset, data_length_length):le_uint()
    subtree:add(f_data_length, data_length)
    offset = offset + data_length_length
    
    
    local chunk_size = 16  -- You can adjust this value for your display preferences

    -- Iterate through the buffer and add chunks to the protocol tree
    while offset < data_length do
        -- Get the chunk data
        local chunk = buffer(offset, chunk_size)

        -- Format the label with the byte range, e.g., "Data bytes [0001-0016]:"
        local label = string.format("Data bytes [%.4d-%.4d]:", offset , offset + chunk_size)

        -- Add the chunk to the tree, using the label
        local data_field = subtree:add(f_data_bytes, chunk)

        -- Update the offset for the next chunk
        offset = offset + chunk_size
     end
end