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

local db = require('ffxiv_db')
local ffxiv_ipc_fate_position = Proto("ffxiv_ipc_fate_position", "FFXIV-IPC Fate Position")

local fate_position_fields = {
  fate     = ProtoField.uint16("ffxiv_ipc_fate_position.fate", "Fate", base.DEC, db.Fate),
  unknown0 = ProtoField.uint32("ffxiv_ipc_fate_position.unknown0", "Unknown0", base.DEC),
  npc_id   = ProtoField.uint32("ffxiv_ipc_fate_position.npc_id", "NpcId", base.HEX),
  unknown1 = ProtoField.uint32("ffxiv_ipc_fate_position.unknown1", "Unknown1", base.DEC),
  x        = ProtoField.int32("ffxiv_ipc_fate_position.x", "X", base.DEC),
  y        = ProtoField.int32("ffxiv_ipc_fate_position.y", "Y", base.DEC),
  z        = ProtoField.int32("ffxiv_ipc_fate_position.z", "Z", base.DEC),
}

ffxiv_ipc_fate_position.fields = fate_position_fields

function ffxiv_ipc_fate_position.dissector(tvbuf, pktinfo, root)
  local tree = root:add(ffxiv_ipc_fate_position, tvbuf)
  pktinfo.cols.info:set("Fate Position")

  local len = tvbuf:len()

  -- dissect the fate field
  local fate_tvbr = tvbuf:range(0, 2)
  local fate_val  = fate_tvbr:le_uint()
  tree:add_le(fate_position_fields.fate, fate_tvbr, fate_val)

  local fate_display = ", Fate: " .. (db.Fate[fate_val] or "(unknown)")
  pktinfo.cols.info:append(fate_display)
  tree:append_text(fate_display)

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

  -- dissect the npc_id field
  local npc_id_tvbr = tvbuf:range(4, 4)
  local npc_id_val  = npc_id_tvbr:le_uint()
  tree:add_le(fate_position_fields.npc_id, npc_id_tvbr, npc_id_val)

  -- dissect the unknown1 field
  local unknown1_tvbr = tvbuf:range(8, 4)
  local unknown1_val  = unknown1_tvbr:le_uint()
  tree:add_le(fate_position_fields.unknown1, unknown1_tvbr, unknown1_val)

  -- dissect the x field
  local x_tvbr = tvbuf:range(12, 4)
  local x_val  = x_tvbr:le_int()
  tree:add_le(fate_position_fields.x, x_tvbr, x_val)

  local x_display = ", X: " .. x_val
  pktinfo.cols.info:append(x_display)
  tree:append_text(x_display)

  -- dissect the y field
  local y_tvbr = tvbuf:range(16, 4)
  local y_val  = y_tvbr:le_int()
  tree:add_le(fate_position_fields.y, y_tvbr, y_val)

  local y_display = ", Y: " .. y_val
  pktinfo.cols.info:append(y_display)
  tree:append_text(y_display)

  -- dissect the z field
  local z_tvbr = tvbuf:range(20, 4)
  local z_val  = z_tvbr:le_int()
  tree:add_le(fate_position_fields.z, z_tvbr, z_val)

  local z_display = ", Z: " .. z_val
  pktinfo.cols.info:append(z_display)
  tree:append_text(z_display)

  return len
end