mgirlich/jsontools

handling of int64

Closed this issue · 0 comments

  • use option as default?

  • when to inform?

  • ptype = NULL

    • bigint_found = FALSE -> number
    • bigint_found = TRUE & bigint_as_char = TRUE -> convert numbers to character
    • bigint_found = TRUE & bigint_as_char = FALSE -> integer64()
  • ptype = integer64()

    • bigint_as_char = TRUE -> convert numbers to character
    • bigint_as_char = FALSE -> integer64()
  • ptype = character()

    • bigint_found = TRUE -> error
if (bigint_as_char && bit64::is.integer64(ptype)) {
  stop_jsontools("`bigint_as_char = TRUE` not allowed with `ptype` = `integer64()`.")
}

# TODO think about info...
bigint_found <- is_true(attr(x_parsed, "bigint"))
if (bigint_found && is_null(ptype)) {
  if (bigint_as_char) {
    inform("bigints found; converted to `character()`.")
  } else {
    inform("bigints found; converted to `bit64::integer64()`.")
  }
}

if (is_null(ptype)) {
  if (bigint_found) {
    if (bigint_as_char) {
      # convert numbers to character
    } else {
      # convert everything to integer64
    }
  } else {
    # nothing to do
  }
} else if (bit64::is.integer64(ptype)) {
  # * `bigint_as_char = TRUE` -> convert numbers to character
  # * `bigint_as_char = FALSE` -> integer64()
  if (bigint_as_char)
}

# TODO bigint handling looks ugly...
if (bigint_found) {
  # TODO what about json_type real?
  # -> probably a bad idea anyway...
  stopifnot(identical(json_ptype, integer()))
  
  if (bigint_as_char) {
    browser()
    # convert logicals manually to integer as they otherwise become "true"/"false"
    is_lgl <- json_types %in% c("true", "false")
    x_parsed[is_lgl] <- as.integer(x_parsed[is_lgl])
    json_ptype <- character()
  } else {
    json_ptype <- bit64::integer64()
  }
}