-- This file is generated by tools/json2lua.js

local db = require('ffxiv_db')
local ffxiv_ipc_examine = Proto("ffxiv_ipc_examine", "FFXIV-IPC Examine")

local examine_fields = {
  unknown0           = ProtoField.uint16("ffxiv_ipc_examine.unknown0", "Unknown0", base.DEC),
  class_job          = ProtoField.int8("ffxiv_ipc_examine.class_job", "ClassJob", base.DEC, db.ClassJob),
  level              = ProtoField.int8("ffxiv_ipc_examine.level", "Level", base.DEC),
  padding            = ProtoField.uint16("ffxiv_ipc_examine.padding", "padding", base.DEC),
  title              = ProtoField.uint16("ffxiv_ipc_examine.title", "Title", base.DEC, db.TitleMasculine),
  grand_company      = ProtoField.int8("ffxiv_ipc_examine.grand_company", "grandCompany", base.DEC),
  grand_company_rank = ProtoField.int8("ffxiv_ipc_examine.grand_company_rank", "grandCompanyRank", base.DEC),
  unknown_a          = ProtoField.bytes("ffxiv_ipc_examine.unknown_a", "unknownA", base.NONE),
  u6_from_pspawn     = ProtoField.uint32("ffxiv_ipc_examine.u6_from_pspawn", "u6_fromPSpawn", base.DEC),
  u7_from_pspawn     = ProtoField.uint32("ffxiv_ipc_examine.u7_from_pspawn", "u7_fromPSpawn", base.DEC),
  padding1           = ProtoField.bytes("ffxiv_ipc_examine.padding1", "padding1", base.NONE),
  main_weapon_model  = ProtoField.uint64("ffxiv_ipc_examine.main_weapon_model", "mainWeaponModel", base.DEC),
  sec_weapon_model   = ProtoField.uint64("ffxiv_ipc_examine.sec_weapon_model", "secWeaponModel", base.DEC),
  unknown2           = ProtoField.uint16("ffxiv_ipc_examine.unknown2", "unknown2", base.DEC),
  world              = ProtoField.uint16("ffxiv_ipc_examine.world", "World", base.DEC, db.World),
  unknown30          = ProtoField.bytes("ffxiv_ipc_examine.unknown30", "unknown30", base.NONE),
  nickname           = ProtoField.string("ffxiv_ipc_examine.nickname", "Nickname", base.UNICODE),
}

ffxiv_ipc_examine.fields = examine_fields

