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

local db = require('ffxiv_db')
local enum = require('ffxiv_enum')
local ffxiv_ipc_inventory_transaction = Proto("ffxiv_ipc_inventory_transaction", "FFXIV-IPC Inventory Transaction")

local inventory_transaction_fields = {
  sequence          = ProtoField.uint32("ffxiv_ipc_inventory_transaction.sequence", "Sequence", base.DEC),
  type              = ProtoField.uint32("ffxiv_ipc_inventory_transaction.type", "Type", base.DEC),
  owner_id          = ProtoField.uint32("ffxiv_ipc_inventory_transaction.owner_id", "OwnerId", base.HEX),
  storage_id        = ProtoField.uint32("ffxiv_ipc_inventory_transaction.storage_id", "StorageId", base.DEC, enum.reverse.item_location),
  slot_id           = ProtoField.uint32("ffxiv_ipc_inventory_transaction.slot_id", "SlotId", base.DEC),
  stack_size        = ProtoField.uint32("ffxiv_ipc_inventory_transaction.stack_size", "StackSize", base.DEC),
  catalog_id        = ProtoField.uint32("ffxiv_ipc_inventory_transaction.catalog_id", "CatalogId", base.DEC, db.Item),
  some_actor_id     = ProtoField.uint32("ffxiv_ipc_inventory_transaction.some_actor_id", "SomeActorId", base.HEX),
  target_storage_id = ProtoField.uint32("ffxiv_ipc_inventory_transaction.target_storage_id", "TargetStorageId", base.HEX),
}

ffxiv_ipc_inventory_transaction.fields = inventory_transaction_fields

function ffxiv_ipc_inventory_transaction.dissector(tvbuf, pktinfo, root)
  local tree = root:add(ffxiv_ipc_inventory_transaction, tvbuf)
  pktinfo.cols.info:set("Inventory Transaction")

  local len = tvbuf:len()

  -- dissect the sequence field
  local sequence_tvbr = tvbuf:range(0, 4)
  local sequence_val  = sequence_tvbr:le_uint()
  tree:add_le(inventory_transaction_fields.sequence, sequence_tvbr, sequence_val)

  -- dissect the type field
  local type_tvbr = tvbuf:range(4, 4)
  local type_val  = type_tvbr:le_uint()
  tree:add_le(inventory_transaction_fields.type, type_tvbr, type_val)

  -- dissect the owner_id field
  local owner_id_tvbr = tvbuf:range(8, 4)
  local owner_id_val  = owner_id_tvbr:le_uint()
  tree:add_le(inventory_transaction_fields.owner_id, owner_id_tvbr, owner_id_val)

  -- dissect the storage_id field
  local storage_id_tvbr = tvbuf:range(12, 4)
  local storage_id_val  = storage_id_tvbr:le_uint()
  tree:add_le(inventory_transaction_fields.storage_id, storage_id_tvbr, storage_id_val)

  local storage_id_display = ", StorageId: " .. (enum.reverse.item_location[storage_id_val] or "(unknown)")
  pktinfo.cols.info:append(storage_id_display)
  tree:append_text(storage_id_display)

  -- dissect the slot_id field
  local slot_id_tvbr = tvbuf:range(16, 4)
  local slot_id_val  = slot_id_tvbr:le_uint()
  tree:add_le(inventory_transaction_fields.slot_id, slot_id_tvbr, slot_id_val)

  -- dissect the stack_size field
  local stack_size_tvbr = tvbuf:range(20, 4)
  local stack_size_val  = stack_size_tvbr:le_uint()
  tree:add_le(inventory_transaction_fields.stack_size, stack_size_tvbr, stack_size_val)

  local stack_size_display = ", StackSize: " .. stack_size_val
  pktinfo.cols.info:append(stack_size_display)
  tree:append_text(stack_size_display)

  -- dissect the catalog_id field
  local catalog_id_tvbr = tvbuf:range(24, 4)
  local catalog_id_val  = catalog_id_tvbr:le_uint()
  tree:add_le(inventory_transaction_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 some_actor_id field
  local some_actor_id_tvbr = tvbuf:range(28, 4)
  local some_actor_id_val  = some_actor_id_tvbr:le_uint()
  tree:add_le(inventory_transaction_fields.some_actor_id, some_actor_id_tvbr, some_actor_id_val)

  -- dissect the target_storage_id field
  local target_storage_id_tvbr = tvbuf:range(32, 4)
  local target_storage_id_val  = target_storage_id_tvbr:le_uint()
  tree:add_le(inventory_transaction_fields.target_storage_id, target_storage_id_tvbr, target_storage_id_val)

  return len
end