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

local db = require('ffxiv_db')
local enum = require('ffxiv_enum')
local ffxiv_ipc_item_info = Proto("ffxiv_ipc_item_info", "FFXIV-IPC ItemInfo")

local item_info_fields = {
  index              = ProtoField.uint32("ffxiv_ipc_item_info.index", "Index", base.DEC),
  unknown0           = ProtoField.uint32("ffxiv_ipc_item_info.unknown0", "Unknown0", base.DEC),
  container_id       = ProtoField.uint16("ffxiv_ipc_item_info.container_id", "ContainerId", base.DEC, enum.reverse.item_location),
  slot               = ProtoField.uint16("ffxiv_ipc_item_info.slot", "Slot", base.DEC),
  quantity           = ProtoField.uint32("ffxiv_ipc_item_info.quantity", "Quantity", base.DEC),
  catalog_id         = ProtoField.uint32("ffxiv_ipc_item_info.catalog_id", "CatalogId", base.DEC, db.Item),
  reserved_flag      = ProtoField.uint32("ffxiv_ipc_item_info.reserved_flag", "ReservedFlag", base.DEC),
  signature_id       = ProtoField.uint64("ffxiv_ipc_item_info.signature_id", "SignatureId", base.DEC),
  quality            = ProtoField.uint8("ffxiv_ipc_item_info.quality", "Quality", base.DEC, enum.reverse.item_quality),
  attribute2         = ProtoField.uint8("ffxiv_ipc_item_info.attribute2", "Attribute2", base.DEC),
  condition          = ProtoField.uint16("ffxiv_ipc_item_info.condition", "Condition", base.DEC),
  spiritbond         = ProtoField.uint16("ffxiv_ipc_item_info.spiritbond", "Spiritbond", base.DEC),
  stain              = ProtoField.uint16("ffxiv_ipc_item_info.stain", "Stain", base.DEC),
  glamour_catalog_id = ProtoField.uint16("ffxiv_ipc_item_info.glamour_catalog_id", "GlamourCatalogId", base.DEC, db.Item),
  unknown6           = ProtoField.uint16("ffxiv_ipc_item_info.unknown6", "Unknown6", base.DEC),
  materia1           = ProtoField.uint16("ffxiv_ipc_item_info.materia1", "Materia1", base.DEC),
  materia2           = ProtoField.uint16("ffxiv_ipc_item_info.materia2", "Materia2", base.DEC),
  materia3           = ProtoField.uint16("ffxiv_ipc_item_info.materia3", "Materia3", base.DEC),
  materia4           = ProtoField.uint16("ffxiv_ipc_item_info.materia4", "Materia4", base.DEC),
  materia5           = ProtoField.uint16("ffxiv_ipc_item_info.materia5", "Materia5", base.DEC),
  materia1_tier      = ProtoField.uint8("ffxiv_ipc_item_info.materia1_tier", "Materia1Tier", base.DEC),
  materia2_tier      = ProtoField.uint8("ffxiv_ipc_item_info.materia2_tier", "Materia2Tier", base.DEC),
  materia3_tier      = ProtoField.uint8("ffxiv_ipc_item_info.materia3_tier", "Materia3Tier", base.DEC),
  materia4_tier      = ProtoField.uint8("ffxiv_ipc_item_info.materia4_tier", "Materia4Tier", base.DEC),
  materia5_tier      = ProtoField.uint8("ffxiv_ipc_item_info.materia5_tier", "Materia5Tier", base.DEC),
  unknown10          = ProtoField.uint8("ffxiv_ipc_item_info.unknown10", "Unknown10", base.DEC),
  unknown11          = ProtoField.uint32("ffxiv_ipc_item_info.unknown11", "Unknown11", base.DEC),
}