function ffxiv_ipc_examine.dissector(tvbuf, pktinfo, root)
  local tree = root:add(ffxiv_ipc_examine, tvbuf)
  pktinfo.cols.info:set("Examine")

  local len = tvbuf:len()

  -- dissect the unknown0 field
  local unknown0_tvbr = tvbuf:range(0, 2)
  local unknown0_val  = unknown0_tvbr:le_uint()
  tree:add_le(examine_fields.unknown0, unknown0_tvbr, unknown0_val)

  -- dissect the class_job field
  local class_job_tvbr = tvbuf:range(2, 1)
  local class_job_val  = class_job_tvbr:le_int()
  tree:add_le(examine_fields.class_job, class_job_tvbr, class_job_val)

  -- dissect the level field
  local level_tvbr = tvbuf:range(3, 1)
  local level_val  = level_tvbr:le_int()
  tree:add_le(examine_fields.level, level_tvbr, level_val)

  -- dissect the padding field
  local padding_tvbr = tvbuf:range(4, 2)
  local padding_val  = padding_tvbr:le_uint()
  tree:add_le(examine_fields.padding, padding_tvbr, padding_val)

  -- dissect the title field
  local title_tvbr = tvbuf:range(6, 2)
  local title_val  = title_tvbr:le_uint()
  tree:add_le(examine_fields.title, title_tvbr, title_val)

  -- dissect the grand_company field
  local grand_company_tvbr = tvbuf:range(8, 1)
  local grand_company_val  = grand_company_tvbr:le_int()
  tree:add_le(examine_fields.grand_company, grand_company_tvbr, grand_company_val)

  -- dissect the grand_company_rank field
  local grand_company_rank_tvbr = tvbuf:range(9, 1)
  local grand_company_rank_val  = grand_company_rank_tvbr:le_int()
  tree:add_le(examine_fields.grand_company_rank, grand_company_rank_tvbr, grand_company_rank_val)

  -- dissect the unknown_a field
  local unknown_a_tvbr = tvbuf:range(10, 6)
  local unknown_a_val  = unknown_a_tvbr:raw(10)
  tree:add(examine_fields.unknown_a, unknown_a_tvbr, unknown_a_val)

  -- dissect the u6_from_pspawn field
  local u6_from_pspawn_tvbr = tvbuf:range(16, 4)
  local u6_from_pspawn_val  = u6_from_pspawn_tvbr:le_uint()
  tree:add_le(examine_fields.u6_from_pspawn, u6_from_pspawn_tvbr, u6_from_pspawn_val)

  -- dissect the u7_from_pspawn field
  local u7_from_pspawn_tvbr = tvbuf:range(20, 4)
  local u7_from_pspawn_val  = u7_from_pspawn_tvbr:le_uint()
  tree:add_le(examine_fields.u7_from_pspawn, u7_from_pspawn_tvbr, u7_from_pspawn_val)

  -- dissect the padding1 field
  local padding1_tvbr = tvbuf:range(24, 8)
  local padding1_val  = padding1_tvbr:raw(24)
  tree:add(examine_fields.padding1, padding1_tvbr, padding1_val)

  -- dissect the main_weapon_model field
  local main_weapon_model_tvbr = tvbuf:range(32, 8)
  local main_weapon_model_val  = main_weapon_model_tvbr:le_uint64()
  tree:add_le(examine_fields.main_weapon_model, main_weapon_model_tvbr, main_weapon_model_val)

  -- dissect the sec_weapon_model field
  local sec_weapon_model_tvbr = tvbuf:range(40, 8)
  local sec_weapon_model_val  = sec_weapon_model_tvbr:le_uint64()
  tree:add_le(examine_fields.sec_weapon_model, sec_weapon_model_tvbr, sec_weapon_model_val)

  -- dissect the unknown2 field
  local unknown2_tvbr = tvbuf:range(48, 2)
  local unknown2_val  = unknown2_tvbr:le_uint()
  tree:add_le(examine_fields.unknown2, unknown2_tvbr, unknown2_val)

  -- dissect the world field
  local world_tvbr = tvbuf:range(50, 2)
  local world_val  = world_tvbr:le_uint()
  tree:add_le(examine_fields.world, world_tvbr, world_val)

  -- dissect the unknown30 field
  local unknown30_tvbr = tvbuf:range(52, 12)
  local unknown30_val  = unknown30_tvbr:raw(52)
  tree:add(examine_fields.unknown30, unknown30_tvbr, unknown30_val)

  -- dissect examine_item_data
  local examine_item_data_dissector = Dissector.get('ffxiv_ipc_examine_item_data')
  local examine_item_data_pos = 64
  local examine_item_data_len = 40
  local examine_item_data_count = 14

  while examine_item_data_pos + examine_item_data_len <= len do
    local examine_item_data_tvbr = tvbuf:range(examine_item_data_pos, 40)
    examine_item_data_dissector:call(examine_item_data_tvbr:tvb(), pktinfo, root)
    examine_item_data_pos = examine_item_data_pos + examine_item_data_len
    examine_item_data_count = examine_item_data_count - 1
    if examine_item_data_count <= 0 then
      break
    end
  end

  -- dissect the nickname field
  if tvbuf:len() >= 656 then
    local nickname_tvbr = tvbuf:range(624, 32)
    local nickname_val  = nickname_tvbr:string(ENC_UTF_8)
    tree:add(examine_fields.nickname, nickname_tvbr, nickname_val)

    local nickname_display = ", Nickname: " .. nickname_val
    pktinfo.cols.info:append(nickname_display)
    tree:append_text(nickname_display)
  end

  return len
end