ffxiv_ipc_item_info.fields = item_info_fields

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

  local len = tvbuf:len()

  -- dissect the index field
  local index_tvbr = tvbuf:range(0, 4)
  local index_val  = index_tvbr:le_uint()
  tree:add_le(item_info_fields.index, index_tvbr, index_val)

  -- dissect the unknown0 field
  local unknown0_tvbr = tvbuf:range(4, 4)
  local unknown0_val  = unknown0_tvbr:le_uint()
  tree:add_le(item_info_fields.unknown0, unknown0_tvbr, unknown0_val)

  -- dissect the container_id field
  local container_id_tvbr = tvbuf:range(8, 2)
  local container_id_val  = container_id_tvbr:le_uint()
  tree:add_le(item_info_fields.container_id, container_id_tvbr, container_id_val)

  -- dissect the slot field
  local slot_tvbr = tvbuf:range(10, 2)
  local slot_val  = slot_tvbr:le_uint()
  tree:add_le(item_info_fields.slot, slot_tvbr, slot_val)

  -- dissect the quantity field
  local quantity_tvbr = tvbuf:range(12, 4)
  local quantity_val  = quantity_tvbr:le_uint()
  tree:add_le(item_info_fields.quantity, quantity_tvbr, quantity_val)

  local quantity_display = ", Quantity: " .. quantity_val
  pktinfo.cols.info:append(quantity_display)
  tree:append_text(quantity_display)

  -- dissect the catalog_id field
  local catalog_id_tvbr = tvbuf:range(16, 4)
  local catalog_id_val  = catalog_id_tvbr:le_uint()
  tree:add_le(item_info_fields.catalog_id, catalog_id_tvbr, catalog_id_val)

  local catalog_id_display = ", CatalogId: " .. (db.Item[catalog_id_val] or "(unknown)")
  pktinfo.cols.info:append(catalog_id_display)
  tree:append_text(catalog_id_display)

  -- dissect the reserved_flag field
  local reserved_flag_tvbr = tvbuf:range(20, 4)
  local reserved_flag_val  = reserved_flag_tvbr:le_uint()
  tree:add_le(item_info_fields.reserved_flag, reserved_flag_tvbr, reserved_flag_val)

  -- dissect the signature_id field
  local signature_id_tvbr = tvbuf:range(24, 8)
  local signature_id_val  = signature_id_tvbr:le_uint64()
  tree:add_le(item_info_fields.signature_id, signature_id_tvbr, signature_id_val)

  -- dissect the quality field
  local quality_tvbr = tvbuf:range(32, 1)
  local quality_val  = quality_tvbr:le_uint()
  tree:add_le(item_info_fields.quality, quality_tvbr, quality_val)

  local quality_display = ", Quality: " .. (enum.reverse.item_quality[quality_val] or "(unknown)")
  pktinfo.cols.info:append(quality_display)
  tree:append_text(quality_display)

  -- dissect the attribute2 field
  local attribute2_tvbr = tvbuf:range(33, 1)
  local attribute2_val  = attribute2_tvbr:le_uint()
  tree:add_le(item_info_fields.attribute2, attribute2_tvbr, attribute2_val)

  -- dissect the condition field
  local condition_tvbr = tvbuf:range(34, 2)
  local condition_val  = condition_tvbr:le_uint()
  tree:add_le(item_info_fields.condition, condition_tvbr, condition_val)

  -- dissect the spiritbond field
  local spiritbond_tvbr = tvbuf:range(36, 2)
  local spiritbond_val  = spiritbond_tvbr:le_uint()
  tree:add_le(item_info_fields.spiritbond, spiritbond_tvbr, spiritbond_val)

  -- dissect the stain field
  local stain_tvbr = tvbuf:range(38, 2)
  local stain_val  = stain_tvbr:le_uint()
  tree:add_le(item_info_fields.stain, stain_tvbr, stain_val)

  -- dissect the glamour_catalog_id field
  local glamour_catalog_id_tvbr = tvbuf:range(40, 2)
  local glamour_catalog_id_val  = glamour_catalog_id_tvbr:le_uint()
  tree:add_le(item_info_fields.glamour_catalog_id, glamour_catalog_id_tvbr, glamour_catalog_id_val)

  -- dissect the unknown6 field
  local unknown6_tvbr = tvbuf:range(42, 2)
  local unknown6_val  = unknown6_tvbr:le_uint()
  tree:add_le(item_info_fields.unknown6, unknown6_tvbr, unknown6_val)

  -- dissect the materia1 field
  local materia1_tvbr = tvbuf:range(44, 2)
  local materia1_val  = materia1_tvbr:le_uint()
  tree:add_le(item_info_fields.materia1, materia1_tvbr, materia1_val)

  -- dissect the materia2 field
  local materia2_tvbr = tvbuf:range(46, 2)
  local materia2_val  = materia2_tvbr:le_uint()
  tree:add_le(item_info_fields.materia2, materia2_tvbr, materia2_val)

  -- dissect the materia3 field
  local materia3_tvbr = tvbuf:range(48, 2)
  local materia3_val  = materia3_tvbr:le_uint()
  tree:add_le(item_info_fields.materia3, materia3_tvbr, materia3_val)

  -- dissect the materia4 field
  local materia4_tvbr = tvbuf:range(50, 2)
  local materia4_val  = materia4_tvbr:le_uint()
  tree:add_le(item_info_fields.materia4, materia4_tvbr, materia4_val)

  -- dissect the materia5 field
  local materia5_tvbr = tvbuf:range(52, 2)
  local materia5_val  = materia5_tvbr:le_uint()
  tree:add_le(item_info_fields.materia5, materia5_tvbr, materia5_val)

  -- dissect the materia1_tier field
  local materia1_tier_tvbr = tvbuf:range(54, 1)
  local materia1_tier_val  = materia1_tier_tvbr:le_uint()
  tree:add_le(item_info_fields.materia1_tier, materia1_tier_tvbr, materia1_tier_val)

  -- dissect the materia2_tier field
  local materia2_tier_tvbr = tvbuf:range(55, 1)
  local materia2_tier_val  = materia2_tier_tvbr:le_uint()
  tree:add_le(item_info_fields.materia2_tier, materia2_tier_tvbr, materia2_tier_val)

  -- dissect the materia3_tier field
  local materia3_tier_tvbr = tvbuf:range(56, 1)
  local materia3_tier_val  = materia3_tier_tvbr:le_uint()
  tree:add_le(item_info_fields.materia3_tier, materia3_tier_tvbr, materia3_tier_val)

  -- dissect the materia4_tier field
  local materia4_tier_tvbr = tvbuf:range(57, 1)
  local materia4_tier_val  = materia4_tier_tvbr:le_uint()
  tree:add_le(item_info_fields.materia4_tier, materia4_tier_tvbr, materia4_tier_val)

  -- dissect the materia5_tier field
  local materia5_tier_tvbr = tvbuf:range(58, 1)
  local materia5_tier_val  = materia5_tier_tvbr:le_uint()
  tree:add_le(item_info_fields.materia5_tier, materia5_tier_tvbr, materia5_tier_val)

  -- dissect the unknown10 field
  local unknown10_tvbr = tvbuf:range(59, 1)
  local unknown10_val  = unknown10_tvbr:le_uint()
  tree:add_le(item_info_fields.unknown10, unknown10_tvbr, unknown10_val)

  -- dissect the unknown11 field
  local unknown11_tvbr = tvbuf:range(60, 4)
  local unknown11_val  = unknown11_tvbr:le_uint()
  tree:add_le(item_info_fields.unknown11, unknown11_tvbr, unknown11_val)

  return len
end